]> git.droids-corp.org - fpv.git/commitdiff
use printf_P instead of printf if possible
authorOlivier Matz <zer0@droids-corp.org>
Thu, 24 Jul 2014 18:25:53 +0000 (20:25 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 24 Jul 2014 18:25:53 +0000 (20:25 +0200)
imuboard/commands_gen.c
imuboard/gps_venus.c
imuboard/mpu6050.c
imuboard/sd_log.c
mainboard/commands_gen.c
mainboard/main.c

index f49ef9a11d802697669aa7bc763ddb065b782336..d62fbdf6c9a1ffd3bf67af22beb6d33eedb407b6 100644 (file)
@@ -90,7 +90,7 @@ static void cmd_bootloader_parsed(void *parsed_result, void *data)
 #ifndef HOST_VERSION
        bootloader();
 #else
-       printf("not implemented\n");
+       printf_P(PSTR("not implemented\n"));
 #endif
 }
 
@@ -361,9 +361,9 @@ static void cmd_stack_space_parsed(void *parsed_result, void *data)
        (void)parsed_result;
        (void)data;
 #ifdef HOST_VERSION
-       printf("not implemented\n");
+       printf_P(PSTR("not implemented\n"));
 #else
-       printf("res stack: %d\r\n", min_stack_space_available());
+       printf_P(PSTR("res stack: %d\r\n"), min_stack_space_available());
 #endif
 }
 
index 22e2076ca0312c6c6532e770f437aa033c429999..157091267703d9835eda23b64363206afca6db71 100644 (file)
@@ -18,8 +18,8 @@
 #include "sd_raw_config.h"
 #include "sd_log.h"
 
-#define debug_printf(args...) do { } while (0)
-/* #define debug_printf(args...) printf(args) */
+#define debug_printf(fmt, a...) do { } while (0)
+/* #define debug_printf(fmt, ...) printf_P(PSTR(fmt), ##__VA_ARGS__) */
 
 #define GPS_UART 0
 
@@ -399,11 +399,11 @@ int wait_ack(int msg_type)
                        continue;
 
                if (rxframe.data[0] == 0x83)
-                       printf("ACK\n");
+                       printf_P(PSTR("ACK\n"));
                else if (rxframe.data[0] == 0x84)
-                       printf("NACK\n");
+                       printf_P(PSTR("NACK\n"));
                else
-                       printf("ZARB\n");
+                       printf_P(PSTR("ZARB\n"));
                break;
        }
 
