From 8fc0e39d39626aefe98d951e58bcbdfbbbc2207a Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Thu, 18 Sep 2014 19:50:19 +0200 Subject: [PATCH] imuboard: allow to log on stdout even if sdcard is enabled --- imuboard/gps_venus.c | 6 +++--- imuboard/gps_venus.h | 4 +++- imuboard/imu.c | 14 ++++++++++---- imuboard/imu.h | 4 ++-- imuboard/main.c | 8 ++------ 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/imuboard/gps_venus.c b/imuboard/gps_venus.c index 2aa8f83..fbb6578 100644 --- a/imuboard/gps_venus.c +++ b/imuboard/gps_venus.c @@ -617,7 +617,7 @@ void gps_get_pos(struct gps_pos *pos) memcpy(pos, &gps_pos, sizeof(*pos)); } -int gps_log(void) +int gps_log(uint8_t to_stdout) { uint32_t ms; uint8_t flags, prio; @@ -646,13 +646,13 @@ int gps_log(void) (double)gps_pos.sea_altitude / 100.); - if (sd_log_enabled()) { + if (!to_stdout && sd_log_enabled()) { if (sd_log_write(buf, len) != len) { printf_P(PSTR("error writing to file\n")); return -1; } } - else { + else if (to_stdout) { printf_P(PSTR("%s"), buf); } diff --git a/imuboard/gps_venus.h b/imuboard/gps_venus.h index 7970088..7397cbc 100644 --- a/imuboard/gps_venus.h +++ b/imuboard/gps_venus.h @@ -38,7 +38,9 @@ struct gps_pos { } __attribute__ ((packed)); int gps_venus_init(void); -int gps_log(void); + +/* log gps position stdout (if stdout is 1) or on sdcard (if 0) */ +int gps_log(uint8_t to_stdout); /* does not lock intr, must be done by user */ void gps_get_pos(struct gps_pos *pos); diff --git a/imuboard/imu.c b/imuboard/imu.c index c113e1c..14f8479 100644 --- a/imuboard/imu.c +++ b/imuboard/imu.c @@ -99,7 +99,8 @@ void imu_get_pos_euler(struct euler *euler) } -int imu_log(void) + +int imu_log(uint8_t to_stdout) { char buf[128]; int16_t len; @@ -124,9 +125,14 @@ int imu_log(void) imu.gx, imu.gy, imu.gz, imu.ax, imu.ay, imu.az, imu.mx, imu.my, imu.mz); - if (sd_log_write(buf, len) != len) { - printf_P(PSTR("error writing to file\n")); - return -1; + if (!to_stdout && sd_log_enabled()) { + if (sd_log_write(buf, len) != len) { + printf_P(PSTR("error writing to file\n")); + return -1; + } + } + else if (to_stdout) { + printf_P(PSTR("%s"), buf); } return 0; diff --git a/imuboard/imu.h b/imuboard/imu.h index 06c03a1..06755c9 100644 --- a/imuboard/imu.h +++ b/imuboard/imu.h @@ -65,8 +65,8 @@ struct euler { /* initialize the IMU */ void imu_init(void); -/* if sd log file is opened, log the status of IMU on the sdcard */ -int imu_log(void); +/* log imu status on stdout (if stdout is 1) or on sdcard (if 0) */ +int imu_log(uint8_t to_stdout); /* return a filled imu_info structure corresponding to the latest axes read in * the timer callback. Does not lock irq, so it's up to the user to do that. */ diff --git a/imuboard/main.c b/imuboard/main.c index bee118f..37be46c 100644 --- a/imuboard/main.c +++ b/imuboard/main.c @@ -140,9 +140,6 @@ static void main_timer_interrupt(void) LED2_OFF(); } -/* XXX */ -int sd_main(void); - int main(void) { DDRB = 0x18 /* LEDs */; @@ -182,15 +179,14 @@ int main(void) printf_P(PSTR("\r\n")); rdline_newline(&imuboard.rdl, imuboard.prompt); - //sd_main(); imu_init(); gps_venus_init(); imuboard.flags |= IMUBOARD_F_BOOT_OK; while (1) { - //imu_log(); - //gps_log(); + imu_log(0); + gps_log(0); cmdline_poll(); } -- 2.39.5