From 01b6265abb13fe7b6f803ab87e8acc387c3c75ef Mon Sep 17 00:00:00 2001 From: Arjen Baart Date: Sun, 2 Aug 2020 12:43:54 +0200 Subject: [PATCH] Introduction of lightswitch --- src/lightswitch.c | 24 +++++++++++++++++++----- src/startpwm | 2 ++ test/wakeupsequence | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/lightswitch.c b/src/lightswitch.c index 7b81626..8edc613 100644 --- a/src/lightswitch.c +++ b/src/lightswitch.c @@ -50,10 +50,10 @@ void setup_io(); int main(int argc, char *argv[]) { - int i; + int old_state, new_state; struct timespec interval; - interval.tv_sec = 2; + interval.tv_sec = 1; interval.tv_nsec = 0; // Set up gpi pointer for direct register access @@ -62,11 +62,25 @@ int main(int argc, char *argv[]) // Initialize the IO pins. INP_GPIO(SWITCH_IN); - // Scan the arguments. - + old_state = GET_GPIO(SWITCH_IN); + while (1) { - printf("%d", GET_GPIO(SWITCH_IN)); + new_state = GET_GPIO(SWITCH_IN); + if (new_state != old_state) + { + //fprintf(stderr, "Changed state to %d\n", new_state); + if (new_state == 0) + { + system("lightcontrol -r 100 -g 100 -b 100 -w 100"); + } + else + { + system("lightcontrol -r 0 -g 0 -b 0 -w 0"); + } + + old_state = new_state; + } nanosleep(&interval, NULL); } diff --git a/src/startpwm b/src/startpwm index 9bba7ca..582ce58 100755 --- a/src/startpwm +++ b/src/startpwm @@ -12,6 +12,8 @@ lightcontrol -r 0 -g 0 -b 0 -w 0 chrt -f 50 pwm & +lightswitch & + # Create a sequence of light colors to test if the generator is working # The sequence is red - green - blue - white. diff --git a/test/wakeupsequence b/test/wakeupsequence index 4abff51..bfd4e02 100755 --- a/test/wakeupsequence +++ b/test/wakeupsequence @@ -12,5 +12,6 @@ lightcontrol -r 100 -f $FADETIME lightcontrol -g 100 -f $FADETIME lightcontrol -w 100 -f $FADETIME sleep 3000 +curtain -o 2 lightcontrol -r 0 -g 0 -w 0 -f $FADETIME -- 2.20.1