teres1-ledctrl: add more looops

This commit is contained in:
Alexey Korepanov 2017-11-21 23:56:08 +00:00
parent 457331b794
commit 68f6cf578c

@ -15,6 +15,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/input.h> #include <linux/input.h>
@ -69,34 +71,37 @@ int main (int argc, char **argv)
device = argv[1]; device = argv[1];
if((fd = open(device, O_RDONLY)) == -1) for (;;)
{ {
perror("Could not open input device"); if((fd = open(device, O_RDONLY)) != -1)
exit(255);
}
export_gpio(LED_NUM);
export_gpio(LED_CAPS);
while(read(fd, &ie, sizeof(struct input_event)))
{
switch (ie.type)
{ {
case 17: // EV_LED export_gpio(LED_NUM);
switch (ie.code) { export_gpio(LED_CAPS);
case 0: // LED_NUML
printf("type %d\tcode %d\tvalue %d\n", ie.type, ie.code, ie.value); while(read(fd, &ie, sizeof(struct input_event)) > 0)
set_gpio(LED_NUM, ie.value); {
break; switch (ie.type)
case 1: // LED_CAPSL {
printf("type %d\tcode %d\tvalue %d\n", ie.type, ie.code, ie.value); case 17: // EV_LED
set_gpio(LED_CAPS, ie.value); switch (ie.code) {
break; case 0: // LED_NUML
printf("type %d\tcode %d\tvalue %d\n", ie.type, ie.code, ie.value);
set_gpio(LED_NUM, ie.value);
break;
case 1: // LED_CAPSL
printf("type %d\tcode %d\tvalue %d\n", ie.type, ie.code, ie.value);
set_gpio(LED_CAPS, ie.value);
break;
}
break;
}
} }
break;
} }
// something went wrong: rinse and repeat
close(fd);
usleep(65535u);
} }
return 0; return 0; // never
} }