update accel to use floating point numbers, change types of generic sensor interfaces
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/f6b1db0f Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f6b1db0f Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f6b1db0f Branch: refs/heads/develop Commit: f6b1db0fcef7036efb761a2b6c59347aa8944bd8 Parents: 9482961 Author: Sterling Hughes <[email protected]> Authored: Sun Dec 18 14:03:52 2016 -0800 Committer: Sterling Hughes <[email protected]> Committed: Sun Dec 18 14:03:52 2016 -0800 ---------------------------------------------------------------------- hw/drivers/sensors/sim/src/generic_accel.c | 8 ++++---- hw/sensor/include/sensor/accel.h | 8 ++++---- hw/sensor/include/sensor/sensor.h | 11 ++++------- hw/sensor/src/sensor_shell.c | 6 +++--- 4 files changed, 15 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b1db0f/hw/drivers/sensors/sim/src/generic_accel.c ---------------------------------------------------------------------- diff --git a/hw/drivers/sensors/sim/src/generic_accel.c b/hw/drivers/sensors/sim/src/generic_accel.c index cbed0d0..df7316a 100644 --- a/hw/drivers/sensors/sim/src/generic_accel.c +++ b/hw/drivers/sensors/sim/src/generic_accel.c @@ -134,15 +134,15 @@ sim_accel_sensor_read(struct sensor *sensor, sensor_type_t type, * if number of axises is configured, up to 3-axises of data can be * returned. */ - sad.sad_x = 0; + sad.sad_x = 0.0; sad.sad_y = SENSOR_ACCEL_DATA_UNUSED; sad.sad_z = SENSOR_ACCEL_DATA_UNUSED; if (sa->sa_cfg.sac_nr_axises > 1) { - sad.sad_y = 0; + sad.sad_y = 0.0; } if (sa->sa_cfg.sac_nr_axises > 2) { - sad.sad_z = 0; + sad.sad_z = 0.0; } /* Call data function for each of the generated readings. */ @@ -169,7 +169,7 @@ sim_accel_sensor_get_config(struct sensor *sensor, sensor_type_t type, goto err; } - cfg->sc_valtype = SENSOR_VALUE_TYPE_MS2_TRIPLET; + cfg->sc_valtype = SENSOR_VALUE_TYPE_FLOAT_TRIPLET; return (0); err: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b1db0f/hw/sensor/include/sensor/accel.h ---------------------------------------------------------------------- diff --git a/hw/sensor/include/sensor/accel.h b/hw/sensor/include/sensor/accel.h index 431e05c..17e3561 100644 --- a/hw/sensor/include/sensor/accel.h +++ b/hw/sensor/include/sensor/accel.h @@ -32,15 +32,15 @@ extern "C" { * All values are in MS^2 */ struct sensor_accel_data { - int32_t sad_x; - int32_t sad_y; - int32_t sad_z; + float sad_x; + float sad_y; + float sad_z; } __attribute__((packed)); /** * Accelerometer data is unused for this field. */ -#define SENSOR_ACCEL_DATA_UNUSED (0xFFFFFFFF) +#define SENSOR_ACCEL_DATA_UNUSED (-1) #ifdef __cplusplus } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b1db0f/hw/sensor/include/sensor/sensor.h ---------------------------------------------------------------------- diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h index 2ec36f6..2f99ea2 100644 --- a/hw/sensor/include/sensor/sensor.h +++ b/hw/sensor/include/sensor/sensor.h @@ -97,16 +97,13 @@ typedef enum { */ #define SENSOR_VALUE_TYPE_FLOAT (2) /** - * Meters per second squared. - * - * 32-bit signed integer, with 0xFFFFFFFF reserved for unused. + * 32-bit integer triplet. */ -#define SENSOR_VALUE_TYPE_MS2 (3) +#define SENSOR_VALUE_TYPE_INT32_TRIPLET (3) /** - * Triplet of meters per second squared. + * 32-bit floating point number triplet. */ -#define SENSOR_VALUE_TYPE_MS2_TRIPLET (4) - +#define SENSOR_VALUE_TYPE_FLOAT_TRIPLET (4) /** http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6b1db0f/hw/sensor/src/sensor_shell.c ---------------------------------------------------------------------- diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c index dbde99f..e975da6 100644 --- a/hw/sensor/src/sensor_shell.c +++ b/hw/sensor/src/sensor_shell.c @@ -93,13 +93,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 = %d, ", sad->sad_x); + console_printf("x = %f, ", sad->sad_x); } if (sad->sad_y != SENSOR_ACCEL_DATA_UNUSED) { - console_printf("y = %d, ", sad->sad_y); + console_printf("y = %f, ", sad->sad_y); } if (sad->sad_z != SENSOR_ACCEL_DATA_UNUSED) { - console_printf("z = %d", sad->sad_z); + console_printf("z = %f", sad->sad_z); } console_printf("\n"); }
