software:firmware
MakAir Firmware
keyboard.cpp File Reference

Buttons related functions. More...

Go to the source code of this file.

Macros

#define SM_DEBOUNCE   2u
 
#define SM_REPEAT   20u
 
#define SM_PERIOD   15u
 

Functions

static OneButton buttonAlarmOff (PIN_BTN_ALARM_OFF, false, false)
 
static OneButton buttonStart (PIN_BTN_START, false, false)
 
static OneButton buttonStop (PIN_BTN_STOP, false, false)
 
void onPeakPressureIncrease ()
 Handler of the button to increase the crete pressure. More...
 
void onPeakPressureDecrease ()
 Handler of the button to decrease the crete pressure. More...
 
void onPlateauPressureIncrease ()
 Handler of the button to increase the plateau pressure. More...
 
void onPlateauPressureDecrease ()
 Handler of the button to decrease the plateau pressure. More...
 
void onPeepPressureIncrease ()
 Handler of the button to increase the PEP pressure. More...
 
void onPeepPressureDecrease ()
 Handler of the button to decrease the PEP pressure. More...
 
void onCycleIncrease ()
 Handler of the button to increase the number of breathing cycles. More...
 
void onCycleDecrease ()
 Handler of the button to decrease the number of breathing cycles. More...
 
void onAlarmOff ()
 Handler of the button to stop alarm. More...
 
void onStart ()
 Handler of the button to start. More...
 
void onStop ()
 Handler of the button to stop. More...
 
void initKeyboard ()
 Initialize keyboard abstraction. More...
 
void scanMatrixLoop ()
 
void keyboardLoop ()
 Handle button events. More...
 
void calibrateButtons ()
 Helper to calibrate analog values of buttons. More...
 

Variables

uint16_t scanMatrixCurrentColumn = 1
 
uint16_t scanMatrixCounterC1R1 = 0
 
uint16_t scanMatrixCounterC1R2 = 0
 
uint16_t scanMatrixCounterC1R3 = 0
 
uint16_t scanMatrixCounterC2R1 = 0
 
uint16_t scanMatrixCounterC2R2 = 0
 
uint16_t scanMatrixCounterC2R3 = 0
 
uint16_t scanMatrixCounterC3R1 = 0
 
uint16_t scanMatrixCounterC3R2 = 0
 
uint16_t scanMatrixCounterC3R3 = 0
 

Detailed Description

Buttons related functions.

Author
Makers For Life

