From 68f6cf578c5932196b6af4768a3a1edbc38f0cba Mon Sep 17 00:00:00 2001 From: Alexey Korepanov Date: Tue, 21 Nov 2017 23:56:08 +0000 Subject: [PATCH] teres1-ledctrl: add more looops --- .../A64-TERES/teres1-ledctrl/teres1-ledctrl.c | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/SOFTWARE/A64-TERES/teres1-ledctrl/teres1-ledctrl.c b/SOFTWARE/A64-TERES/teres1-ledctrl/teres1-ledctrl.c index 06bde8f9..483b4d91 100644 --- a/SOFTWARE/A64-TERES/teres1-ledctrl/teres1-ledctrl.c +++ b/SOFTWARE/A64-TERES/teres1-ledctrl/teres1-ledctrl.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include @@ -69,34 +71,37 @@ int main (int argc, char **argv) device = argv[1]; - if((fd = open(device, O_RDONLY)) == -1) + for (;;) { - perror("Could not open input device"); - exit(255); - } - - export_gpio(LED_NUM); - export_gpio(LED_CAPS); - - - while(read(fd, &ie, sizeof(struct input_event))) - { - switch (ie.type) + if((fd = open(device, O_RDONLY)) != -1) { - case 17: // EV_LED - switch (ie.code) { - 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; + export_gpio(LED_NUM); + export_gpio(LED_CAPS); + + while(read(fd, &ie, sizeof(struct input_event)) > 0) + { + switch (ie.type) + { + case 17: // EV_LED + switch (ie.code) { + 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 }