]> git.droids-corp.org - fpv.git/commitdiff
beep when GPS returns a bad position
authorOlivier Matz <zer0@droids-corp.org>
Tue, 9 Sep 2014 17:02:19 +0000 (19:02 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Tue, 9 Sep 2014 17:49:31 +0000 (19:49 +0200)
common/i2c_commands.h
imuboard/i2c_protocol.c
imuboard/main.h
imuboard/sd_log.c
mainboard/i2c_protocol.c

index 92a1405e20b7fd6b522b858303a68d5c90c9d158..7a9b9c5154146bac7f09e49d191ee7da89da3d3b 100644 (file)
@@ -58,8 +58,10 @@ struct i2c_req_imuboard_status {
 struct i2c_ans_imuboard_status {
        struct i2c_cmd_hdr hdr;
 
-#define I2C_IMUBOARD_STATUS_GPS_OK 0x01
-#define I2C_IMUBOARD_STATUS_IMU_OK 0x02
+#define I2C_IMUBOARD_STATUS_BOOT_OK     0x01
+#define I2C_IMUBOARD_STATUS_SDCARD_OK   0x02
+#define I2C_IMUBOARD_STATUS_GPS_OK      0x04
+#define I2C_IMUBOARD_STATUS_IMU_OK      0x08
        uint8_t flags;
 
        int32_t latitude;  /* between -90e7 and 90e7, in 1/1e-7 degrees,
index 9d73252bd8044387a06e22fac005d6a7f4227ffe..015e49c0af0c45443805f4b3dcc04e5bcd5b772d 100644 (file)
@@ -83,6 +83,11 @@ static void i2c_send_status(void)
        IRQ_UNLOCK(irq_flags);
 
        ans.flags = 0;
+       if (imuboard.flags & IMUBOARD_F_BOOT_OK)
+               ans.flags |= I2C_IMUBOARD_STATUS_BOOT_OK;
+       if (imuboard.flags & IMUBOARD_F_SDCARD_OK)
+               ans.flags |= I2C_IMUBOARD_STATUS_SDCARD_OK;
+
        if (gps_pos_valid(&gps_pos)) {
                ans.flags |= I2C_IMUBOARD_STATUS_GPS_OK;
                ans.latitude = gps_pos.latitude;
index ad65316a4d72cea07716f425fc265692c4d7c648..e172287b00b22c2abd5ef9429c228bc4e2aa9efb 100644 (file)
@@ -72,6 +72,10 @@ struct imuboard {
 
        struct callout_mgr intr_cm;
 
+#define IMUBOARD_F_BOOT_OK   0x01
+#define IMUBOARD_F_SDCARD_OK 0x02
+       uint8_t flags;
+
        /* log */
        uint8_t logs[NB_LOGS+1];
        uint8_t log_level;
index edc83ea56b01dced538772a7b2f0a6dce002ae83..e7ff850798e2427e598ca149536088dd676c9954 100644 (file)
@@ -9,6 +9,7 @@
 #include "sd_raw.h"
 #include "sd_raw_config.h"
 #include "sd_log.h"
+#include "main.h"
 
 static struct fat_file_struct *log_fd = NULL;
 
@@ -127,7 +128,9 @@ int8_t sd_log_open(void)
                printf_P(PSTR("error opening "));
                return -1;
        }
+       log_fd = fd;
 
+       imuboard.flags |= IMUBOARD_F_SDCARD_OK;
        return 0;
 }
 
index 912f7697f44973926be89010a5289c6284dd91df..fe58b7cc952af074ff4d6d5242e1c272d1cc02e0 100644 (file)
 #define I2C_TIMEOUT 100 /* ms */
 #define I2C_MAX_ERRORS 40
 
+#define IMUBOARD_BEEP_PERIOD_MS 2000
+
 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 */
@@ -58,6 +58,7 @@ static volatile uint8_t running_op = OP_READY;
 static uint8_t error_log = 0;
 
 static struct callout i2c_timer;
+static struct callout imuboard_beep_timer;
 
 static int8_t i2c_req_imuboard_status(void);
 
@@ -112,6 +113,35 @@ void i2cproto_wait_update(void)
        //WAIT_COND_OR_TIMEOUT((i2c_poll_num-poll_num) > 1, 150); /* XXX todo */
 }
 
+static void imuboard_beep_cb(struct callout_mgr *cm, struct callout *tim, void *arg)
+{
+       (void)cm;
+       (void)tim;
+       (void)arg;
+
+       if ((imuboard_status.flags & I2C_IMUBOARD_STATUS_SDCARD_OK) == 0) {
+               beep(0, 1, 1);
+               goto reschedule;
+       }
+
+       if ((imuboard_status.flags & I2C_IMUBOARD_STATUS_BOOT_OK) == 0) {
+               beep(0, 1, 1);
+               beep(0, 1, 1);
+               goto reschedule;
+       }
+
+       if ((imuboard_status.flags & I2C_IMUBOARD_STATUS_GPS_OK) == 0) {
+               beep(0, 1, 1);
+               beep(0, 1, 1);
+               beep(0, 1, 1);
+               goto reschedule;
+       }
+
+ reschedule:
+       callout_reschedule(cm, tim, IMUBOARD_BEEP_PERIOD_MS);
+}
+
+
 /* called periodically : the goal of this 'thread' is to send requests
  * and read answers on i2c slaves in the correct order. */
 static void i2c_poll_slaves(struct callout_mgr *cm, struct callout *tim, void *arg)
@@ -252,13 +282,6 @@ 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 & I2C_IMUBOARD_STATUS_GPS_OK)) {
-                       gps_ok = 1;
-                       beep(0, 1, 1);
-                       beep(0, 1, 1);
-               }
-
                break;
        }
 
@@ -338,4 +361,7 @@ void i2c_protocol_init(void)
 {
        callout_init(&i2c_timer, i2c_poll_slaves, NULL, I2C_PRIO);
        callout_schedule(&xbeeboard.intr_cm, &i2c_timer, I2C_PERIOD_MS);
+       callout_init(&imuboard_beep_timer, imuboard_beep_cb, NULL, I2C_PRIO); // prio ok ? XXX
+       callout_schedule(&xbeeboard.intr_cm, &imuboard_beep_timer,
+               IMUBOARD_BEEP_PERIOD_MS);
 }