software:firmware
MakAir Firmware
calibration.cpp File Reference

Calibration of the ventilator. More...

Go to the source code of this file.

Macros

#define RESTART_READ_KEYBOARD_DELAY   100
 

Functions

void Calibration_Init ()
 Initialization of calibration process. More...
 
void Calibration_Wait_Measure_Pressure (uint16_t ms)
 Block execution for a given duration. More...
 
void Calibration_Read_Keyboard_Delayed ()
 Read keyboard duing calibration process (delayed) More...
 
void Calibration_Restart ()
 Restart calibration process. More...
 
bool Calibration_Started ()
 Check if calibration mode is started. More...
 

Variables

int32_t pressureOffsetSum
 
uint32_t pressureOffsetCount
 
int32_t minOffsetValue = 0
 
int32_t maxOffsetValue = 0
 
uint32_t restartWaitTimer = 0
 
bool startButtonPressed = false
 
bool calibationStarted = false
 
bool calibrationValid = false
 

Detailed Description

Calibration of the ventilator.

Author
Makers For Life

Definition in file calibration.cpp.

Macro Definition Documentation

◆ RESTART_READ_KEYBOARD_DELAY

#define RESTART_READ_KEYBOARD_DELAY   100

Definition at line 38 of file calibration.cpp.

Function Documentation

◆ Calibration_Init()

void Calibration_Init ( void  )

Initialization of calibration process.

Definition at line 40 of file calibration.cpp.

