Skip to content

Commit

Permalink
tg5040: increase mute switch poll rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Inman committed Nov 11, 2024
1 parent c27eb99 commit 5a96daa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions workspace/tg5040/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <pthread.h>

#include <msettings.h>

Expand Down Expand Up @@ -33,13 +34,45 @@
#define PRESSED 1
#define REPEAT 2

#define MUTE_STATE_PATH "/sys/class/gpio/gpio243/value"

#define INPUT_COUNT 4
static int inputs[INPUT_COUNT] = {};
static struct input_event ev;

static int getInt(char* path) {
int i = 0;
FILE *file = fopen(path, "r");
if (file!=NULL) {
fscanf(file, "%i", &i);
fclose(file);
}
return i;
}

static pthread_t mute_pt;
static void* watchMute(void *arg) {
int is_muted,was_muted;

is_muted = was_muted = getInt(MUTE_STATE_PATH);
SetMute(is_muted);

while(1) {
usleep(200000); // 5 times per second

is_muted = getInt(MUTE_STATE_PATH);
if (was_muted!=is_muted) {
was_muted = is_muted;
SetMute(is_muted);
}
}

return 0;
}

int main (int argc, char *argv[]) {
InitSettings();
pthread_create(&mute_pt, NULL, &watchMute, NULL);

char path[32];
for (int i=0; i<INPUT_COUNT; i++) {
Expand Down
2 changes: 1 addition & 1 deletion workspace/tg5040/keymon/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif
TARGET = keymon

CC = $(CROSS_COMPILE)gcc
CFLAGS = -Os -lmsettings -lrt -ldl -Wl,--gc-sections -s
CFLAGS = -Os -lmsettings -lpthread -lrt -ldl -Wl,--gc-sections -s
CFLAGS += -I. -I../../all/common -I../platform/ -DPLATFORM=\"$(UNION_PLATFORM)\"

all:
Expand Down

0 comments on commit 5a96daa

Please sign in to comment.