Skip to content

Commit 04ff1f9

Browse files
committed
Fixed new bug with power sensor
1 parent 23b4976 commit 04ff1f9

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

include/LoadConfig.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ namespace RUN {
9494
// Task Execution Intervals
9595
enum TASK_INTERVALS : uint32_t {
9696
TI_FSM_mS = 50, // CONFIG - 100 ms (10 Hz)
97-
TI_POLL_SENSORS_mS = 2, // CONFIG - 2 ms (500 Hz)
97+
TI_POLL_SENSORS_mS = 3, // CONFIG - 3 ms (333 Hz), stopped likeing 2 ms
98+
// (100 Hz) around commit 9d80f8b
9899
TI_ADJUST_LOAD_mS = 500, // CONFIG - 500 ms (2 Hz)
99-
TI_RECV_ms = 50, // CONFIG - 100 ms (10 Hz)
100-
TI_SEND_ms = 75, // CONFIG - 10 ms (100 Hz) // FIXME
100+
TI_RECV_ms = 50, // CONFIG - 100 ms (10 Hz)
101+
TI_SEND_ms = 75, // CONFIG - 75 ms (13.33 Hz) // FIXME
101102
TI_CFG_ms = 1000, // CONFIG - 1000 ms (1 Hz)
102103
TI_TELNET_ms = 500, // CONFIG - 500 ms (2 Hz)
103104
TI_OTA_ms = 1000, // CONFIG - 1000 ms (1 Hz)

src/main.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ void setup() {
257257
if (!Wire.begin(UM_PROS3::I2C_SDA_PIN, UM_PROS3::I2C_SCL_PIN)) {
258258
ESP_LOGE(TAG, "Failed to initialize I2C on pins %d (SDA) and %d (SCL)",
259259
UM_PROS3::I2C_SDA_PIN, UM_PROS3::I2C_SCL_PIN);
260+
} else {
261+
// Constant error spam when set to 1
262+
Wire.setTimeOut(2);
260263
}
261264

262265
loadConfigured = configureLoad();
@@ -395,22 +398,26 @@ vTaskPollSensors([[maybe_unused]] void *pvParameters) { // NOSONAR
395398
// load.updateSafetyFlag(); // Moved to interrupts before noticing that
396399
// the backoff was the problem, might as well leave it that way
397400

398-
static uint32_t backoffFactor =
399-
RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
400-
uint32_t delay_ms = 0;
401-
if (INA260::updateReadings()) {
402-
backoffFactor = RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
403-
delay_ms = RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS;
404-
} else {
405-
// Logging already handled
406-
delay_ms = RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS * backoffFactor;
407-
backoffFactor *= RUN::TASK_INTERVALS::FAIL_BACKOFF_MULTIPLIER;
408-
}
401+
// static uint32_t backoffFactor =
402+
// RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
403+
// uint32_t delay_ms = 0;
404+
// if (INA260::updateReadings()) {
405+
// backoffFactor = RUN::TASK_INTERVALS::FAIL_BACKOFF_BASE_FACTOR;
406+
// delay_ms = RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS;
407+
// } else {
408+
// // Logging already handled
409+
// delay_ms = RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS *
410+
// backoffFactor; backoffFactor *=
411+
// RUN::TASK_INTERVALS::FAIL_BACKOFF_MULTIPLIER;
412+
// }
413+
INA260::updateReadings();
409414

410-
BaseType_t xWasDelayed =
411-
xTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(delay_ms));
412-
if (xWasDelayed != pdTRUE) {
413-
ESP_LOGE(TAG, "Timing not met!");
415+
BaseType_t xWasDelayed = xTaskDelayUntil(
416+
&xLastWakeTime,
417+
pdMS_TO_TICKS(RUN::TASK_INTERVALS::TI_POLL_SENSORS_mS));
418+
// xTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(delay_ms));
419+
if (xWasDelayed == pdFALSE) {
420+
ESP_LOGE(TAG, "Timing"); // FIXME!
414421
}
415422
}
416423
}

0 commit comments

Comments
 (0)