#include #include #include #include #include #define MSECS 1000 int main(void) { int fd; char buf[2] = "0"; char *btns; char led_pattern = 0; fd = open("/dev/lms_ui", O_RDWR | O_SYNC); printf("device opened\n"); write(fd, buf, 2); btns = mmap(0, 6, PROT_READ, MAP_SHARED, fd, 0); char last_states = 0xff; while (1) { char states = 0 ; for (int i = 0 ; i < 6 ; i++) states = (states << 1) | (btns[i] & 0x01); if (states & 0x01) break; if (states != last_states) { if (states) { if (states & 0x20) { // up led_pattern = (led_pattern + 1) % 10; } else if (states & 0x08) { // down if (--led_pattern < 0) led_pattern = 9; } printf("setting LED pattern to %d\n", led_pattern); buf[0] = '0' + led_pattern; write(fd, buf, 2); } last_states = states ; } usleep(100*MSECS); } buf[0] = '1'; write(fd, buf, 2); close(fd); printf("Bye bye.\n"); return 0; }