40  {
41  // Restart calibration process when invalid
42  while (calibrationValid == false) {
43  delay(1000);
44  resetScreen();
45  calibationStarted = true;
46  // RCM-SW-17 (Christmas tree at startup)
48  digitalWrite(PIN_LED_START, LED_START_ACTIVE);
49  digitalWrite(PIN_LED_GREEN, LED_GREEN_ACTIVE);
50  digitalWrite(PIN_LED_RED, LED_RED_ACTIVE);
51  digitalWrite(PIN_LED_YELLOW, LED_YELLOW_ACTIVE);
53  digitalWrite(PIN_LED_START, LED_START_INACTIVE);
54  digitalWrite(PIN_LED_GREEN, LED_GREEN_INACTIVE);
55  digitalWrite(PIN_LED_RED, LED_RED_INACTIVE);
56  digitalWrite(PIN_LED_YELLOW, LED_YELLOW_INACTIVE);
58 
61 
62  int32_t inspiratoryPressureSensorOffset = 0;
63  resetScreen();
64  if (pressureOffsetCount != 0u) {
65  inspiratoryPressureSensorOffset =
66  pressureOffsetSum / static_cast<int32_t>(pressureOffsetCount);
67  } else {
68  inspiratoryPressureSensorOffset = 0;
69  }
70 
71  // Happens when patient is plugged at startup
72  if (((maxOffsetValue - minOffsetValue) >= 10)
73  || (inspiratoryPressureSensorOffset >= MAX_PRESSURE_OFFSET)) {
74  // Invalid calibration
75  calibrationValid = false;
78 
79  // Wait for user to press start to restart calibration
80  restartWaitTimer = 0;
81 
82  while (startButtonPressed == false) {
84 
85  // Heartbeat fatal error periodically
86  if ((restartWaitTimer % 1000u) == 0u) {
88  }
89 
91  }
92  } else {
93  calibrationValid = true;
94  inspiratoryPressureSensor.setPressureSensorOffset(inspiratoryPressureSensorOffset);
95  }
96 
97  if (calibrationValid) {
98 #ifdef MASS_FLOW_METER_ENABLED
99  int32_t flowMeterFlowAtStarting = MFM_read_airflow();
100  (void)MFM_calibrateZero();
101 #else
102  int32_t flowMeterFlowAtStarting = 0;
103 #endif
108  delay(500);
110  delay(1000);
111 #ifdef MASS_FLOW_METER_ENABLED
112  int32_t flowMeterFlowWithBlowerOn = MFM_read_airflow();
113 #else
114  int32_t flowMeterFlowWithBlowerOn = 30000;
115 #endif
116 
117  blower.stop();
118 
119  // Happens when flow meter fails
120  bool isMassFlowMeterOutOfRange = ((flowMeterFlowAtStarting < -1000)
121  || (flowMeterFlowAtStarting > 1000));
122 
123  if ((isMassFlowMeterOutOfRange == true)
124  || ((flowMeterFlowWithBlowerOn < 20000) || (flowMeterFlowWithBlowerOn > 100000))) {
125  // Invalid calibration
126  calibrationValid = false;
127  displayFlowMeterFail(flowMeterFlowAtStarting, flowMeterFlowWithBlowerOn);
128 
130 
131  // Wait for user to press start to restart calibration
132  restartWaitTimer = 0;
133 
134  while (startButtonPressed == false) {
136 
137  // Heartbeat fatal error periodically
138  if ((restartWaitTimer % 1000u) == 0u) {
139  // MFM reports an out-of-range value, it might not be connected
140  if (isMassFlowMeterOutOfRange == true) {
141  // MFM failure (eg. not connected)
143  } else {
144  // Other calibration errors
145  sendCalibrationFatalError(inspiratoryPressureSensorOffset,
147  flowMeterFlowAtStarting,
148  flowMeterFlowWithBlowerOn);
149  }
150  }
151 
153  }
154  } else {
155  calibrationValid = true;
156  }
157 
158  displayPressureOffset(inspiratoryPressureSensorOffset);
159  delay(1000);
160 #ifdef MASS_FLOW_METER_ENABLED
162  delay(1000);
163 #endif
164  }
165  // Reset values to default state
166  calibationStarted = false;
167  startButtonPressed = false;
168  }
169 }
Blower blower
Definition: blower.cpp:20
void Buzzer_High_Prio_Start(void)
Activate the buzzer pattern for high priority alarms.
Definition: buzzer.cpp:186
void Buzzer_Boot_Start(void)
Activate boot bip.
Definition: buzzer.cpp:194
bool startButtonPressed
Definition: calibration.cpp:35
int32_t maxOffsetValue
Definition: calibration.cpp:33
void Calibration_Wait_Measure_Pressure(uint16_t ms)
Block execution for a given duration.
uint32_t pressureOffsetCount
Definition: calibration.cpp:31
uint32_t restartWaitTimer
Definition: calibration.cpp:34
int32_t minOffsetValue
Definition: calibration.cpp:32
#define RESTART_READ_KEYBOARD_DELAY
Definition: calibration.cpp:38
void Calibration_Read_Keyboard_Delayed()
Read keyboard duing calibration process (delayed)
bool calibrationValid
Definition: calibration.cpp:37
int32_t pressureOffsetSum
Definition: calibration.cpp:30
bool calibationStarted
Definition: calibration.cpp:36
void stop()
Stops the blower.
Definition: blower.cpp:105
void runSpeed(uint16_t p_runSpeed)
Run the blower to a given speed.
Definition: blower.cpp:69
void setPressureSensorOffset(int32_t p_pressureSensorOffest)
Set the pressure sensor offset.
Definition: pressure.h:30
void execute()
Command the valve to go to the requested aperture.
void open()
Request opening of the Pressure Valve.
int32_t MFM_getOffset(void)
Get massflow meter offset.
int8_t MFM_calibrateZero(void)
If the massflow meter needs to be calibrated, this function will be usefull.
int32_t MFM_read_airflow(void)
Read instant air flow.
#define PIN_LED_GREEN
Definition: parameters.h:253
#define PIN_LED_RED
Definition: parameters.h:255
#define LED_START_INACTIVE
Definition: parameters.h:258
#define PIN_LED_YELLOW
Definition: parameters.h:254
#define PIN_LED_START
Definition: parameters.h:252
#define LED_GREEN_ACTIVE
Definition: parameters.h:263
#define DEFAULT_BLOWER_SPEED
Definition: parameters.h:194
#define LED_YELLOW_INACTIVE
Definition: parameters.h:262
#define LED_GREEN_INACTIVE
Definition: parameters.h:264
#define LED_RED_INACTIVE
Definition: parameters.h:260
#define LED_RED_ACTIVE
Definition: parameters.h:259
#define LED_YELLOW_ACTIVE
Definition: parameters.h:261
#define LED_START_ACTIVE
Definition: parameters.h:257
#define MAX_PRESSURE_OFFSET
Definition: parameters.h:123
PressureSensor inspiratoryPressureSensor
Definition: pressure.cpp:23
PressureValve inspiratoryValve
PressureValve expiratoryValve
void displayPressureOffsetUnstable(uint32_t p_minOffsetValue, uint32_t p_maxOffsetValue)
Display error when pressure offset is unstable.
Definition: screen.cpp:219
void displayFlowMeterOffset(int32_t p_flowMeterFlowOffset)
Display flow meter offset.
Definition: screen.cpp:212
void displayPressureOffset(int32_t p_inspiratoryPressureSensorOffset)
Display pressure offset.
Definition: screen.cpp:186
void displayPatientMustBeUnplugged()
Display the "calibration in progress" message.
Definition: screen.cpp:236
void resetScreen()
Erase everything that is on the screen.
Definition: screen.cpp:50
void displayFlowMeterFail(int32_t p_flowMeterFlowAtStarting, int32_t p_flowMeterFlowWithBlowerOn)
Display error when flow meter fails.
Definition: screen.cpp:194
void sendMassFlowMeterFatalError(void)
Send a "mass flow meter" fatal error.
Definition: telemetry.cpp:1321
void sendCalibrationFatalError(int16_t pressureOffsetValue, int16_t minPressureValue, int16_t maxPressureValue, int16_t flowAtStartingValue, int16_t flowWithBlowerOnValue)
Definition: telemetry.cpp:1193
void sendInconsistentPressureFatalError(uint16_t pressureValue)
Definition: telemetry.cpp:1359

◆ Calibration_Read_Keyboard_Delayed()

void Calibration_Read_Keyboard_Delayed ( void  )

Read keyboard duing calibration process (delayed)

Definition at line 197 of file calibration.cpp.

197  {
198  keyboardLoop();
200 }
void keyboardLoop()
Handle button events.
Definition: keyboard.cpp:223

◆ Calibration_Restart()

void Calibration_Restart ( void  )

Restart calibration process.

Definition at line 202 of file calibration.cpp.

202 { startButtonPressed = true; }

◆ Calibration_Started()

bool Calibration_Started ( void  )

Check if calibration mode is started.

Returns
True if calibration mode is started

Definition at line 204 of file calibration.cpp.

204 { return calibationStarted; }

◆ Calibration_Wait_Measure_Pressure()

void Calibration_Wait_Measure_Pressure ( uint16_t  ms)

Block execution for a given duration.

Parameters
msDuration of the blocking in millisecond

Definition at line 171 of file calibration.cpp.

171  {
172  uint16_t start = millis();
175  pressureOffsetSum = 0;
177 
178  // Open valves
183 
184  while ((millis() - start) < ms) {
185  // Measure 1 pressure per ms we wait
186  if ((millis() - start) > pressureOffsetCount) {
192  }
193  continue;
194  }
195 }
int32_t read()
Read the current pressure for the feedback control.
Definition: pressure.cpp:29
void close()
Request closing of the Pressure Valve.
int32_t pressureValue

Variable Documentation

◆ calibationStarted

bool calibationStarted = false

Definition at line 36 of file calibration.cpp.

◆ calibrationValid

bool calibrationValid = false

Definition at line 37 of file calibration.cpp.

◆ maxOffsetValue

int32_t maxOffsetValue = 0

Definition at line 33 of file calibration.cpp.

◆ minOffsetValue

int32_t minOffsetValue = 0

Definition at line 32 of file calibration.cpp.

◆ pressureOffsetCount

uint32_t pressureOffsetCount

Definition at line 31 of file calibration.cpp.

◆ pressureOffsetSum

int32_t pressureOffsetSum

Definition at line 30 of file calibration.cpp.

◆ restartWaitTimer

uint32_t restartWaitTimer = 0

Definition at line 34 of file calibration.cpp.

◆ startButtonPressed

bool startButtonPressed = false

Definition at line 35 of file calibration.cpp.