software:firmware
MakAir Firmware
ActivationController Class Reference

Controls breathing activation ON/OFF state. More...

#include <activation.h>

Public Member Functions

 ActivationController ()
 
void refreshState ()
 Refresh the current state. More...
 
bool isRunning () const
 Return if breathing is activated or not. More...
 
void changeState (uint16_t state)
 Change the current state. More...
 
void onStartButton ()
 Callback to call each time the start button is pushed. More...
 
void onStopButton ()
 Callback to call each time the stop button is pushed. More...
 

Private Types

enum  State { STOPPED = 0 , RUNNING , RUNNING_READY_TO_STOP }
 

Private Attributes

State m_state
 Activation status. More...
 
uint32_t m_timeOfLastStopPushed
 Last time stop button was pushed. More...
 

Detailed Description

Controls breathing activation ON/OFF state.

Definition at line 18 of file activation.h.

Member Enumeration Documentation

◆ State

Enumerator
STOPPED 

Breathing is OFF.

RUNNING 

Breathing is ON.

RUNNING_READY_TO_STOP 

Breathing is ON, waiting for a second push to stop.

Definition at line 52 of file activation.h.

52  {
54  STOPPED = 0,
55 
57  RUNNING,
58 
61  };
@ 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

Constructor & Destructor Documentation

◆ ActivationController()

ActivationController::ActivationController ( )

Definition at line 25 of file activation.cpp.

State m_state
Activation status.
Definition: activation.h:64
uint32_t m_timeOfLastStopPushed
Last time stop button was pushed.
Definition: activation.h:67

Member Function Documentation

◆ changeState()

void ActivationController::changeState ( uint16_t  state)

Change the current state.

Parameters
stateNew state: 0 = STOPPED, 1 = RUNNING

Definition at line 29 of file activation.cpp.

29  {
30  if (state == 0u) {
31  m_state = STOPPED;
32  } else {
33  m_state = RUNNING;
34  }
35 }

◆ isRunning()

bool ActivationController::isRunning ( ) const
inline

Return if breathing is activated or not.

Definition at line 32 of file activation.h.

32 { return m_state != STOPPED; }

◆ onStartButton()

void ActivationController::onStartButton ( )

Callback to call each time the start button is pushed.

Definition at line 27 of file activation.cpp.

27 { m_state = RUNNING; }

◆ onStopButton()

void ActivationController::onStopButton ( )

Callback to call each time the stop button is pushed.

Definition at line 37 of file activation.cpp.

37  {
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 }
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

◆ refreshState()

void ActivationController::refreshState ( )

Refresh the current state.

Warning
It must be called regularly to protect against time counter overflow

Definition at line 49 of file activation.cpp.

49  {
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 }

Member Data Documentation

◆ m_state

State ActivationController::m_state
private

Activation status.

Definition at line 64 of file activation.h.

◆ m_timeOfLastStopPushed

uint32_t ActivationController::m_timeOfLastStopPushed
private

Last time stop button was pushed.

Definition at line 67 of file activation.h.


The documentation for this class was generated from the following files: