#define SWITCH_IN 2
+#define FIRMASK 0x03
+
+#define TEST_CYCLES (60 * 5) // 1 minute
+
+unsigned fir_record[TEST_CYCLES];
int main(int argc, char *argv[])
{
+ unsigned int fir; // A simple FIR filter
+
int old_state, new_state;
struct timespec interval;
setup_io();
// Initialize the IO pins.
+ //GPIO_PULL = 0;
INP_GPIO(SWITCH_IN);
- old_state = GET_GPIO(SWITCH_IN);
+ // Initialize to switched off state
+ fir = 0xffff;
+ old_state = 1; // Off
- while (1)
+ int cycle = 0;
+ //while (1)
+ while (cycle < TEST_CYCLES)
{
- new_state = GET_GPIO(SWITCH_IN);
+ unsigned input = GET_GPIO(SWITCH_IN) == 0 ? 0 : 1;
+
+ fir <<= 1;
+ fir |= input;
+
+ fprintf(stderr, "FIR = 0x%x\r", fir);
+ if ( (fir & FIRMASK) == 0)
+ {
+ new_state = 0; // On
+ }
+ if ( (fir & FIRMASK) == FIRMASK)
+ {
+ new_state = 1; // Off
+ }
+
if (new_state != old_state)
{
- //fprintf(stderr, "Changed state to %d\n", new_state);
+ //fprintf(stderr, "Changed state to %d\r", new_state);
if (new_state == 0)
{
system("lightcontrol -r 100 -g 100 -b 100 -w 100");
old_state = new_state;
}
+ fir_record[cycle++] = fir;
+
nanosleep(&interval, NULL);
}
+ for (int i = 0; i < TEST_CYCLES; i++)
+ {
+ //printf("FIR = 0x%08x\n", fir_record[i]);
+ }
+
return 0;
}