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
No related merge requests found
......@@ -113,6 +113,7 @@ typedef _Bool bool;
#define API_BHI160_ENABLE 0xe0
#define API_BHI160_DISABLE 0xe1
#define API_BHI160_DISABLE_ALL 0xe2
/* clang-format on */
......@@ -1029,6 +1030,11 @@ API(API_BHI160_DISABLE, int epic_bhi160_disable_sensor(
enum bhi160_sensor_type sensor_type
));
/**
* Disable all BHI160 sensors.
*/
API(API_BHI160_DISABLE_ALL, void epic_bhi160_disable_all_sensors());
/**
* Vibration Motor
* ===============
......
......@@ -62,6 +62,9 @@ static SemaphoreHandle_t bhi160_mutex = NULL;
/* Streams */
static struct stream_info bhi160_streams[10];
/* Active */
static bool bhi160_sensor_active[10] = { 0 };
/* -- Utilities -------------------------------------------------------- {{{ */
/*
* Retrieve the data size for a sensor. This value is needed for the creation
......@@ -165,6 +168,9 @@ int epic_bhi160_enable_sensor(
hwlock_release(HWLOCK_I2C);
return bhyret;
}
bhi160_sensor_active[sensor_type] = true;
xSemaphoreGive(bhi160_mutex);
} else {
hwlock_release(HWLOCK_I2C);
......@@ -189,7 +195,9 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
if (xSemaphoreTake(bhi160_mutex, LOCK_WAIT) == pdTRUE) {
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) {
xSemaphoreGive(bhi160_mutex);
hwlock_release(HWLOCK_I2C);
......@@ -197,12 +205,15 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
}
vQueueDelete(stream->queue);
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) {
xSemaphoreGive(bhi160_mutex);
hwlock_release(HWLOCK_I2C);
return bhyret;
}
bhi160_sensor_active[sensor_type] = false;
xSemaphoreGive(bhi160_mutex);
} else {
hwlock_release(HWLOCK_I2C);
......@@ -212,6 +223,16 @@ int epic_bhi160_disable_sensor(enum bhi160_sensor_type sensor_type)
hwlock_release(HWLOCK_I2C);
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 ----------------------------------------------------------- {{{ */
......
......@@ -259,6 +259,11 @@ int hardware_reset(void)
*/
display_init_slim();
/*
* BHI160
*/
epic_bhi160_disable_all_sensors();
/*
* BME680 Sensor
*/
......
......@@ -4,18 +4,19 @@ import utime
disp = display.open()
bhi = bhi160.BHI160Accelerometer()
while True:
with bhi160.BHI160Accelerometer(sample_rate=20) as bhi:
utime.sleep(0.25)
samples = bhi.read()
if len(samples) > 0:
disp.clear()
sample = samples[0]
samples = bhi.read()
if len(samples) > 0:
disp.clear()
sample = samples[0]
disp.print("Accelerometer", posy=0)
disp.print("X: %f" % sample["x"], posy=20)
disp.print("Y: %f" % sample["y"], posy=40)
disp.print("Z: %f" % sample["z"], posy=60)
disp.print("Accelerometer", posy=0)
disp.print("X: %f" % sample["x"], posy=20)
disp.print("Y: %f" % sample["y"], posy=40)
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(
mp_bhi160_disable_sensor_obj, mp_bhi160_disable_sensor
);
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_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