This relies on the OneButton library (https://github.com/mathertel/OneButton).

Definition in file keyboard.cpp.

Macro Definition Documentation

◆ SM_DEBOUNCE

#define SM_DEBOUNCE   2u

Definition at line 106 of file keyboard.cpp.

◆ SM_PERIOD

#define SM_PERIOD   15u

Definition at line 108 of file keyboard.cpp.

◆ SM_REPEAT

#define SM_REPEAT   20u

Definition at line 107 of file keyboard.cpp.

Function Documentation

◆ buttonAlarmOff()

static OneButton buttonAlarmOff ( PIN_BTN_ALARM_OFF  ,
false  ,
false   
)
static

◆ buttonStart()

static OneButton buttonStart ( PIN_BTN_START  ,
false  ,
false   
)
static

◆ buttonStop()

static OneButton buttonStop ( PIN_BTN_STOP  ,
false  ,
false   
)
static

◆ calibrateButtons()

void calibrateButtons ( )

Helper to calibrate analog values of buttons.

Definition at line 233 of file keyboard.cpp.

233 {}

◆ initKeyboard()

void initKeyboard ( )

Initialize keyboard abstraction.

Warning
It must be called once to be able to use the buttons

Definition at line 78 of file keyboard.cpp.

78  {
79  // define the 3x3 matrix keyboard input and output
80  pinMode(PIN_OUT_COL1, OUTPUT);
81  pinMode(PIN_OUT_COL2, OUTPUT);
82  pinMode(PIN_OUT_COL3, OUTPUT);
83  digitalWrite(PIN_OUT_COL1, LOW);
84  digitalWrite(PIN_OUT_COL2, LOW);
85  digitalWrite(PIN_OUT_COL3, LOW);
86  pinMode(PIN_IN_ROW1, INPUT);
87  pinMode(PIN_IN_ROW2, INPUT);
88  pinMode(PIN_IN_ROW3, INPUT);
89 
90  buttonAlarmOff.attachClick(onAlarmOff);
91  buttonStart.attachClick(onStart);
92  buttonStop.attachClick(onStop);
93 }
void onStart()
Handler of the button to start.
Definition: keyboard.cpp:65
static OneButton buttonAlarmOff(PIN_BTN_ALARM_OFF, false, false)
void onAlarmOff()
Handler of the button to stop alarm.
Definition: keyboard.cpp:62
void onStop()
Handler of the button to stop.
Definition: keyboard.cpp:76
static OneButton buttonStart(PIN_BTN_START, false, false)
static OneButton buttonStop(PIN_BTN_STOP, false, false)
#define PIN_OUT_COL2
Definition: parameters.h:236
#define PIN_IN_ROW3
Definition: parameters.h:240
#define PIN_IN_ROW1
Definition: parameters.h:238
#define PIN_OUT_COL1
Definition: parameters.h:235
#define PIN_IN_ROW2
Definition: parameters.h:239
#define PIN_OUT_COL3
Definition: parameters.h:237

◆ keyboardLoop()

void keyboardLoop ( )

Handle button events.

Warning
It must be called in the program loop

Definition at line 223 of file keyboard.cpp.

223  {
224 #ifndef DISABLE_BUTTONS
225  scanMatrixLoop();
226  buttonAlarmOff.tick();
227  buttonStart.tick();
228  buttonStop.tick();
229 #endif
230 }
void scanMatrixLoop()
Definition: keyboard.cpp:112

◆ onAlarmOff()

void onAlarmOff ( )

Handler of the button to stop alarm.

Definition at line 62 of file keyboard.cpp.

AlarmController alarmController
Instance of the alarm controller.
void snooze()
Snooze alarm for 2 minutes.

◆ onCycleDecrease()

void onCycleDecrease ( )

Handler of the button to decrease the number of breathing cycles.

Definition at line 59 of file keyboard.cpp.

void onCycleDecrease()
Decrease the desired number of cycles per minute.
MainController mainController

◆ onCycleIncrease()

void onCycleIncrease ( )

Handler of the button to increase the number of breathing cycles.

Definition at line 56 of file keyboard.cpp.

void onCycleIncrease()
Increase the desired number of cycles per minute.

◆ onPeakPressureDecrease()

void onPeakPressureDecrease ( )

Handler of the button to decrease the crete pressure.

Definition at line 41 of file keyboard.cpp.

void onPeakPressureDecrease()
Decrease the desired peak pressure.

◆ onPeakPressureIncrease()

void onPeakPressureIncrease ( )

Handler of the button to increase the crete pressure.

Definition at line 38 of file keyboard.cpp.

void onPeakPressureIncrease()
Increase the desired peak pressure.

◆ onPeepPressureDecrease()

void onPeepPressureDecrease ( )

Handler of the button to decrease the PEP pressure.

Definition at line 53 of file keyboard.cpp.

void onPeepPressureDecrease()
Decrease the minimal PEEP desired.

◆ onPeepPressureIncrease()

void onPeepPressureIncrease ( )

Handler of the button to increase the PEP pressure.

Definition at line 50 of file keyboard.cpp.

void onPeepPressureIncrease()
Increase the minimal PEEP desired.

◆ onPlateauPressureDecrease()

void onPlateauPressureDecrease ( )

Handler of the button to decrease the plateau pressure.

Definition at line 47 of file keyboard.cpp.

void onPlateauPressureDecrease()
Decrease the desired plateau pressure.

◆ onPlateauPressureIncrease()

void onPlateauPressureIncrease ( )

Handler of the button to increase the plateau pressure.

Definition at line 44 of file keyboard.cpp.

void onPlateauPressureIncrease()
Increase the desired plateau pressure.

◆ onStart()

void onStart ( )

Handler of the button to start.

Definition at line 65 of file keyboard.cpp.

65  {
66  if (Calibration_Started()) {
67  // Restart calibration
69  } else {
70  // Or start the machine
72  }
73 }
ActivationController activationController
Instance of the activation controller.
Definition: activation.cpp:21
bool Calibration_Started()
Check if calibration mode is started.
void Calibration_Restart()
Restart calibration process.
void onStartButton()
Callback to call each time the start button is pushed.
Definition: activation.cpp:27

◆ onStop()

void onStop ( )

Handler of the button to stop.

Definition at line 76 of file keyboard.cpp.

void onStopButton()
Callback to call each time the stop button is pushed.
Definition: activation.cpp:37

◆ scanMatrixLoop()

void scanMatrixLoop ( )

Definition at line 112 of file keyboard.cpp.

112  {
113  if (1u == scanMatrixCurrentColumn) {
114  // Increase counter for each column and row
115  if (HIGH == digitalRead(PIN_IN_ROW1)) {
117  } else {
119  }
120  if (HIGH == digitalRead(PIN_IN_ROW2)) {
122  } else {
124  }
125  if (HIGH == digitalRead(PIN_IN_ROW3)) {
127  } else {
129  }
130  // first click (after debounce ticks) or
131  // later clicks if continuous press trigger action
134  && (0u == (scanMatrixCounterC1R1 - SM_REPEAT) % SM_PERIOD))) {
136  }
139  && (0u == (scanMatrixCounterC1R2 - SM_REPEAT) % SM_PERIOD))) {
141  }
144  && (0u == (scanMatrixCounterC1R3 - SM_REPEAT) % SM_PERIOD))) {
146  }
147  } else if (2u == scanMatrixCurrentColumn) {
148  if (HIGH == digitalRead(PIN_IN_ROW1)) {
150  } else {
152  }
153  if (HIGH == digitalRead(PIN_IN_ROW2)) {
155  } else {
157  }
158  if (HIGH == digitalRead(PIN_IN_ROW3)) {
160  } else {
162  }
163  // first click (after debounce ticks) or
164  // later clicks if continuous press trigger action
167  && (0u == (scanMatrixCounterC2R1 - SM_REPEAT) % SM_PERIOD))) {
169  }
172  && (0u == (scanMatrixCounterC2R2 - SM_REPEAT) % SM_PERIOD))) {
174  }
177  && (0u == (scanMatrixCounterC2R3 - SM_REPEAT) % SM_PERIOD))) {
179  }
180  } else if (3u == scanMatrixCurrentColumn) {
181  if (HIGH == digitalRead(PIN_IN_ROW1)) {
183  } else {
185  }
186  if (HIGH == digitalRead(PIN_IN_ROW2)) {
188  } else {
190  }
191  if (HIGH == digitalRead(PIN_IN_ROW3)) {
193  } else {
195  }
196  // first click (after debounce ticks) or
197  // later clicks if continuous press trigger action
200  && (0u == (scanMatrixCounterC3R1 - SM_REPEAT) % SM_PERIOD))) {
201  onCycleIncrease();
202  }
205  && (0u == (scanMatrixCounterC3R2 - SM_REPEAT) % SM_PERIOD))) {
206  onCycleDecrease();
207  }
208  // there is no button on col3 x row3
209  } else {
210  // Do nothing
211  }
212 
213  // next column
215  if (4u == scanMatrixCurrentColumn) {
217  }
218  digitalWrite(PIN_OUT_COL1, (1u == scanMatrixCurrentColumn) ? HIGH : LOW);
219  digitalWrite(PIN_OUT_COL2, (2u == scanMatrixCurrentColumn) ? HIGH : LOW);
220  digitalWrite(PIN_OUT_COL3, (3u == scanMatrixCurrentColumn) ? HIGH : LOW);
221 }
uint16_t scanMatrixCounterC2R2
Definition: keyboard.cpp:101
uint16_t scanMatrixCurrentColumn
Definition: keyboard.cpp:96
void onCycleIncrease()
Handler of the button to increase the number of breathing cycles.
Definition: keyboard.cpp:56
uint16_t scanMatrixCounterC1R3
Definition: keyboard.cpp:99
void onPlateauPressureDecrease()
Handler of the button to decrease the plateau pressure.
Definition: keyboard.cpp:47
#define SM_PERIOD
Definition: keyboard.cpp:108
#define SM_REPEAT
Definition: keyboard.cpp:107
void onPeepPressureIncrease()
Handler of the button to increase the PEP pressure.
Definition: keyboard.cpp:50
uint16_t scanMatrixCounterC3R2
Definition: keyboard.cpp:104
uint16_t scanMatrixCounterC3R3
Definition: keyboard.cpp:105
uint16_t scanMatrixCounterC2R3
Definition: keyboard.cpp:102
uint16_t scanMatrixCounterC1R2
Definition: keyboard.cpp:98
void onCycleDecrease()
Handler of the button to decrease the number of breathing cycles.
Definition: keyboard.cpp:59
uint16_t scanMatrixCounterC2R1
Definition: keyboard.cpp:100
void onPeepPressureDecrease()
Handler of the button to decrease the PEP pressure.
Definition: keyboard.cpp:53
void onPlateauPressureIncrease()
Handler of the button to increase the plateau pressure.
Definition: keyboard.cpp:44
void onPeakPressureIncrease()
Handler of the button to increase the crete pressure.
Definition: keyboard.cpp:38
void onPeakPressureDecrease()
Handler of the button to decrease the crete pressure.
Definition: keyboard.cpp:41
uint16_t scanMatrixCounterC3R1
Definition: keyboard.cpp:103
#define SM_DEBOUNCE
Definition: keyboard.cpp:106
uint16_t scanMatrixCounterC1R1
Definition: keyboard.cpp:97

