Introduction of lightswitch
authorArjen Baart <arjen@andromeda.nl>
Sun, 2 Aug 2020 10:43:54 +0000 (12:43 +0200)
committerArjen Baart <arjen@andromeda.nl>
Sun, 2 Aug 2020 10:43:54 +0000 (12:43 +0200)
src/lightswitch.c
src/startpwm
test/wakeupsequence

index 7b81626..8edc613 100644 (file)
@@ -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);
    }
 
index 9bba7ca..582ce58 100755 (executable)
@@ -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.
index 4abff51..bfd4e02 100755 (executable)
@@ -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