src-avr: Control log with pin on companion connector
authorKeith Packard <keithp@keithp.com>
Mon, 23 May 2011 18:52:40 +0000 (11:52 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 23 May 2011 22:13:55 +0000 (16:13 -0600)
Use the SPI chip select (SS) which is hooked to port B0.

Signed-off-by: Keith Packard <keithp@keithp.com>
src-avr/ao_log_telescience.c

index f092027a6db88bcc78424ea13ab1e677025856b4..bda8912922160d3aa33bae0723c5fd9095616e95 100644 (file)
@@ -85,9 +85,36 @@ ao_log_valid(struct ao_log_telescience *log)
        return 0;
 }
 
+void
+ao_log_start(void)
+{
+       printf("Log goes from %ld to %ld\n", ao_log_current_pos, ao_log_end_pos);
+       ao_log_running = 1;
+       ao_wakeup(&ao_log_running);
+}
+
+void
+ao_log_stop(void)
+{
+       printf ("Log stopped at %ld\n", ao_log_current_pos);
+       ao_log_running = 0;
+       ao_wakeup((void *) &ao_adc_head);
+}
+
+void
+ao_log_check_pin(void)
+{
+       if (PINB & (1 << PINB0))
+               ao_log_stop();
+       else
+               ao_log_start();
+}
+
 void
 ao_log_telescience(void)
 {
+       ao_log_check_pin();
+
        ao_storage_setup();
 
        /* Find end of data */
@@ -127,22 +154,6 @@ ao_log_telescience(void)
        }
 }
 
-void
-ao_log_start(void)
-{
-       printf("Log goes from %ld to %ld\n", ao_log_current_pos, ao_log_end_pos);
-       ao_log_running = 1;
-       ao_wakeup(&ao_log_running);
-}
-
-void
-ao_log_stop(void)
-{
-       printf ("Log stopped at %ld\n", ao_log_current_pos);
-       ao_log_running = 0;
-       ao_wakeup((void *) &ao_adc_head);
-}
-
 void
 ao_log_set(void)
 {
@@ -214,11 +225,22 @@ const struct ao_cmds ao_log_cmds[] = {
        { 0,    NULL },
 };
 
+ISR(PCINT0_vect)
+{
+       ao_log_check_pin();
+}
+
 void
 ao_log_init(void)
 {
        ao_log_running = 0;
 
+       PCMSK0 |= (1 << PCINT0);        /* Enable PCINT0 pin change */
+
+       PCICR |= (1 << PCIE0);          /* Enable pin change interrupt */
+
+       PORTB &= ~(1 << PORTB0);        /* Pull input down; always log if NC */
+
        ao_cmd_register(&ao_log_cmds[0]);
 
        ao_add_task(&ao_log_task, ao_log_telescience, "log");