Variable Documentation

◆ scanMatrixCounterC1R1

uint16_t scanMatrixCounterC1R1 = 0

Definition at line 97 of file keyboard.cpp.

◆ scanMatrixCounterC1R2

uint16_t scanMatrixCounterC1R2 = 0

Definition at line 98 of file keyboard.cpp.

◆ scanMatrixCounterC1R3

uint16_t scanMatrixCounterC1R3 = 0

Definition at line 99 of file keyboard.cpp.

◆ scanMatrixCounterC2R1

uint16_t scanMatrixCounterC2R1 = 0

Definition at line 100 of file keyboard.cpp.

◆ scanMatrixCounterC2R2

uint16_t scanMatrixCounterC2R2 = 0

Definition at line 101 of file keyboard.cpp.

◆ scanMatrixCounterC2R3

uint16_t scanMatrixCounterC2R3 = 0

Definition at line 102 of file keyboard.cpp.

◆ scanMatrixCounterC3R1

uint16_t scanMatrixCounterC3R1 = 0

Definition at line 103 of file keyboard.cpp.

◆ scanMatrixCounterC3R2

uint16_t scanMatrixCounterC3R2 = 0

Definition at line 104 of file keyboard.cpp.

◆ scanMatrixCounterC3R3

uint16_t scanMatrixCounterC3R3 = 0

Definition at line 105 of file keyboard.cpp.

◆ scanMatrixCurrentColumn

uint16_t scanMatrixCurrentColumn = 1

Definition at line 96 of file keyboard.cpp.