software:firmware
MakAir Firmware
screen.h File Reference

Display and LCD screen related functions. More...

#include <LiquidCrystal.h>
#include "../includes/parameters.h"

Go to the source code of this file.

Functions

void startScreen ()
 Start the screen. More...
 
void resetScreen ()
 Erase everything that is on the screen. More...
 
void displayCurrentPressure (uint16_t pressure, uint16_t cyclesPerMinute)
 Display the current step of the breathing. More...
 
void displayCurrentVolume (int32_t volumeMassFlow, uint16_t cyclesPerMinute)
 Display the current injected air volume. More...
 
void displayCurrentSettings (uint16_t peakPressureMax, uint16_t plateauPressureMax, uint16_t peepMin)
 Display the current settings. More...
 
void displayCurrentInformation (uint16_t peakPressure, uint16_t plateauPressure, uint16_t peep)
 Display relevant values from the ongoing cycle. More...
 
void displayAlarmInformation (uint8_t p_alarmCodes[], uint8_t p_nbTriggeredAlarms)
 Display triggered alarm codes. More...
 
void displayPressureOffsetUnstable (uint32_t p_minOffsetValue, uint32_t p_maxOffsetValue)
 Display error when pressure offset is unstable. More...
 
void displayPressureOffset (int32_t p_inspiratoryPressureSensorOffset)
 Display pressure offset. More...
 
void displayFlowMeterFail (int32_t p_flowMeterFlowAtStarting, int32_t p_flowMeterFlowWithBlowerOn)
 Display error when flow meter fails. More...
 
void displayFlowMeterOffset (int32_t p_flowMeterFlowOffset)
 Display flow meter offset. More...
 
void displayPatientMustBeUnplugged ()
 Display the "calibration in progress" message. More...
 
void displayEndOfLineTestMode ()
 Show that EOL mode was triggered. More...
 
void displayBatteryDeepDischarge ()
 Display error when battery level is too discharged. More...
 
void displayWatchdogError ()
 Display error when machine was restarted by watchdog. More...
 
void displayMachineStopped ()
 Display a message when the machine is stopped. More...
 
void clearAlarmDisplayCache ()
 Force clear the alarm display cache. More...
 
uint16_t convertAndRound (uint16_t pressure)
 Convert and round a pressure value. More...
 

Variables

LiquidCrystal screen
 Instance of the screen controller. More...
 

Detailed Description

Display and LCD screen related functions.

Author
Makers For Life

This relies on the LiquidCrystal library (https://github.com/arduino-libraries/LiquidCrystal). LCD screen must have 4 lines of 20 characters.

Definition in file screen.h.

Function Documentation

◆ clearAlarmDisplayCache()

void clearAlarmDisplayCache ( )

Force clear the alarm display cache.

Definition at line 144 of file screen.cpp.

144 { clearCache = true; }
static bool clearCache
Definition: screen.cpp:111

◆ convertAndRound()

uint16_t convertAndRound ( uint16_t  pressure)

Convert and round a pressure value.

Parameters
pressurePressure in mmH2O
Returns
Rounded pressure in cmH2O

Definition at line 275 of file screen.cpp.

275  {
276  uint16_t result;
277  uint16_t lastDigit = pressure % 10u;
278 
279  if (lastDigit < 5u) {
280  result = (pressure / 10u);
281  } else {
282  result = (pressure / 10u) + 1u;
283  }
284 
285  return result;
286 }

◆ displayAlarmInformation()

void displayAlarmInformation ( uint8_t  p_alarmCodes[],
uint8_t  p_nbTriggeredAlarms 
)

Display triggered alarm codes.

Parameters
p_alarmCodesList of alarm codes to display
p_nbTriggeredAlarmsNumber of triggered alarms

Definition at line 146 of file screen.cpp.

146  {
147  // WARNING There is a risk of data not being displayed as expected
148  // if the line is overwritten somewhere else in the code.
149  if (hasAlarmInformationChanged(p_alarmCodes, p_nbTriggeredAlarms)) {
150  if (p_nbTriggeredAlarms == 0u) {
151  screen.setCursor(0, 2);
152  screen.print(NO_ALARM_LINE);
153  } else {
154  uint8_t nbAlarmToPrint = min(MAX_ALARMS_DISPLAYED, p_nbTriggeredAlarms);
155 
156  // +1 for trailing NULL char
157  char buf[SCREEN_LINE_LENGTH + 1];
158 
159  // Write beginning of line
160  (void)strncpy(buf, ALARM_LINE, ALARMS_CODE_POS);
161 
162  // Write alarm codes
163  int pos = ALARMS_CODE_POS;
164  for (uint8_t i = 0; i < nbAlarmToPrint; i++) {
165  int spaceLeft = SCREEN_LINE_LENGTH - pos;
166  // + 1 for the trailing NULL char
167  int n = snprintf(&buf[pos], spaceLeft + 1, " %u", p_alarmCodes[i]);
168  if ((n < 0) || (n > spaceLeft)) {
169  break; // Error or no space left in buffer
170  }
171  pos += n;
172  }
173 
174  // Fill the end of the line with spaces
175  (void)strncpy(&buf[pos], &ALARM_LINE[pos], SCREEN_LINE_LENGTH - pos);
176 
177  // Make sure string is NULL terminated
178  buf[SCREEN_LINE_LENGTH] = '\0';
179 
180  screen.setCursor(0, 2);
181  screen.print(buf);
182  }
183  }
184 }
uint16_t i
#define SCREEN_LINE_LENGTH
Number of characters per line.
Definition: parameters.h:215
static const int ALARMS_CODE_POS
Position of the first alarm code in the third line of the screen.
Definition: screen.cpp:34
static const char * ALARM_LINE
Static label to display at the begining of the third line of the screen when at least one alarm is tr...
Definition: screen.cpp:31
LiquidCrystal screen(PIN_LCD_RS, PIN_LCD_RW, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7)
Instance of the screen controller.
static const char * NO_ALARM_LINE
Text to display at the third line of the screen when no alarm is triggered.
Definition: screen.cpp:27
static const uint8_t MAX_ALARMS_DISPLAYED
Number of alarm codes to display on screen at most.
Definition: screen.cpp:24
static bool hasAlarmInformationChanged(uint8_t p_alarmCodes[], uint8_t p_nbTriggeredAlarms)
Check whether triggered alarms are already displayed on screen or not.
Definition: screen.cpp:114

◆ displayBatteryDeepDischarge()

void displayBatteryDeepDischarge ( )

Display error when battery level is too discharged.

Definition at line 260 of file screen.cpp.

260  {
261  screen.clear();
262  screen.setCursor(0, 0);
263  screen.print("Battery very low");
264  screen.setCursor(0, 2);
265  screen.print("Please charge");
266  screen.setCursor(0, 3);
267  screen.print("before running.");
268 }

◆ displayCurrentInformation()

void displayCurrentInformation ( uint16_t  peakPressure,
uint16_t  plateauPressure,
uint16_t  peep 
)

Display relevant values from the ongoing cycle.

Parameters
peakPressureThe peak pressure [mmH2O]
plateauPressureThe plateau pressure [mmH2O]
peepThe Positive End Expiratory Pressure (PEEP) [mmH2O]

Definition at line 91 of file screen.cpp.

91  {
92  // cppcheck-suppress misra-c2012-12.3 ; call to unknown external: screen.setCursor
93  screen.setCursor(0, 3);
94  char message[SCREEN_LINE_LENGTH + 1];
95 
96  // If plateau was not detected
97  if (plateauPressure == UINT16_MAX) {
98  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "%2u ? %2u meas",
99  convertAndRound(peakPressure), convertAndRound(peep));
100  } else {
101  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "%2u %2u %2u meas",
102  convertAndRound(peakPressure), convertAndRound(plateauPressure),
103  convertAndRound(peep));
104  }
105 
106  screen.print(message);
107 }
uint16_t convertAndRound(uint16_t pressure)
Convert and round a pressure value.
Definition: screen.cpp:275

