Skip to content

Commit 6e1260d

Browse files
authored
Revert "modules: sensor: add warmup delays to prevent CCS810 early read failures"
This reverts commit cc1ac5c.
1 parent cc1ac5c commit 6e1260d

3 files changed

Lines changed: 8 additions & 143 deletions

File tree

app/src/modules/controller/controller_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ZBUS_SUBSCRIBER_DEFINE(controller_sensor_subscriber,
1515
CONFIG_CONTROLLER_MODULE_ZBUS_SUBSCRIBER_QUEUE_SIZE);
1616

1717
/* Controller state machine object initialization macro */
18-
#define CONTROLLER_STATE_OBJECT_INIT() \
18+
#define CONTROLLER_MODULE_STATE_OBJECT_INIT() \
1919
(struct controller_state_object) \
2020
{ \
2121
.sample_interval_ms = CONFIG_CONTROLLER_MODULE_SAMPLE_INTERVAL_MS, \
@@ -91,7 +91,7 @@ int controller_module_init(void)
9191
LOG_INF("Initializing controller module");
9292

9393
/* Initialize state machine object */
94-
controller_state_obj = CONTROLLER_STATE_OBJECT_INIT();
94+
controller_state_obj = CONTROLLER_MODULE_STATE_OBJECT_INIT();
9595

9696
/* Initialize state machine */
9797
smf_set_initial(SMF_CTX(&controller_state_obj),

app/src/modules/sensor/Kconfig.sensor

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,6 @@ config SENSOR_MODULE_MAX_RETRIES
4646
help
4747
Maximum number of recovery attempts before giving up.
4848

49-
# Sensor-specific warmup configurations
50-
config SENSOR_MODULE_WARMUP_ENABLE
51-
bool "Enable sensor warmup periods"
52-
default y
53-
help
54-
Enable warmup delays for sensors that need stabilization time
55-
before providing accurate readings.
56-
57-
config SENSOR_MODULE_CCS811_WARMUP_MS
58-
int "CCS811 warmup period (ms)"
59-
default 5000
60-
depends on SENSOR_MODULE_WARMUP_ENABLE
61-
help
62-
Warmup time required for CCS811 sensor before first valid reading.
63-
CCS811 needs time to stabilize after power-on or reset.
64-
65-
config SENSOR_MODULE_BME280_WARMUP_MS
66-
int "BME280 warmup period (ms)"
67-
default 100
68-
depends on SENSOR_MODULE_WARMUP_ENABLE
69-
help
70-
Warmup time required for BME280 sensor before first valid reading.
71-
72-
config SENSOR_MODULE_HM3301_WARMUP_MS
73-
int "HM3301 warmup period (ms)"
74-
default 100
75-
depends on SENSOR_MODULE_WARMUP_ENABLE
76-
help
77-
Warmup time required for HM3301 sensor before first valid reading.
78-
7949
config CCS811_ENV_COMPENSATION
8050
bool "Enable environmental compensation for CCS811"
8151
default y

app/src/modules/sensor/sensor_module.c

Lines changed: 6 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,11 @@
1010

1111
LOG_MODULE_REGISTER(sensor_module, CONFIG_SENSOR_MODULE_LOG_LEVEL);
1212

13-
/* Macro to validate sensor type enum values */
14-
#define IS_VALID_SENSOR_TYPE(type) ((int)(type) >= 0 && (type) < SENSOR_TYPE_COUNT)
15-
1613
/* Macro for type-safe sensor state object initialization */
1714
#define SENSOR_STATE_OBJECT_INIT() \
18-
(struct sensor_state_object) \
1915
{ \
2016
.ctx = {0}, .current_state = SENSOR_MODULE_STATE_INIT, .current_data = {0}, \
21-
.error_count = 0, .max_retries = 0, .last_read_time = 0, .read_timeout_ms = 0, \
22-
IF_ENABLED(CONFIG_SENSOR_MODULE_WARMUP_ENABLE, \
23-
(.sensor_init_time = 0, \
24-
.sensor_warmup_complete = {false})) \
17+
.error_count = 0, .max_retries = 0, .last_read_time = 0, .read_timeout_ms = 0 \
2518
}
2619

2720
/* ZBUS subscriber for sensor requests */
@@ -63,12 +56,6 @@ struct sensor_state_object {
6356
/* Timing */
6457
int64_t last_read_time;
6558
int64_t read_timeout_ms;
66-
67-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
68-
/* Sensor warmup tracking */
69-
int64_t sensor_init_time;
70-
bool sensor_warmup_complete[SENSOR_TYPE_COUNT];
71-
#endif
7259
};
7360

7461
/* Forward declarations for state functions */
@@ -128,11 +115,6 @@ static void update_sensor_health(struct sensor_health *health, bool success);
128115
static const char *get_sensor_name(enum sensor_type type);
129116
static void sensor_set_state(struct sensor_state_object *ctx, enum sensor_module_state new_state);
130117

131-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
132-
static bool is_sensor_warmup_complete(enum sensor_type type);
133-
static int64_t get_sensor_warmup_time(enum sensor_type type);
134-
#endif
135-
136118
#ifdef CONFIG_CCS811_ENV_COMPENSATION
137119
static int update_ccs811_env_data(const struct sensor_value *temp, const struct sensor_value *hum);
138120
static void handle_ccs811_env_compensation(const struct sensor_value *temp,
@@ -145,7 +127,7 @@ int sensor_module_init(void)
145127
int ret;
146128

147129
/* Initialize state machine context */
148-
sensor_state_obj = SENSOR_STATE_OBJECT_INIT();
130+
sensor_state_obj = (struct sensor_state_object)SENSOR_STATE_OBJECT_INIT();
149131

150132
sensor_state_obj.max_retries = CONFIG_SENSOR_MODULE_MAX_RETRIES;
151133
sensor_state_obj.read_timeout_ms = CONFIG_SENSOR_MODULE_READ_TIMEOUT_MS;
@@ -264,14 +246,6 @@ static void sensor_state_init_run(void *obj)
264246
return;
265247
}
266248

267-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
268-
/* Initialize warmup timing */
269-
ctx->sensor_init_time = k_uptime_get();
270-
for (int i = 0; i < SENSOR_TYPE_COUNT; i++) {
271-
ctx->sensor_warmup_complete[i] = false;
272-
}
273-
#endif
274-
275249
/* Initialize context with configured values */
276250
ctx->error_count = 0;
277251
ctx->max_retries = sensor_state_obj.max_retries;
@@ -318,15 +292,6 @@ static void sensor_state_reading_run(void *obj)
318292
continue;
319293
}
320294

321-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
322-
/* Check if sensor warmup is complete */
323-
if (!is_sensor_warmup_complete(i)) {
324-
LOG_DBG("Sensor SM: %s warmup not complete, skipping read",
325-
get_sensor_name(i));
326-
continue;
327-
}
328-
#endif
329-
330295
int ret = read_sensor_data(i, &ctx->current_data);
331296
if (ret == 0) {
332297
successful_reads++;
@@ -354,43 +319,18 @@ static void sensor_state_reading_run(void *obj)
354319
}
355320
}
356321

