Repository: incubator-mynewt-core Updated Branches: refs/heads/sensors_branch d983810db -> fbbad56bb
Changing sensor API display Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fbbad56b Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fbbad56b Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fbbad56b Branch: refs/heads/sensors_branch Commit: fbbad56bb178bc6b5dbf0f7e83f15deed5e2f7fd Parents: d983810 Author: Vipul Rahane <vipulrah...@apache.org> Authored: Wed Jan 25 16:43:16 2017 -0800 Committer: Vipul Rahane <vipulrah...@apache.org> Committed: Wed Jan 25 16:43:16 2017 -0800 ---------------------------------------------------------------------- apps/slinky/src/main.c | 2 +- hw/sensor/src/sensor_shell.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbbad56b/apps/slinky/src/main.c ---------------------------------------------------------------------- diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c index cd585a4..4b0e870 100755 --- a/apps/slinky/src/main.c +++ b/apps/slinky/src/main.c @@ -235,7 +235,7 @@ init_tasks(void) TASK2_PRIO, OS_WAIT_FOREVER, pstack, TASK2_STACK_SIZE); } -#ifdef ARCH_arduino_zero +#if !ARCH_sim static int config_sensor(void) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbbad56b/hw/sensor/src/sensor_shell.c ---------------------------------------------------------------------- diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c index a5ee643..6312f81 100644 --- a/hw/sensor/src/sensor_shell.c +++ b/hw/sensor/src/sensor_shell.c @@ -22,6 +22,7 @@ #if MYNEWT_VAL(SENSOR_CLI) #include <string.h> +#include <stdio.h> #include <errno.h> #include <assert.h> @@ -81,12 +82,21 @@ struct sensor_shell_read_ctx { int num_entries; }; +static char* +floattostr(float num, char *fltstr, int len) +{ + snprintf(fltstr, len, "%s%d.%09ld", num < 0.0 ? "-":"", (int)num, + labs((long int)((num - (float)((int)num)) * 1000000000))); + return fltstr; +} + static int sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data) { struct sensor_shell_read_ctx *ctx; struct sensor_accel_data *sad; struct sensor_mag_data *smd; + char tmpstr[13]; ctx = (struct sensor_shell_read_ctx *) arg; @@ -95,13 +105,13 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data) if (ctx->type == SENSOR_TYPE_ACCELEROMETER) { sad = (struct sensor_accel_data *) data; if (sad->sad_x != SENSOR_ACCEL_DATA_UNUSED) { - console_printf("x = %x, ", (uint32_t)sad->sad_x * 1000000000); + console_printf("x = %s ", floattostr(sad->sad_x, tmpstr, 13)); } if (sad->sad_y != SENSOR_ACCEL_DATA_UNUSED) { - console_printf("y = %x, ", (uint32_t)sad->sad_y * 1000000000); + console_printf("y = %s ", floattostr(sad->sad_y, tmpstr, 13)); } if (sad->sad_z != SENSOR_ACCEL_DATA_UNUSED) { - console_printf("z = %x.", (uint32_t)sad->sad_z * 1000000000); + console_printf("z = %s", floattostr(sad->sad_z, tmpstr, 13)); } console_printf("\n"); }