[ble] __ASSERT initialization & sensor reading
After we tracked down a rare, annoying bug for the zigbee sample in #150, this PR does something similar for the ble sample. If there's an error either initializing the board of reading the sensors, __ASSERT will reboot the system, instead of letting it hang forever.
This commit is contained in:
parent
8fb45f7165
commit
1a5acd02a5
2 changed files with 17 additions and 11 deletions
|
|
@ -19,6 +19,8 @@ CONFIG_USE_SEGGER_RTT=y
|
||||||
CONFIG_NEWLIB_LIBC=y
|
CONFIG_NEWLIB_LIBC=y
|
||||||
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
|
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
|
||||||
|
|
||||||
|
CONFIG_ASSERT=y
|
||||||
|
|
||||||
# Application config - see all options in Kconfig.
|
# Application config - see all options in Kconfig.
|
||||||
# CONFIG_PRST_BLE_ENCODING_BTHOME_V2=y
|
# CONFIG_PRST_BLE_ENCODING_BTHOME_V2=y
|
||||||
# CONFIG_PRST_SLEEP_DURATION_SEC=1
|
# CONFIG_PRST_SLEEP_DURATION_SEC=1
|
||||||
|
|
|
||||||
|
|
@ -14,25 +14,29 @@
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
||||||
|
|
||||||
int main(void) {
|
int prst_init() {
|
||||||
RET_IF_ERR(prst_adc_init());
|
RET_IF_ERR(prst_adc_init());
|
||||||
RET_IF_ERR(prst_led_init());
|
RET_IF_ERR(prst_led_init());
|
||||||
RET_IF_ERR(prst_button_init());
|
RET_IF_ERR(prst_button_init());
|
||||||
RET_IF_ERR(prst_ble_init());
|
RET_IF_ERR(prst_ble_init());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
RET_IF_ERR(prst_led_flash(2));
|
int prst_loop(prst_sensors_t *sensors) {
|
||||||
|
RET_IF_ERR(prst_sensors_read_all(sensors));
|
||||||
|
RET_IF_ERR(prst_ble_adv_set_data(sensors));
|
||||||
|
RET_IF_ERR(prst_ble_adv_start());
|
||||||
|
k_sleep(K_SECONDS(CONFIG_PRST_BLE_ADV_DURATION_SEC));
|
||||||
|
RET_IF_ERR(prst_ble_adv_stop());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
__ASSERT(!prst_init(), "Error in prst_init()");
|
||||||
|
prst_led_flash(2);
|
||||||
prst_sensors_t sensors;
|
prst_sensors_t sensors;
|
||||||
while (true) {
|
while (true) {
|
||||||
RET_IF_ERR(prst_sensors_read_all(&sensors));
|
__ASSERT(!prst_loop(&sensors), "Error in prst_loop()");
|
||||||
|
|
||||||
RET_IF_ERR(prst_ble_adv_set_data(&sensors));
|
|
||||||
RET_IF_ERR(prst_ble_adv_start());
|
|
||||||
|
|
||||||
k_sleep(K_SECONDS(CONFIG_PRST_BLE_ADV_DURATION_SEC));
|
|
||||||
|
|
||||||
RET_IF_ERR(prst_ble_adv_stop());
|
|
||||||
|
|
||||||
k_sleep(K_SECONDS(CONFIG_PRST_SLEEP_DURATION_SEC));
|
k_sleep(K_SECONDS(CONFIG_PRST_SLEEP_DURATION_SEC));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue