Skip to content
Snippets Groups Projects
Verified Commit 1aaffea6 authored by koalo's avatar koalo Committed by rahix
Browse files

feat(bhi160): Disable all sensors in hardware_reset

parent afcef864
No related branches found
No related tags found
1 merge request!163Support for BHI160
...@@ -113,6 +113,7 @@ typedef _Bool bool; ...@@ -113,6 +113,7 @@ typedef _Bool bool;
#define API_BHI160_ENABLE 0xe0 #define API_BHI160_ENABLE 0xe0
#define API_BHI160_DISABLE 0xe1 #define API_BHI160_DISABLE 0xe1
#define API_BHI160_DISABLE_ALL 0xe2
/* clang-format on */ /* clang-format on */
...@@ -1029,6 +1030,11 @@ API(API_BHI160_DISABLE, int epic_bhi160_disable_sensor( ...@@ -1029,6 +1030,11 @@ API(API_BHI160_DISABLE, int epic_bhi160_disable_sensor(
enum bhi160_sensor_type sensor_type enum bhi160_sensor_type sensor_type
)); ));
/**
* Disable all BHI160 sensors.
*/
API(API_BHI160_DISABLE_ALL, void epic_bhi160_disable_all_sensors());
/** /**
* Vibration Motor * Vibration Motor
* =============== * ===============
......
...@@ -62,6 +62,9 @@ static SemaphoreHandle_t bhi160_mutex = NULL; ...@@ -62,6 +62,9 @@ static SemaphoreHandle_t bhi160_mutex = NULL;
/* Streams */ /* Streams */
static struct stream_info bhi160_streams[10]; static struct stream_info bhi160_streams[10];
/* Active */
static bool bhi160_sensor_active[10] = { 0 };
/* -- Utilities -------------------------------------------------------- {{{ */ /* -- Utilities -------------------------------------------------------- {{{ */
/* /*
* Retrieve the data size for a sensor. This value is needed for the creation * Retrieve the data size for a sensor. This value is needed for the creation
...@@ -165,6 +168,9 @@ int epic_bhi160_enable_sensor( ...@@ -165,6 +168,9 @@ int epic_bhi160_enable_sensor(
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
return bhyret; return bhyret;
} }
bhi160_sensor_active[sensor_type] = true;
xSemaphoreGive(bhi160_mutex); xSemaphoreGive(bhi160_mutex);
} else { } else {
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
...@@ -189,7 +195,9 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type) ...@@ -189,7 +195,9 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
if (xSemaphoreTake(bhi160_mutex, LOCK_WAIT) == pdTRUE) { if (xSemaphoreTake(bhi160_mutex, LOCK_WAIT) == pdTRUE) {
struct stream_info *stream = &bhi160_streams[sensor_type]; struct stream_info *stream = &bhi160_streams[sensor_type];
int streamret = stream_deregister(bhi160_lookup_sd(sensor_type), stream); int streamret = stream_deregister(
bhi160_lookup_sd(sensor_type), stream
);
if (streamret < 0) { if (streamret < 0) {
xSemaphoreGive(bhi160_mutex); xSemaphoreGive(bhi160_mutex);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
...@@ -197,12 +205,15 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type) ...@@ -197,12 +205,15 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
} }
vQueueDelete(stream->queue); vQueueDelete(stream->queue);
stream->queue = NULL; stream->queue = NULL;
int bhyret = bhy_disable_virtual_sensor(vs_id, VS_WAKEUP); int bhyret = bhy_disable_virtual_sensor(vs_id, VS_WAKEUP);
if (bhyret < 0) { if (bhyret < 0) {
xSemaphoreGive(bhi160_mutex); xSemaphoreGive(bhi160_mutex);
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
return bhyret; return bhyret;
} }
bhi160_sensor_active[sensor_type] = false;
xSemaphoreGive(bhi160_mutex); xSemaphoreGive(bhi160_mutex);
} else { } else {
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
...@@ -212,6 +223,16 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type) ...@@ -212,6 +223,16 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
hwlock_release(HWLOCK_I2C); hwlock_release(HWLOCK_I2C);
return 0; return 0;
} }
void epic_bhi160_disable_all_sensors()
{
for (int i = 0; i < sizeof(bhi160_sensor_active); i++) {
if (bhi160_sensor_active[i]) {
epic_bhi160_disable_sensor(i);
}
}
}
/* }}} */ /* }}} */
/* -- Driver ----------------------------------------------------------- {{{ */ /* -- Driver ----------------------------------------------------------- {{{ */
......
...@@ -259,6 +259,11 @@ int hardware_reset(void) ...@@ -259,6 +259,11 @@ int hardware_reset(void)
*/ */
display_init_slim(); display_init_slim();
/*
* BHI160
*/
epic_bhi160_disable_all_sensors();
/* /*
* BME680 Sensor * BME680 Sensor
*/ */
......
...@@ -4,18 +4,19 @@ import utime ...@@ -4,18 +4,19 @@ import utime
disp = display.open() disp = display.open()
bhi = bhi160.BHI160Accelerometer()
while True: while True:
with bhi160.BHI160Accelerometer(sample_rate=20) as bhi: samples = bhi.read()
utime.sleep(0.25) if len(samples) > 0:
samples = bhi.read() disp.clear()
if len(samples) > 0: sample = samples[0]
disp.clear()
sample = samples[0]
disp.print("Accelerometer", posy=0) disp.print("Accelerometer", posy=0)
disp.print("X: %f" % sample["x"], posy=20) disp.print("X: %f" % sample["x"], posy=20)
disp.print("Y: %f" % sample["y"], posy=40) disp.print("Y: %f" % sample["y"], posy=40)
disp.print("Z: %f" % sample["z"], posy=60) disp.print("Z: %f" % sample["z"], posy=60)
disp.update() disp.update()
utime.sleep(0.1)
...@@ -65,7 +65,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1( ...@@ -65,7 +65,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(
mp_bhi160_disable_sensor_obj, mp_bhi160_disable_sensor mp_bhi160_disable_sensor_obj, mp_bhi160_disable_sensor
); );
STATIC const mp_rom_map_elem_t bhi160_module_globals_table[] = { STATIC const mp_rom_map_elem_t bhi160_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_bhi160) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_bhi160) },
{ MP_ROM_QSTR(MP_QSTR_enable_sensor), { MP_ROM_QSTR(MP_QSTR_enable_sensor),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment