beacon from 2009
[aversive.git] / projects / microb2010 / ballboard / main.c
index ed8716b..7a3cee5 100755 (executable)
@@ -58,6 +58,8 @@
 #include "actuator.h"
 #include "cs.h"
 #include "i2c_protocol.h"
+#include "state.h"
+#include "beacon.h"
 
 /* 0 means "programmed"
  * ---- with 16 Mhz quartz
@@ -169,13 +171,17 @@ int main(void)
 #  error not supported
 #endif
 
-       //eeprom_write_byte(EEPROM_MAGIC_ADDRESS, EEPROM_MAGIC_BALLBOARD);
        /* check eeprom to avoid to run the bad program */
        if (eeprom_read_byte(EEPROM_MAGIC_ADDRESS) !=
            EEPROM_MAGIC_BALLBOARD) {
+               int c;
                sei();
-               printf_P(PSTR("Bad eeprom value\r\n"));
-               while(1);
+               printf_P(PSTR("Bad eeprom value ('f' to force)\r\n"));
+               c = uart_recv(CMDLINE_UART);
+               if (c == 'f')
+                       eeprom_write_byte(EEPROM_MAGIC_ADDRESS, EEPROM_MAGIC_BALLBOARD);
+               wait_ms(100);
+               bootloader();
        }
 
        /* LOGS */
@@ -207,9 +213,10 @@ int main(void)
                      &PORTD, 4);
        PWM_NG_INIT16(&gen.pwm2_4B, 4, B, 10, PWM_NG_MODE_SIGNED,
                      &PORTD, 5);
-       PWM_NG_INIT16(&gen.pwm3_1A, 1, A, 10, PWM_NG_MODE_SIGNED,
-                     &PORTD, 6);
-       PWM_NG_INIT16(&gen.pwm4_1B, 1, B, 10, PWM_NG_MODE_SIGNED,
+       PWM_NG_INIT16(&gen.pwm3_1A, 1, A, 10, PWM_NG_MODE_SIGNED |
+                     PWM_NG_MODE_SIGN_INVERTED, &PORTD, 6);
+       PWM_NG_INIT16(&gen.pwm4_1B, 1, B, 10, PWM_NG_MODE_SIGNED |
+                     PWM_NG_MODE_SIGN_INVERTED,
                      &PORTD, 7);
 
 
@@ -239,6 +246,11 @@ int main(void)
        /* sensors, will also init hardware adc */
        sensor_init();
 
+       /* beacon */
+       beacon_init();
+       scheduler_add_periodical_event_priority(beacon_calc, NULL, 
+                                               20000L / SCHEDULER_UNIT, 
+                                               BEACON_PRIO);
        /* TIME */
        time_init(TIME_PRIO);
 
@@ -250,8 +262,13 @@ int main(void)
 
        sei();
 
+       actuator_init();
+       beacon_calibre_pos();
+
        printf_P(PSTR("\r\n"));
        printf_P(PSTR("Dass das Gluck deinen Haus setzt.\r\n"));
+
+       state_machine();
        cmdline_interact();
 
        return 0;