--- embedtools/src/pceng_run.c 2011/10/24 13:41:48 1.1.2.6 +++ embedtools/src/pceng_run.c 2011/10/24 23:14:36 1.1.2.9 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: pceng_run.c,v 1.1.2.6 2011/10/24 13:41:48 misho Exp $ + * $Id: pceng_run.c,v 1.1.2.9 2011/10/24 23:14:36 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -142,7 +142,7 @@ LED(u_char ledno, u_char state) } outl(led_base[type - 1][ledno], n); - return 0; + return (int) state; } static int @@ -166,6 +166,8 @@ RunCmd(u_char pin, u_int state) } if (!*szStr) return 0; + if (pin) + snprintf(szArg, sizeof szArg, "%d=%d", pin, state); else snprintf(szArg, sizeof szArg, "%d", state); @@ -194,7 +196,7 @@ Run() if ((ret = gpioRead(i)) == -1) return 126; else - states |= (1 << i); + states |= ret ? (1 << i) : 0; /* state machine */ while (!Kill) { @@ -210,7 +212,7 @@ Run() return 127; if (ret != ((states >> i) & 0x1)) { - if (!i) { + if (!i) { /* button */ t = 0; do { t++; @@ -218,7 +220,7 @@ Run() if (gpioRead(i) != ret) break; } while (!Kill); - } else { + } else { /* leds */ t = ret; if (ret) states |= (1 << i); @@ -229,6 +231,8 @@ Run() RunCmd(i, t); } } + + usleep(slice); } return 0;