From ac224ea7b8589003d02354ee8d6462253de7e1dc Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 4 Jun 2021 01:06:26 +0000 Subject: [PATCH] fix: update from upstream See https://github.com/nrfconnect/sdk-nrf/tree/8fe904a68d9273d5d89ad651378493795a0b13f4/applications/asset_tracker_v2 --- src/ext_sensors/ext_sensors.c | 68 ++++++++++++++++++++++++----------- src/ext_sensors/ext_sensors.h | 5 +++ src/modules/sensor_module.c | 26 ++++++-------- 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/src/ext_sensors/ext_sensors.c b/src/ext_sensors/ext_sensors.c index 9d85bcaf..18923b78 100644 --- a/src/ext_sensors/ext_sensors.c +++ b/src/ext_sensors/ext_sensors.c @@ -60,7 +60,7 @@ static void accelerometer_trigger_handler(const struct device *dev, { int err = 0; struct sensor_value data[ACCELEROMETER_CHANNELS]; - struct ext_sensor_evt evt; + struct ext_sensor_evt evt = {0}; switch (trig->type) { case SENSOR_TRIG_THRESHOLD: @@ -110,42 +110,48 @@ static void accelerometer_trigger_handler(const struct device *dev, int ext_sensors_init(ext_sensor_handler_t handler) { + struct ext_sensor_evt evt = {0}; + if (handler == NULL) { - LOG_INF("External sensor handler NULL!"); + LOG_ERR("External sensor handler NULL!"); return -EINVAL; } + evt_handler = handler; + if (!device_is_ready(temp_sensor.dev)) { LOG_ERR("Temperature sensor device is not ready"); - return -ENODEV; + evt.type = EXT_SENSOR_EVT_TEMPERATURE_ERROR; + evt_handler(&evt); } if (!device_is_ready(humid_sensor.dev)) { LOG_ERR("Humidity sensor device is not ready"); - return -ENODEV; + evt.type = EXT_SENSOR_EVT_HUMIDITY_ERROR; + evt_handler(&evt); } if (!device_is_ready(accel_sensor.dev)) { LOG_ERR("Accelerometer device is not ready"); - return -ENODEV; - } - + evt.type = EXT_SENSOR_EVT_ACCELEROMETER_ERROR; + evt_handler(&evt); + } else { #if defined(CONFIG_EXTERNAL_SENSORS_ACTIVITY_DETECTION_AUTO) - struct sensor_trigger trig = { - .chan = SENSOR_CHAN_ACCEL_XYZ, - .type = SENSOR_TRIG_THRESHOLD - }; + struct sensor_trigger trig = { + .chan = SENSOR_CHAN_ACCEL_XYZ, + .type = SENSOR_TRIG_THRESHOLD + }; - int err = sensor_trigger_set(accel_sensor.dev, &trig, accelerometer_trigger_handler); + int err = sensor_trigger_set(accel_sensor.dev, + &trig, accelerometer_trigger_handler); - if (err) { - LOG_ERR("Could not set trigger for device %s, error: %d", - accel_sensor.dev->name, err); - return err; - } + if (err) { + LOG_ERR("Could not set trigger for device %s, error: %d", + accel_sensor.dev->name, err); + return err; + } #endif - - evt_handler = handler; + } return 0; } @@ -153,12 +159,15 @@ int ext_sensors_init(ext_sensor_handler_t handler) int ext_sensors_temperature_get(double *ext_temp) { int err; - struct sensor_value data; + struct sensor_value data = {0}; + struct ext_sensor_evt evt = {0}; err = sensor_sample_fetch_chan(temp_sensor.dev, SENSOR_CHAN_ALL); if (err) { LOG_ERR("Failed to fetch data from %s, error: %d", temp_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_TEMPERATURE_ERROR; + evt_handler(&evt); return -ENODATA; } @@ -166,6 +175,8 @@ int ext_sensors_temperature_get(double *ext_temp) if (err) { LOG_ERR("Failed to fetch data from %s, error: %d", temp_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_TEMPERATURE_ERROR; + evt_handler(&evt); return -ENODATA; } @@ -179,12 +190,15 @@ int ext_sensors_temperature_get(double *ext_temp) int ext_sensors_humidity_get(double *ext_hum) { int err; - struct sensor_value data; + struct sensor_value data = {0}; + struct ext_sensor_evt evt = {0}; err = sensor_sample_fetch_chan(humid_sensor.dev, SENSOR_CHAN_ALL); if (err) { LOG_ERR("Failed to fetch data from %s, error: %d", humid_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_HUMIDITY_ERROR; + evt_handler(&evt); return -ENODATA; } @@ -192,6 +206,8 @@ int ext_sensors_humidity_get(double *ext_hum) if (err) { LOG_ERR("Failed to fetch data from %s, error: %d", humid_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_HUMIDITY_ERROR; + evt_handler(&evt); return -ENODATA; } @@ -207,6 +223,7 @@ int ext_sensors_mov_thres_set(double threshold_new) int err, input_value; double range_max_m_s2 = ADXL362_RANGE_MAX_M_S2; double threshold_new_copy; + struct ext_sensor_evt evt = {0}; if (threshold_new > range_max_m_s2) { LOG_ERR("Invalid threshold value"); @@ -241,6 +258,8 @@ int ext_sensors_mov_thres_set(double threshold_new) LOG_ERR("Failed to set accelerometer x-axis threshold value"); LOG_ERR("Device: %s, error: %d", accel_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_ACCELEROMETER_ERROR; + evt_handler(&evt); return err; } @@ -250,6 +269,8 @@ int ext_sensors_mov_thres_set(double threshold_new) LOG_ERR("Failed to set accelerometer y-axis threshold value"); LOG_ERR("Device: %s, error: %d", accel_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_ACCELEROMETER_ERROR; + evt_handler(&evt); return err; } @@ -259,6 +280,8 @@ int ext_sensors_mov_thres_set(double threshold_new) LOG_ERR("Failed to set accelerometer z-axis threshold value"); LOG_ERR("Device: %s, error: %d", accel_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_ACCELEROMETER_ERROR; + evt_handler(&evt); return err; } @@ -274,6 +297,7 @@ int ext_sensors_accelerometer_trigger_callback_set(bool enable) .chan = SENSOR_CHAN_ACCEL_XYZ, .type = SENSOR_TRIG_THRESHOLD }; + struct ext_sensor_evt evt = {0}; sensor_trigger_handler_t handler = enable ? accelerometer_trigger_handler : NULL; @@ -281,6 +305,8 @@ int ext_sensors_accelerometer_trigger_callback_set(bool enable) if (err) { LOG_ERR("Could not set trigger for device %s, error: %d", accel_sensor.dev->name, err); + evt.type = EXT_SENSOR_EVT_ACCELEROMETER_ERROR; + evt_handler(&evt); return err; } diff --git a/src/ext_sensors/ext_sensors.h b/src/ext_sensors/ext_sensors.h index 1957f302..9cb13ec0 100644 --- a/src/ext_sensors/ext_sensors.h +++ b/src/ext_sensors/ext_sensors.h @@ -28,6 +28,11 @@ extern "C" { /** @brief Enum containing callback events from library. */ enum ext_sensor_evt_type { EXT_SENSOR_EVT_ACCELEROMETER_TRIGGER, + + /** Events propagated when an error associated with a sensor device occurs. */ + EXT_SENSOR_EVT_ACCELEROMETER_ERROR, + EXT_SENSOR_EVT_TEMPERATURE_ERROR, + EXT_SENSOR_EVT_HUMIDITY_ERROR }; /** @brief Structure containing external sensor data. */ diff --git a/src/modules/sensor_module.c b/src/modules/sensor_module.c index bc95479a..ea08f891 100644 --- a/src/modules/sensor_module.c +++ b/src/modules/sensor_module.c @@ -130,7 +130,6 @@ static void accelerometer_callback_set(bool enable) err = ext_sensors_accelerometer_trigger_callback_set(enable); if (err) { LOG_ERR("ext_sensors_accelerometer_trigger_callback_set, error: %d", err); - SEND_ERROR(sensor, SENSOR_EVT_ERROR, err); } } @@ -155,13 +154,22 @@ static void ext_sensor_handler(const struct ext_sensor_evt *const evt) case EXT_SENSOR_EVT_ACCELEROMETER_TRIGGER: movement_data_send(evt); break; + case EXT_SENSOR_EVT_ACCELEROMETER_ERROR: + LOG_ERR("EXT_SENSOR_EVT_ACCELEROMETER_ERROR"); + break; + case EXT_SENSOR_EVT_TEMPERATURE_ERROR: + LOG_ERR("EXT_SENSOR_EVT_TEMPERATURE_ERROR"); + break; + case EXT_SENSOR_EVT_HUMIDITY_ERROR: + LOG_ERR("EXT_SENSOR_EVT_HUMIDITY_ERROR"); + break; default: break; } } #endif -static int environmental_data_get(void) +static void environmental_data_get(void) { struct sensor_module_event *sensor_module_event; #if defined(CONFIG_EXTERNAL_SENSORS) @@ -172,13 +180,11 @@ static int environmental_data_get(void) err = ext_sensors_temperature_get(&temp); if (err) { LOG_ERR("temperature_get, error: %d", err); - return err; } err = ext_sensors_humidity_get(&hum); if (err) { LOG_ERR("temperature_get, error: %d", err); - return err; } sensor_module_event = new_sensor_module_event(); @@ -202,8 +208,6 @@ static int environmental_data_get(void) sensor_module_event->type = SENSOR_EVT_ENVIRONMENTAL_NOT_SUPPORTED; #endif EVENT_SUBMIT(sensor_module_event); - - return 0; } static int setup(void) @@ -246,7 +250,6 @@ static void on_state_init(struct sensor_msg_data *msg) LOG_WRN("Passed in threshold value not valid"); } else if (err) { LOG_ERR("Failed to set threshold, error: %d", err); - SEND_ERROR(sensor, SENSOR_EVT_ERROR, err); } #endif state_set(STATE_RUNNING); @@ -268,7 +271,6 @@ static void on_state_running(struct sensor_msg_data *msg) LOG_WRN("Passed in threshold value not valid"); } else if (err) { LOG_ERR("Failed to set threshold, error: %d", err); - SEND_ERROR(sensor, SENSOR_EVT_ERROR, err); } #endif } @@ -280,13 +282,7 @@ static void on_state_running(struct sensor_msg_data *msg) return; } - int err; - - err = environmental_data_get(); - if (err) { - LOG_ERR("environmental_data_get, error: %d", err); - SEND_ERROR(sensor, SENSOR_EVT_ERROR, err); - } + environmental_data_get(); } }