Преглед на файлове

input initialization/callback correction

Thomas Hondema преди 3 дни
родител
ревизия
0c3edd9eea
променени са 1 файла, в които са добавени 9 реда и са изтрити 7 реда
  1. 9 7
      lib/meCoffee_controller_logic/src/shot_control.cpp

+ 9 - 7
lib/meCoffee_controller_logic/src/shot_control.cpp

@@ -41,6 +41,8 @@ void beginShotEvent(FirmwareState* state, uint32_t timestamp) {
 }
 
 void endShotEvent(FirmwareState* state, uint32_t endTimestamp, uint32_t beginTimestamp) {
+    // V10 counts release and timeout as activity, including a burst with no begin.
+    state->powerSchedule.lastActivityTimestamp = endTimestamp;
     setGroupEnabled(&groupForRole(&state->outputChannels, OutputGroupRole::Pump), false);
     setGroupEnabled(&groupForRole(&state->outputChannels, OutputGroupRole::Valve), false);
     state->shot.lastShotDuration = endTimestamp - beginTimestamp;
@@ -94,7 +96,7 @@ bool isInputQualified(const DebouncedInput& input) {
 
 void initializeDebouncedInput(DebouncedInput* input) {
     *input = DebouncedInput{};
-    input->isLastLevelHigh = true;
+    input->isLastLevelHigh = false;
 }
 
 ShotOutputRequest evaluateShotOutputRequest(const SettingsValues& settings, uint8_t alternateMode, uint32_t elapsedMilliseconds) {
@@ -114,6 +116,12 @@ void pollDebouncedInput(FirmwareState* state, DebouncedInput* input, InputRole r
     if (isPinHigh != input->isLastLevelHigh) {
         input->isLastLevelHigh = isPinHigh;
         input->lastChangeTimestamp = foregroundSnapshotMilliseconds;
+        // V10 begins on the edge after qualification, before recording its time.
+        // The qualifying edge itself can run the active callback with a zero origin.
+        if (isInputQualified(*input) && input->beginTimestamp == 0) {
+            runInputStateChange(state, role, 1, foregroundSnapshotMilliseconds, 0);
+            input->beginTimestamp = foregroundSnapshotMilliseconds;
+        }
         uint8_t& edgeCount = isPinHigh ? input->risingEdgeCount : input->fallingEdgeCount;
         if (edgeCount < 255) {
             ++edgeCount;
@@ -121,12 +129,6 @@ void pollDebouncedInput(FirmwareState* state, DebouncedInput* input, InputRole r
         if (!isInputQualified(*input)) {
             return;
         }
-        // The begin guard and the active callback run in the same call, so the first qualified
-        // falling edge both begins the burst and requests the outputs.
-        if (!isPinHigh && input->beginTimestamp == 0) {
-            input->beginTimestamp = foregroundSnapshotMilliseconds;
-            runInputStateChange(state, role, 1, foregroundSnapshotMilliseconds, 0);
-        }
         if (role == InputRole::Shot) {
             runShotActiveCallback(state, foregroundSnapshotMilliseconds, input->beginTimestamp);
         }