@@ -451,32 +451,34 @@ static int decode_gps_pos(uint8_t *buf, uint16_t len)
 /* display current GPS position stored in the global variable */
 static void display_gps(void)
 {
-       printf("id %.2X mode %.2X svnum %.2X gpsw %.4X tow %.10"PRIu32"\t",
+       printf_P(PSTR("id %.2X mode %.2X svnum %.2X gpsw %.4X "
+                       "tow %.10"PRIu32"\t"),
                gps_pos.msg_id,
                gps_pos.mode,
                gps_pos.sv_num,
                gps_pos.gps_week,
                gps_pos.tow);
 
-       printf("lat %.8"PRIx32" long %.8"PRIx32" alt %.8"PRIx32"\n",
+       printf_P(PSTR("lat %.8"PRIx32" long %.8"PRIx32" alt %.8"PRIx32"\n"),
                gps_pos.latitude,
                gps_pos.longitude,
                gps_pos.altitude);
 
-       printf("gdop %3.3f pdop %3.3f hdop %3.3f vdop %3.3f tdop %3.3f\n",
+       printf_P(PSTR("gdop %3.3f pdop %3.3f hdop %3.3f vdop %3.3f "
+                       "tdop %3.3f\n"),
                (double)gps_pos.gdop/100.,
                (double)gps_pos.pdop/100.,
                (double)gps_pos.hdop/100.,
                (double)gps_pos.vdop/100.,
                (double)gps_pos.tdop/100.);
 
-       printf("lat %3.5f long %3.5f alt %3.5f sea_alt %3.5f\n",
+       printf_P(PSTR("lat %3.5f long %3.5f alt %3.5f sea_alt %3.5f\n"),
                (double)gps_pos.latitude/10000000.,
                (double)gps_pos.longitude/10000000.,
                (double)gps_pos.altitude/100.,
                (double)gps_pos.sea_altitude/100.);
 
-       printf("vx %3.3f vy %3.3f vz %3.3f\n",
+       printf_P(PSTR("vx %3.3f vy %3.3f vz %3.3f\n"),
                (double)gps_pos.ecef_vx/100.,
                (double)gps_pos.ecef_vy/100.,
                (double)gps_pos.ecef_vz/100.);
@@ -511,7 +513,7 @@ static void gps_venus_cb(struct callout_mgr *cm, struct callout *tim, void *arg)
 static void venus634_configure(void)
 {
        /* ask the GPS to reset */
-       printf("init...");
+       printf_P(PSTR("init..."));
        venus634_restart();
        wait_ack(M_RESTART);
 
@@ -519,19 +521,19 @@ static void venus634_configure(void)
         * properly */
        wait_ms(500);
 
-       printf("binmode...");
+       printf_P(PSTR("binmode..."));
        venus634_msg_type();
        wait_ack(M_OUTPUT);
 
-       printf("waas...");
+       printf_P(PSTR("waas..."));
        venus634_waas();
        wait_ack(M_WAAS);
 
-       printf("rate...");
+       printf_P(PSTR("rate..."));
        venus634_rate();
        wait_ack(M_RATE);
 
-       printf("GPS configuration done !\n");
+       printf_P(PSTR("GPS configuration done !\n"));
 }
 
 /*
@@ -592,7 +594,7 @@ int gps_loop(void)
                        }
                }
                else
-                       printf("%s", buf);
+                       printf_P(PSTR("%s"), buf);
 
        }
 
index 2966ee41d4ac4617f6e95ac835633dbbc19f375e..a149f5d493f6b4c403353d614cb1a799bd3eec10 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <aversive/pgmspace.h>
 #include <aversive/wait.h>
 
 #include "i2cm_sw.h"
@@ -68,19 +69,19 @@ static uint8_t read_reg_len(uint8_t i2c_addr, uint8_t reg_addr,
 
        err = i2cm_send(i2c_addr, &reg_addr, 1);
        if (err) {
-               printf("read reg len: i2c error send\r\n");
+               printf_P(PSTR("read reg len: i2c error send\r\n"));
                return err;
        }
 
        err = i2cm_recv(i2c_addr, len);
        if (err) {
-               printf("read reg len: i2c error recv\r\n");
+               printf_P(PSTR("read reg len: i2c error recv\r\n"));
                return err;
        }
 
        err = i2cm_get_recv_buffer(values, len);
        if (err != len) {
-               printf("read reg len: i2c error get recv\r\n");
+               printf_P(PSTR("read reg len: i2c error get recv\r\n"));
                return 0xFF;
        }
 
@@ -153,14 +154,15 @@ static uint8_t send_mpu6050_cmd(uint8_t address, uint8_t reg, uint8_t val)
 
        err = i2cm_send(address, (unsigned char*)buffer, 2);
        if (err)
-               printf("send_mpu6050_cmd(reg=%x): error %.2X\r\n", reg, err);
+               printf_P(PSTR("send_mpu6050_cmd(reg=%x): error %.2X\r\n"),
+                       reg, err);
 
        err = read_reg(address, reg, &check);
        if (err)
                return err;
 
        if (check != val) {
-               printf("reg %x: %x != %x\r\n", reg, check, val);
+               printf_P(PSTR("reg %x: %x != %x\r\n"), reg, check, val);
                return 0xff;
        }
 
@@ -186,7 +188,8 @@ static void mpu6050_compute_drift(void)
                s_gy += g_values[1];
                s_gz += g_values[2];
        }
-       printf("%"PRId32" %"PRId32" %"PRId32" (%"PRIu16") \r\n", s_gx, s_gy, s_gz, i);
+       printf_P(PSTR("%"PRId32" %"PRId32" %"PRId32" (%"PRIu16") \r\n"),
+               s_gx, s_gy, s_gz, i);
        s_gx /= i;
        s_gy /= i;
        s_gz /= i;
@@ -194,8 +197,8 @@ static void mpu6050_compute_drift(void)
        drift_g[0] = s_gx;
        drift_g[1] = s_gy;
        drift_g[2] = s_gz;
-       printf("gyro drift:\r\n");
-       printf("%d %d %d\r\n",
+       printf_P(PSTR("gyro drift:\r\n"));
+       printf_P(PSTR("%d %d %d\r\n"),
               drift_g[0],
               drift_g[1],
               drift_g[2]);
@@ -209,11 +212,11 @@ static uint8_t setup_mpu9150_magneto(void)
 
        /* XXX doesn't work, no answer from magneto */
        /* for (i = 0; i < 127; i++) { */
-       /*      printf("i=%d\r\n", i); */
+       /*      printf_P(PSTR("i=%d\r\n"), i); */
        /*      err = send_mpu6050_cmd(i, 0x0A, 0x00); //PowerDownMode */
 
        /*      if (err == 0) */
-       /*              printf("COIN\r\n"); */
+       /*              printf_P(PSTR("COIN\r\n")); */
        /* } */
        send_mpu6050_cmd(MPU6050_MAGNETO_ADDRESS, 0x0A, 0x00); //PowerDownMode
        send_mpu6050_cmd(MPU6050_MAGNETO_ADDRESS, 0x0A, 0x0F); //SelfTest
@@ -343,9 +346,9 @@ int8_t mpu6050_init(void)
 
        setup_mpu9150_magneto();
 
-       printf("MPU6050 Setup Complete\r\n");
+       printf_P(PSTR("MPU6050 Setup Complete\r\n"));
        mpu6050_compute_drift();
-       printf("MPU6050 drift computed\r\n");
+       printf_P(PSTR("MPU6050 drift computed\r\n"));
 
        return 0;
 }
index 97496f4e554fc1e92f3367bb536993f9aea09f05..edc83ea56b01dced538772a7b2f0a6dce002ae83 100644 (file)
@@ -110,14 +110,14 @@ int8_t sd_log_open(void)
                return -1;
        }
 
-       printf("choose log file name\n");
+       printf_P(PSTR("choose log file name\n"));
        while (1) {
                snprintf(name, sizeof(name), "log%.4d", i++);
                if (!find_file_in_dir(fs, dd, name, &file_entry))
                        break;
        }
 
-       printf("create log file %s\n", name);
+       printf_P(PSTR("create log file %s\n"), name);
        if (!fat_create_file(dd, name, &file_entry)) {
                printf_P(PSTR("error creating file: "));
        }
index 8f962e33bbf09b31aee8a3d25c27805fb9f1d2ca..4e79c52d4da103387e44a30a8987d31924282050 100644 (file)
@@ -90,7 +90,7 @@ static void cmd_bootloader_parsed(void *parsed_result, void *data)
 #ifndef HOST_VERSION
        bootloader();
 #else
-       printf("not implemented\n");
+       printf_P(PSTR("not implemented\n"));
 #endif
 }
 
@@ -361,9 +361,9 @@ static void cmd_stack_space_parsed(void *parsed_result, void *data)
        (void)parsed_result;
        (void)data;
 #ifdef HOST_VERSION
-       printf("not implemented\n");
+       printf_P(PSTR("not implemented\n"));
 #else
-       printf("res stack: %d\r\n", min_stack_space_available());
+       printf_P(PSTR("res stack: %d\r\n"), min_stack_space_available());
 #endif
 }
 
index 0d46bf2ebc84ca1c473c10fe77fbb8fe4c2c24af..de88d8ba540dca86781dd6b1f5df983487cf6096 100644 (file)
@@ -193,7 +193,7 @@ int main(void)
        /* register default channel with a callback */
        if (xbee_register_channel(xbee_dev, XBEE_DEFAULT_CHANNEL,
                                  xbeeapp_rx, NULL) < 0) {
-               fprintf(stderr, "cannot register default channel\n");
+               printf_P(PSTR("cannot register default channel\n"));
                return -1;
        }