You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2017/02/24 19:38:36 UTC
[41/50] incubator-mynewt-core git commit: Printing sensor data as
float string
Printing sensor data as float string
- Making sensor_ftostr() global, so that it can be used by any shell.
- Adding config settings for ACC, MAG, GYRO as per the datasheet
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/40b9b6b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/40b9b6b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/40b9b6b5
Branch: refs/heads/develop
Commit: 40b9b6b511cf624f7a17ba7fc84a6ef4dacc7bf9
Parents: b483d34
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu Feb 16 12:21:21 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu Feb 16 12:21:21 2017 -0800
----------------------------------------------------------------------
hw/drivers/sensors/bno055/src/bno055_priv.h | 64 +++++++++++++++++++++++
hw/drivers/sensors/bno055/src/bno055_shell.c | 29 ++++++----
hw/sensor/include/sensor/sensor.h | 3 ++
hw/sensor/src/sensor_shell.c | 20 +++----
4 files changed, 98 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b9b6b5/hw/drivers/sensors/bno055/src/bno055_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_priv.h b/hw/drivers/sensors/bno055/src/bno055_priv.h
index 295e83b..97f4280 100644
--- a/hw/drivers/sensors/bno055/src/bno055_priv.h
+++ b/hw/drivers/sensors/bno055/src/bno055_priv.h
@@ -237,4 +237,68 @@
#define BNO055_GYRO_ANY_MOTION_THRES_ADDR 0X1E
#define BNO055_GYRO_ANY_MOTION_SET_ADDR 0X1F
+/* Accelerometer config */
+#define BNO055_ACC_CFG_2G 0x0
+#define BNO055_ACC_CFG_4G 0x1
+#define BNO055_ACC_CFG_8G 0x2
+#define BNO055_ACC_CFG_16G 0x3
+
+#define BNO055_ACC_CFG_BW_7_81HZ (0x0 << 2)
+#define BNO055_ACC_CFG_BW_15_63HZ (0x1 << 2)
+#define BNO055_ACC_CFG_BW_31_25HZ (0x2 << 2)
+#define BNO055_ACC_CFG_BW_6_25HZ (0x3 << 2)
+#define BNO055_ACC_CFG_BW_125HZ (0x4 << 2)
+#define BNO055_ACC_CFG_BW_250HZ (0x5 << 2)
+#define BNO055_ACC_CFG_BW_500HZ (0x6 << 2)
+#define BNO055_ACC_CFG_BW_1000HZ (0x7 << 2)
+
+#define BNO055_ACC_CFG_OPR_MODE_NORMAL (0x0 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_SUSPEND (0x1 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_LOWPWR1 (0x2 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_STD (0x3 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_LOWPWR2 (0x4 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_DSUSPEND (0x5 << 5)
+
+/* Gyroscope config */
+#define BNO055_GYR_CFG_RNG_2000DPS 0x0
+#define BNO055_GYR_CFG_RNG_1000DPS 0x1
+#define BNO055_GYR_CFG_RNG_500DPS 0x2
+#define BNO055_GYR_CFG_RNG_250DPS 0x3
+#define BNO055_GYR_CFG_RNG_125DPS 0x4
+
+#define BNO055_GYR_CFG_BW_523HZ (0x0 << 3)
+#define BNO055_GYR_CFG_BW_230HZ (0x1 << 3)
+#define BNO055_GYR_CFG_BW_116HZ (0x2 << 3)
+#define BNO055_GYR_CFG_BW_47HZ (0x3 << 3)
+#define BNO055_GYR_CFG_BW_23HZ (0x4 << 3)
+#define BNO055_GYR_CFG_BW_12HZ (0x5 << 3)
+#define BNO055_GYR_CFG_BW_64HZ (0x6 << 3)
+#define BNO055_GYR_CFG_BW_32HZ (0x7 << 3)
+
+#define BNO055_GYR_CFG_OPR_MODE_NORMAL (0x0 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_FAST_PWR_UP (0x1 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_DSUSPEND (0x2 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_SUSPEND (0x3 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_ADV_PWR_SAVE (0x4 << 5)
+
+/* Magnetometer config */
+#define BNO055_MAG_CFG_BW_2HZ 0x0
+#define BNO055_MAG_CFG_BW_6HZ 0x1
+#define BNO055_MAG_CFG_BW_8HZ 0x2
+#define BNO055_MAG_CFG_BW_10HZ 0x3
+#define BNO055_MAG_CFG_BW_15HZ 0x4
+#define BNO055_MAG_CFG_BW_20HZ 0x5
+#define BNO055_MAG_CFG_BW_25HZ 0x6
+#define BNO055_MAG_CFG_BW_30HZ 0x7
+
+#define BNO055_MAG_CFG_OPR_MODE_LOWPWR (0x0 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_REG (0x1 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_EREG (0x2 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_HIGHACC (0x3 << 3)
+
+#define BNO055_MAG_CFG_PWR_MODE_NORMAL (0x0 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_SLEEP (0x1 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_SUSPEND (0x2 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE (0x3 << 5)
+
#define BNO055_ID 0xA0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b9b6b5/hw/drivers/sensors/bno055/src/bno055_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_shell.c b/hw/drivers/sensors/bno055/src/bno055_shell.c
index 9de1ed5..f370655 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -160,6 +160,7 @@ bno055_shell_cmd_read(int argc, char **argv)
struct sensor_euler_data *sed;
struct sensor_accel_data *sad;
int type;
+ char tmpstr[13];
type = 0;
if (argc > 4) {
@@ -192,9 +193,12 @@ bno055_shell_cmd_read(int argc, char **argv)
goto err;
}
sqd = databuf;
- console_printf("x:%u y:%u z:%u w:%u\n", (unsigned int)sqd->sqd_x,
- (unsigned int)sqd->sqd_y, (unsigned int)sqd->sqd_z,
- (unsigned int)sqd->sqd_w);
+
+ console_printf("x:%s ", sensor_ftostr(sqd->sqd_x, tmpstr, 13));
+ console_printf("y:%s ", sensor_ftostr(sqd->sqd_y, tmpstr, 13));
+ console_printf("z:%s ", sensor_ftostr(sqd->sqd_z, tmpstr, 13));
+ console_printf("w:%s\n", sensor_ftostr(sqd->sqd_w, tmpstr, 13));
+
} else if (type == SENSOR_TYPE_EULER) {
rc = bno055_get_vector_data(databuf, type);
if (rc) {
@@ -202,8 +206,11 @@ bno055_shell_cmd_read(int argc, char **argv)
goto err;
}
sed = databuf;
- console_printf("h:%u r:%u p:%u\n", (unsigned int)sed->sed_h,
- (unsigned int)sed->sed_r, (unsigned int)sed->sed_p);
+
+ console_printf("h:%s ", sensor_ftostr(sed->sed_h, tmpstr, 13));
+ console_printf("r:%s ", sensor_ftostr(sed->sed_r, tmpstr, 13));
+ console_printf("p:%s\n", sensor_ftostr(sed->sed_p, tmpstr, 13));
+
} else {
rc = bno055_get_vector_data(databuf, type);
if (rc) {
@@ -211,11 +218,15 @@ bno055_shell_cmd_read(int argc, char **argv)
goto err;
}
sad = databuf;
- console_printf("x:%u y:%u z:%u\n", (unsigned int)sad->sad_x,
- (unsigned int)sad->sad_y, (unsigned int)sad->sad_z);
+
+ console_printf("x:%s ", sensor_ftostr(sad->sad_x, tmpstr, 13));
+ console_printf("y:%s ", sensor_ftostr(sad->sad_y, tmpstr, 13));
+ console_printf("z:%s\n", sensor_ftostr(sad->sad_z, tmpstr, 13));
}
}
+ free(databuf);
+
return 0;
err:
return rc;
@@ -242,7 +253,7 @@ bno055_shell_cmd_opr_mode(int argc, char **argv)
if (bno055_shell_stol(argv[2], 0, 16, &val)) {
return bno055_shell_err_invalid_arg(argv[2]);
}
- /* Make sure mode is */
+ /* Make sure mode is valid */
if (val > BNO055_OPERATION_MODE_NDOF) {
return bno055_shell_err_invalid_arg(argv[2]);
}
@@ -279,7 +290,7 @@ bno055_shell_cmd_pwr_mode(int argc, char **argv)
if (bno055_shell_stol(argv[2], 0, 16, &val)) {
return bno055_shell_err_invalid_arg(argv[2]);
}
- /* Make sure mode is */
+ /* Make sure mode is valid */
if (val > BNO055_POWER_MODE_SUSPEND) {
return bno055_shell_err_invalid_arg(argv[2]);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b9b6b5/hw/sensor/include/sensor/sensor.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index d707e2b..769a148 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -325,6 +325,9 @@ struct sensor *sensor_mgr_find_next(sensor_mgr_compare_func_t, void *,
struct sensor *sensor_mgr_find_next_bytype(sensor_type_t, struct sensor *);
struct sensor *sensor_mgr_find_next_bydevname(char *, struct sensor *);
+char*
+sensor_ftostr(float num, char *fltstr, int len);
+
/**
* }@
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40b9b6b5/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index c2c68b1..bd73cfa 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -83,10 +83,12 @@ struct sensor_shell_read_ctx {
int num_entries;
};
-static char*
-floattostr(float num, char *fltstr, int len)
+char*
+sensor_ftostr(float num, char *fltstr, int len)
{
- snprintf(fltstr, len, "%s%d.%09ld", num < 0.0 ? "-":"", (int)num,
+ memset(fltstr, 0, len);
+
+ snprintf(fltstr, len, "%s%d.%09ld", num < 0.0 ? "-":"", abs((int)num),
labs((long int)((num - (float)((int)num)) * 1000000000)));
return fltstr;
}
@@ -107,13 +109,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 = %s ", floattostr(sad->sad_x, tmpstr, 13));
+ console_printf("x = %s ", sensor_ftostr(sad->sad_x, tmpstr, 13));
}
if (sad->sad_y != SENSOR_ACCEL_DATA_UNUSED) {
- console_printf("y = %s ", floattostr(sad->sad_y, tmpstr, 13));
+ console_printf("y = %s ", sensor_ftostr(sad->sad_y, tmpstr, 13));
}
if (sad->sad_z != SENSOR_ACCEL_DATA_UNUSED) {
- console_printf("z = %s", floattostr(sad->sad_z, tmpstr, 13));
+ console_printf("z = %s", sensor_ftostr(sad->sad_z, tmpstr, 13));
}
console_printf("\n");
}
@@ -121,13 +123,13 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
if (ctx->type == SENSOR_TYPE_MAGNETIC_FIELD) {
smd = (struct sensor_mag_data *) data;
if (smd->smd_x != SENSOR_MAG_DATA_UNUSED) {
- console_printf("x = %i, ", (int)smd->smd_x);
+ console_printf("x = %s ", sensor_ftostr(smd->smd_x, tmpstr, 13));
}
if (smd->smd_y != SENSOR_MAG_DATA_UNUSED) {
- console_printf("y = %i, ", (int)smd->smd_y);
+ console_printf("y = %s ", sensor_ftostr(smd->smd_y, tmpstr, 13));
}
if (smd->smd_z != SENSOR_MAG_DATA_UNUSED) {
- console_printf("z = %i", (int)smd->smd_z);
+ console_printf("z = %s ", sensor_ftostr(smd->smd_z, tmpstr, 13));
}
console_printf("\n");
}