software:firmware
MakAir Firmware
activation.cpp
Go to the documentation of this file.
1 
8 // INCLUDES ===================================================================
9 
10 // Associated header
11 #include "../includes/activation.h"
12 
13 // Internal libraries
14 #include "../includes/buzzer.h"
15 
17 const uint32_t SECOND_STOP_MAX_DELAY_MS = 5000;
18 
19 // INITIALISATION =============================================================
20 
22 
23 // FUNCTIONS ==================================================================
24 
25 ActivationController::ActivationController() : m_state(STOPPED), m_timeOfLastStopPushed(0) {}
26 
28 
29 void ActivationController::changeState(uint16_t state) {
30  if (state == 0u) {
31  m_state = STOPPED;
32  } else {
33  m_state = RUNNING;
34  }
35 }
36 
40  m_state = STOPPED;
41  } else if ((m_state == RUNNING_READY_TO_STOP) || (m_state == RUNNING)) {
42  m_timeOfLastStopPushed = millis();
44  } else {
45  // Stay in STOPPED state
46  }
47 }
48 
50  // If the 2nd STOP deadline is exceeded, switch back
51  // to running state. This is needed to make sure millis() counter
52  // overflow does not make the test invalid
54  && ((millis() - m_timeOfLastStopPushed) >= SECOND_STOP_MAX_DELAY_MS)) {
55  m_state = RUNNING;
56  }
57 }
ActivationController activationController
Instance of the activation controller.
Definition: activation.cpp:21
const uint32_t SECOND_STOP_MAX_DELAY_MS
Maximum delay in seconds between two pushes on the stop button to actually stop the machine.
Definition: activation.cpp:17
Controls breathing activation ON/OFF state.
Definition: activation.h:18
void onStopButton()
Callback to call each time the stop button is pushed.
Definition: activation.cpp:37
void refreshState()
Refresh the current state.
Definition: activation.cpp:49
void changeState(uint16_t state)
Change the current state.
Definition: activation.cpp:29
void onStartButton()
Callback to call each time the start button is pushed.
Definition: activation.cpp:27
State m_state
Activation status.
Definition: activation.h:64
uint32_t m_timeOfLastStopPushed
Last time stop button was pushed.
Definition: activation.h:67
@ RUNNING_READY_TO_STOP
Breathing is ON, waiting for a second push to stop.
Definition: activation.h:60
@ RUNNING
Breathing is ON.
Definition: activation.h:57
@ STOPPED
Breathing is OFF.
Definition: activation.h:54