[31/50] incubator-mynewt-core git commit: Adding tsl2561 shell back
Adding tsl2561 shell back 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/3559c73a Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3559c73a Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3559c73a Branch: refs/heads/develop Commit: 3559c73ac1a0de7fd34f9802e401fc8c6c48bfc2 Parents: 9f59c4f Author: Vipul RahaneAuthored: Fri Feb 3 15:25:53 2017 -0800 Committer: Vipul Rahane Committed: Fri Feb 3 15:25:53 2017 -0800 -- apps/slinky/src/main.c | 7 ++ .../sensors/tsl2561/include/tsl2561/tsl2561.h | 5 ++ hw/drivers/sensors/tsl2561/src/tsl2561.c| 84 hw/drivers/sensors/tsl2561/src/tsl2561_priv.h | 5 -- hw/drivers/sensors/tsl2561/src/tsl2561_shell.c | 24 -- 5 files changed, 112 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/apps/slinky/src/main.c -- diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c index e87aa0e..718d690 100755 --- a/apps/slinky/src/main.c +++ b/apps/slinky/src/main.c @@ -47,6 +47,9 @@ #include #include #include +#if MYNEWT_VAL(TSL2561_CLI) +#include +#endif #ifdef ARCH_sim #include @@ -377,6 +380,10 @@ main(int argc, char **argv) } #endif +#if MYNEWT_VAL(TSL2561_CLI) +tsl2561_shell_init(); +#endif + config_sensor(); /* http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h -- diff --git a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h b/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h index 2f093be..046967f 100644 --- a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h +++ b/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h @@ -189,6 +189,11 @@ int tsl2561_clear_interrupt(void); int tsl2561_config(struct tsl2561 *, struct tsl2561_cfg *); +#if MYNEWT_VAL(TSL2561_CLI) +int tsl2561_shell_init(void); +#endif + + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/hw/drivers/sensors/tsl2561/src/tsl2561.c -- diff --git a/hw/drivers/sensors/tsl2561/src/tsl2561.c b/hw/drivers/sensors/tsl2561/src/tsl2561.c index 8f90718..c9f7531 100644 --- a/hw/drivers/sensors/tsl2561/src/tsl2561.c +++ b/hw/drivers/sensors/tsl2561/src/tsl2561.c @@ -58,6 +58,13 @@ /* ToDo: Add timer based polling in bg and data ready callback (os_event?) */ /* ToDo: Move values to struct incl. address to allow multiple instances */ +#if MYNEWT_VAL(TSL2561_CLI) +uint8_t g_tsl2561_gain; +uint8_t g_tsl2561_integration_time; +uint8_t g_tsl2561_enabled; +#endif + + #if MYNEWT_VAL(TSL2561_STATS) /* Define the stats section and records */ STATS_SECT_START(tsl2561_stat_section) @@ -217,6 +224,83 @@ err: return rc; } +#if MYNEWT_VAL(TSL2561_CLI) +int +tsl2561_enable(uint8_t state) +{ +int rc; + +/* Enable the device by setting the control bit to 0x03 */ +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, +state ? TSL2561_CONTROL_POWERON : +TSL2561_CONTROL_POWEROFF); +if (!rc) { +g_tsl2561_enabled = state ? 1 : 0; +} + +return rc; +} + +uint8_t +tsl2561_get_enable (void) +{ +return g_tsl2561_enabled; +} + +int +tsl2561_set_integration_time(uint8_t int_time) +{ +int rc; + +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, +g_tsl2561_integration_time | g_tsl2561_gain); +if (rc) { +goto error; +} + +g_tsl2561_integration_time = int_time; + +error: +return rc; +} + +uint8_t +tsl2561_get_integration_time(void) +{ +return g_tsl2561_integration_time; +} + +int +tsl2561_set_gain(uint8_t gain) +{ +int rc; + +if ((gain != TSL2561_LIGHT_GAIN_1X) && (gain != TSL2561_LIGHT_GAIN_16X)) { +TSL2561_ERR("Invalid gain value\n"); +rc = EINVAL; +goto error; +} + +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, +g_tsl2561_integration_time | gain); +if (rc) { +goto error; +} + +g_tsl2561_gain = gain; + +error: +return rc; +} + +uint8_t +tsl2561_get_gain(void) +{ +return g_tsl2561_gain; +} +#endif + + int tsl2561_get_data(uint16_t *broadband, uint16_t *ir, struct tsl2561 *tsl2561) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/hw/drivers/sensors/tsl2561/src/tsl2561_priv.h
incubator-mynewt-core git commit: Adding tsl2561 shell back
Repository: incubator-mynewt-core Updated Branches: refs/heads/sensors_branch 9f59c4f06 -> 3559c73ac Adding tsl2561 shell back 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/3559c73a Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3559c73a Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3559c73a Branch: refs/heads/sensors_branch Commit: 3559c73ac1a0de7fd34f9802e401fc8c6c48bfc2 Parents: 9f59c4f Author: Vipul RahaneAuthored: Fri Feb 3 15:25:53 2017 -0800 Committer: Vipul Rahane Committed: Fri Feb 3 15:25:53 2017 -0800 -- apps/slinky/src/main.c | 7 ++ .../sensors/tsl2561/include/tsl2561/tsl2561.h | 5 ++ hw/drivers/sensors/tsl2561/src/tsl2561.c| 84 hw/drivers/sensors/tsl2561/src/tsl2561_priv.h | 5 -- hw/drivers/sensors/tsl2561/src/tsl2561_shell.c | 24 -- 5 files changed, 112 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/apps/slinky/src/main.c -- diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c index e87aa0e..718d690 100755 --- a/apps/slinky/src/main.c +++ b/apps/slinky/src/main.c @@ -47,6 +47,9 @@ #include #include #include +#if MYNEWT_VAL(TSL2561_CLI) +#include +#endif #ifdef ARCH_sim #include @@ -377,6 +380,10 @@ main(int argc, char **argv) } #endif +#if MYNEWT_VAL(TSL2561_CLI) +tsl2561_shell_init(); +#endif + config_sensor(); /* http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h -- diff --git a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h b/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h index 2f093be..046967f 100644 --- a/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h +++ b/hw/drivers/sensors/tsl2561/include/tsl2561/tsl2561.h @@ -189,6 +189,11 @@ int tsl2561_clear_interrupt(void); int tsl2561_config(struct tsl2561 *, struct tsl2561_cfg *); +#if MYNEWT_VAL(TSL2561_CLI) +int tsl2561_shell_init(void); +#endif + + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3559c73a/hw/drivers/sensors/tsl2561/src/tsl2561.c -- diff --git a/hw/drivers/sensors/tsl2561/src/tsl2561.c b/hw/drivers/sensors/tsl2561/src/tsl2561.c index 8f90718..c9f7531 100644 --- a/hw/drivers/sensors/tsl2561/src/tsl2561.c +++ b/hw/drivers/sensors/tsl2561/src/tsl2561.c @@ -58,6 +58,13 @@ /* ToDo: Add timer based polling in bg and data ready callback (os_event?) */ /* ToDo: Move values to struct incl. address to allow multiple instances */ +#if MYNEWT_VAL(TSL2561_CLI) +uint8_t g_tsl2561_gain; +uint8_t g_tsl2561_integration_time; +uint8_t g_tsl2561_enabled; +#endif + + #if MYNEWT_VAL(TSL2561_STATS) /* Define the stats section and records */ STATS_SECT_START(tsl2561_stat_section) @@ -217,6 +224,83 @@ err: return rc; } +#if MYNEWT_VAL(TSL2561_CLI) +int +tsl2561_enable(uint8_t state) +{ +int rc; + +/* Enable the device by setting the control bit to 0x03 */ +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, +state ? TSL2561_CONTROL_POWERON : +TSL2561_CONTROL_POWEROFF); +if (!rc) { +g_tsl2561_enabled = state ? 1 : 0; +} + +return rc; +} + +uint8_t +tsl2561_get_enable (void) +{ +return g_tsl2561_enabled; +} + +int +tsl2561_set_integration_time(uint8_t int_time) +{ +int rc; + +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, +g_tsl2561_integration_time | g_tsl2561_gain); +if (rc) { +goto error; +} + +g_tsl2561_integration_time = int_time; + +error: +return rc; +} + +uint8_t +tsl2561_get_integration_time(void) +{ +return g_tsl2561_integration_time; +} + +int +tsl2561_set_gain(uint8_t gain) +{ +int rc; + +if ((gain != TSL2561_LIGHT_GAIN_1X) && (gain != TSL2561_LIGHT_GAIN_16X)) { +TSL2561_ERR("Invalid gain value\n"); +rc = EINVAL; +goto error; +} + +rc = tsl2561_write8(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING, +g_tsl2561_integration_time | gain); +if (rc) { +goto error; +} + +g_tsl2561_gain = gain; + +error: +return rc; +} + +uint8_t +tsl2561_get_gain(void) +{ +return g_tsl2561_gain; +} +#endif + + int tsl2561_get_data(uint16_t *broadband, uint16_t *ir, struct tsl2561 *tsl2561) {