◆ displayCurrentPressure()

void displayCurrentPressure ( uint16_t  pressure,
uint16_t  cyclesPerMinute 
)

Display the current step of the breathing.

Parameters
pressureThe current pressure [mmH2O]
cyclesPerMinuteNext desired number of cycles per minute

Definition at line 65 of file screen.cpp.

65  {
66  screen.setCursor(0, 0);
67 
68  char message[SCREEN_LINE_LENGTH + 1];
69 
70  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "Pressure:%2u %2ucpm",
71  convertAndRound(pressure), cyclesPerMinute);
72 
73  screen.print(message);
74 }

◆ displayCurrentSettings()

void displayCurrentSettings ( uint16_t  peakPressureMax,
uint16_t  plateauPressureMax,
uint16_t  peepMin 
)

Display the current settings.

Parameters
peakPressureMaxPeakPressureMax [mmH2O]
plateauPressureMaxNext maximal plateau pressure [mmH2O]
peepMinNext desired Positive End Expiratory Pressure (PEEP) [mmH2O]

Definition at line 76 of file screen.cpp.

78  {
79  // cppcheck-suppress misra-c2012-12.3
80  screen.setCursor(0, 1);
81 
82  char message[SCREEN_LINE_LENGTH + 1];
83 
84  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "%2u %2u %2u set ",
85  convertAndRound(peakPressureMax), convertAndRound(plateauPressureMax),
86  convertAndRound(peepMin));
87 
88  screen.print(message);
89 }

◆ displayCurrentVolume()

void displayCurrentVolume ( int32_t  volumeMassFlow,
uint16_t  cyclesPerMinute 
)

Display the current injected air volume.

Parameters
volumeMassFlowThe number of liter breathed in this cycle
cyclesPerMinuteNext desired number of cycles per minute

Definition at line 53 of file screen.cpp.

53  {
54  screen.setCursor(0, 0);
55 
56  char message[SCREEN_LINE_LENGTH + 1];
57 
58  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "Cpm:%2u %4dml", cyclesPerMinute,
59  volumeMassFlow);
60 
61  screen.print(message);
62 }

◆ displayEndOfLineTestMode()

void displayEndOfLineTestMode ( )

Show that EOL mode was triggered.

Definition at line 245 of file screen.cpp.

245  {
246  screen.clear();
247  screen.print("EOL Test Mode");
248 }

◆ displayFlowMeterFail()

void displayFlowMeterFail ( int32_t  p_flowMeterFlowAtStarting,
int32_t  p_flowMeterFlowWithBlowerOn 
)

Display error when flow meter fails.

Parameters
p_flowMeterFlowAtStartingMeasured flow offset value
p_flowMeterFlowWithBlowerOnMaximum measured flow offset value

Definition at line 194 of file screen.cpp.

194  {
195  resetScreen();
196  screen.setCursor(0, 0);
197  char line1[SCREEN_LINE_LENGTH + 1];
198  (void)snprintf(line1, SCREEN_LINE_LENGTH + 1, "Flow offset: %3d SLM",
199  p_flowMeterFlowAtStarting / 1000);
200  screen.print(line1);
201  screen.setCursor(0, 1);
202  char line2[SCREEN_LINE_LENGTH + 1];
203  (void)snprintf(line2, SCREEN_LINE_LENGTH + 1, "Max flow: %-3d SLM",
204  p_flowMeterFlowWithBlowerOn / 1000);
205  screen.print(line2);
206  screen.setCursor(0, 2);
207  screen.print("Flow meter fail");
208  screen.setCursor(0, 3);
209  screen.print("Press start to retry");
210 }
void resetScreen()
Erase everything that is on the screen.
Definition: screen.cpp:50

◆ displayFlowMeterOffset()