357-
/* Count enabled sensors that have completed warmup */
322+
/* Count enabled sensors */
358323
int enabled_sensor_count = 0;
359324
for (int i = 0; i < SENSOR_TYPE_COUNT; i++) {
360325
if (sensors[i].enabled) {
361-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
362-
if (is_sensor_warmup_complete(i)) {
363-
enabled_sensor_count++;
364-
}
365-
#else
366326
enabled_sensor_count++;
367-
#endif
368327
}
369328
}
370329

371330
/* Only publish data if at least one sensor read successfully */
372331
if (successful_reads == 0) {
373-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
374-
/* Check if any sensors are still warming up */
375-
bool any_warming = false;
376-
for (int i = 0; i < SENSOR_TYPE_COUNT; i++) {
377-
if (sensors[i].enabled && !is_sensor_warmup_complete(i)) {
378-
any_warming = true;
379-
break;
380-
}
381-
}
382-
383-
if (any_warming) {
384-
LOG_DBG("Sensor SM: No readings yet - sensors still warming up");
385-
sensor_set_state(ctx, SENSOR_MODULE_STATE_IDLE);
386-
} else {
387-
LOG_ERR("Sensor SM: All sensors failed, entering error state");
388-
sensor_set_state(ctx, SENSOR_MODULE_STATE_ERROR);
389-
}
390-
#else
391332
LOG_ERR("Sensor SM: All sensors failed, entering error state");
392333
sensor_set_state(ctx, SENSOR_MODULE_STATE_ERROR);
393-
#endif
394334
} else if (successful_reads < enabled_sensor_count) {
395335
LOG_WRN("Sensor SM: Partial sensor failure (%d/%d successful), but publishing "
396336
"available data",
@@ -501,8 +441,8 @@ static int read_sensor_data(enum sensor_type type, struct sensor_msg *data)
501441
return -EINVAL;
502442
}
503443

504-
if (!IS_VALID_SENSOR_TYPE(type) || !sensors[type].enabled) {
505-
LOG_ERR("Invalid or disabled sensor type: %d", (int)type);
444+
if (type >= SENSOR_TYPE_COUNT || !sensors[type].enabled) {
445+
LOG_ERR("Invalid or disabled sensor type: %d", type);
506446
return -EINVAL;
507447
}
508448

@@ -670,7 +610,7 @@ static void handle_ccs811_fallback_compensation(void)
670610

671611
int sensor_module_get_sensor_info(enum sensor_type sensor_type, struct sensor_info *sensor_info)
672612
{
673-
if (!IS_VALID_SENSOR_TYPE(sensor_type) || !sensor_info) {
613+
if (sensor_type >= SENSOR_TYPE_COUNT || !sensor_info) {
674614
LOG_ERR("Invalid parameters for sensor info request");
675615
return -EINVAL;
676616
}
@@ -763,48 +703,3 @@ static void sensor_set_state(struct sensor_state_object *ctx, enum sensor_module
763703
ctx->current_state = new_state;
764704
smf_set_state(SMF_CTX(ctx), &sensor_states[new_state]);
765705
}
766-
767-
#ifdef CONFIG_SENSOR_MODULE_WARMUP_ENABLE
768-
/* Helper function to get warmup time for a sensor type */
769-
static int64_t get_sensor_warmup_time(enum sensor_type type)
770-
{
771-
switch (type) {
772-
case SENSOR_TYPE_BME280:
773-
return CONFIG_SENSOR_MODULE_BME280_WARMUP_MS;
774-
case SENSOR_TYPE_CCS811:
775-
return CONFIG_SENSOR_MODULE_CCS811_WARMUP_MS;
776-
case SENSOR_TYPE_HM3301:
777-
return CONFIG_SENSOR_MODULE_HM3301_WARMUP_MS;
778-
default:
779-
return 0;
780-
}
781-
}
782-
783-
/* Helper function to check if sensor warmup is complete */
784-
static bool is_sensor_warmup_complete(enum sensor_type type)
785-
{
786-
if (!IS_VALID_SENSOR_TYPE(type)) {
787-
LOG_ERR("Invalid sensor type: %d", (int)type);
788-
return false;
789-
}
790-
791-
/* Check if already marked as complete */
792-
if (sensor_state_obj.sensor_warmup_complete[type]) {
793-
return true;
794-
}
795-
796-
/* Check if warmup time has elapsed */
797-
int64_t elapsed_time = k_uptime_get() - sensor_state_obj.sensor_init_time;
798-
int64_t warmup_time = get_sensor_warmup_time(type);
799-
800-
if (elapsed_time >= warmup_time) {
801-
/* Mark as complete and log */
802-
sensor_state_obj.sensor_warmup_complete[type] = true;
803-
LOG_INF("Sensor SM: %s warmup complete after %lld ms", get_sensor_name(type),
804-
elapsed_time);
805-
return true;
806-
}
807-
808-
return false;
809-
}
810-
#endif /* CONFIG_SENSOR_MODULE_WARMUP_ENABLE */

0 commit comments

Comments
 (0)