beep when GPS ready
[protos/xbee-avr.git] / i2c_protocol.c
index 6b667b4..ca4c49c 100644 (file)
@@ -30,8 +30,9 @@
 #include <i2c.h>
 
 #include "../fpv-common/i2c_commands.h"
-#include "main.h"
 #include "i2c_protocol.h"
+#include "beep.h"
+#include "main.h"
 
 #define I2C_STATE_MAX 2
 #define I2C_PERIOD_MS 50
 
 static volatile uint8_t i2c_poll_num = 0;
 static volatile uint8_t i2c_state = 0;
+static volatile uint8_t i2c_rx_count = 0;
+static volatile uint8_t i2c_tx_count = 0;
 static volatile uint16_t i2c_errors = 0;
 
+static uint8_t gps_ok = 0;
+
 #define OP_READY 0 /* no i2c op running */
 #define OP_POLL  1 /* a user command is running */
 #define OP_CMD   2 /* a polling (req / ans) is running */
@@ -80,6 +85,8 @@ volatile uint8_t command_size=0;
 void i2c_protocol_debug(void)
 {
        printf_P(PSTR("I2C protocol debug infos:\r\n"));
+       printf_P(PSTR("  i2c_send=%d\r\n"), i2c_tx_count);
+       printf_P(PSTR("  i2c_recv=%d\r\n"), i2c_rx_count);
        printf_P(PSTR("  i2c_state=%d\r\n"), i2c_state);
        printf_P(PSTR("  i2c_errors=%d\r\n"), i2c_errors);
        printf_P(PSTR("  running_op=%d\r\n"), running_op);
@@ -198,6 +205,7 @@ void i2c_sendevent(int8_t size)
                }
                else
                        command_size = 0;
+               i2c_tx_count++;
        }
        else {
                i2c_errors++;
@@ -230,6 +238,8 @@ void i2c_recvevent(uint8_t * buf, int8_t size)
                goto error;
        }
 
+       i2c_rx_count++;
+
        switch (buf[0]) {
 
        case I2C_ANS_IMUBOARD_STATUS: {
@@ -242,6 +252,13 @@ void i2c_recvevent(uint8_t * buf, int8_t size)
                /* copy status in a global struct */
                memcpy(&imuboard_status, ans, sizeof(imuboard_status));
 
+               if (gps_ok == 0 &&
+                       (imuboard_status.flags & IMUBOARD_STATUS_GPS_OK)) {
+                       gps_ok = 1;
+                       beep(0, 1, 1);
+                       beep(0, 1, 1);
+               }
+
                break;
        }