void displayFlowMeterOffset ( int32_t  p_flowMeterFlowOffset)

Display flow meter offset.

Parameters
p_flowMeterFlowOffsetMeasured flow offset value

Definition at line 212 of file screen.cpp.

212  {
213  screen.setCursor(0, 3);
214  char message[SCREEN_LINE_LENGTH + 1];
215  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "Flow offset: %3d SLM", p_flowMeterFlowOffset);
216  screen.print(message);
217 }

◆ displayMachineStopped()

void displayMachineStopped ( )

Display a message when the machine is stopped.

Definition at line 270 of file screen.cpp.

270  {
271  screen.setCursor(0, 3);
272  screen.print("Press start to begin");
273 }

◆ displayPatientMustBeUnplugged()

void displayPatientMustBeUnplugged ( )

Display the "calibration in progress" message.

Definition at line 236 of file screen.cpp.

236  {
237  screen.setCursor(0, 0);
238  screen.print("Calibration");
239  screen.setCursor(0, 2);
240  screen.print("Patient must be");
241  screen.setCursor(0, 3);
242  screen.print("unplugged");
243 }

◆ displayPressureOffset()

void displayPressureOffset ( int32_t  p_inspiratoryPressureSensorOffset)

Display pressure offset.

Parameters
p_inspiratoryPressureSensorOffsetMeasured offset value

Definition at line 186 of file screen.cpp.

186  {
187  screen.setCursor(0, 3);
188  char message[SCREEN_LINE_LENGTH + 1];
189  (void)snprintf(message, SCREEN_LINE_LENGTH + 1, "P offset: %3d mmH2O",
190  p_inspiratoryPressureSensorOffset);
191  screen.print(message);
192 }

◆ displayPressureOffsetUnstable()

void displayPressureOffsetUnstable ( uint32_t  p_minOffsetValue,
uint32_t  p_maxOffsetValue 
)

Display error when pressure offset is unstable.

Parameters
p_minOffsetValueMinimum measured offset value
p_maxOffsetValueMaximum measured offset value

Definition at line 219 of file screen.cpp.

219  {
220  resetScreen();
221  screen.setCursor(0, 0);
222  char line1[SCREEN_LINE_LENGTH + 1];
223  (void)snprintf(line1, SCREEN_LINE_LENGTH + 1, "P offset is unstable");
224  screen.print(line1);
225  screen.setCursor(0, 1);
226  char line2[SCREEN_LINE_LENGTH + 1];
227  (void)snprintf(line2, SCREEN_LINE_LENGTH + 1, "Max-Min: %3u mmH2O",
228  p_maxOffsetValue - p_minOffsetValue);
229  screen.print(line2);
230  screen.setCursor(0, 2);
231  screen.print("Unplug patient and");
232  screen.setCursor(0, 3);
233  screen.print("press start");
234 }

◆ displayWatchdogError()

void displayWatchdogError ( )

Display error when machine was restarted by watchdog.

Definition at line 250 of file screen.cpp.

250  {
251  screen.clear();
252  screen.setCursor(0, 0);
253  screen.print("An error has occured");
254  screen.setCursor(0, 2);
255  screen.print("Check the machine");
256  screen.setCursor(0, 3);
257  screen.print("before re-using");
258 }

◆ resetScreen()

void resetScreen ( )

Erase everything that is on the screen.

Definition at line 50 of file screen.cpp.

50 { screen.clear(); }

◆ startScreen()

void startScreen ( )

Start the screen.

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

Definition at line 42 of file screen.cpp.

42  {
44  screen.setCursor(0, 0);
45  screen.print("Initialization ");
46  screen.setCursor(0, 1);
47  screen.print(VERSION);
48 }
#define VERSION
Current version of the software.
Definition: parameters.h:20
#define SCREEN_LINE_NUMBER
Number of lines.
Definition: parameters.h:212

Variable Documentation

◆ screen

LiquidCrystal screen
extern

Instance of the screen controller.