software:firmware
MakAir Firmware
MainController Class Reference

Controls breathing cycle. More...

#include <main_controller.h>

Public Member Functions

 MainController ()
 Default constructor. More...
 
void setup ()
 Initialize actuators. More...
 
void initRespiratoryCycle ()
 Begin a respiratory cycle. More...
 
void endRespiratoryCycle (uint32_t p_currentMillis)
 End a respiratory cycle. More...
 
void updateTick (uint32_t p_tick)
 Input a tick number. More...
 
void updatePressure (int16_t p_currentPressure)
 Input a pressure reading. More...
 
void updateInspiratoryFlow (int32_t p_currentInspiratoryFlow)
 Input an inspiratory flow reading. More...
 
void updateExpiratoryFlow (int32_t p_currentExpiratoryFlow)
 Input an expiratory flow reading. More...
 
void updateFakeExpiratoryFlow ()
 Calculate expiratory flow from pressure and valve angle. More...
 
void compute ()
 Perform the pressure control. More...
 
void onVentilationModeSet (uint16_t p_ventilationControllerMode)
 Set ventilation mode. More...
 
void onInspiratoryTriggerFlowSet (uint16_t p_inspiratoryTriggerFlow)
 Set inspiratory trigger flow. More...
 
void onExpiratoryTriggerFlowSet (uint16_t p_expiratoryTriggerFlow)
 Set expiratory trigger flow. More...
 
void onTiMinSet (uint16_t p_tiMin)
 Set min inspiratory time. More...
 
void onTiMaxSet (uint16_t p_tiMax)
 Set max inspiratory time. More...
 
void onLowInspiratoryMinuteVolumeAlarmThresholdSet (uint16_t p_lowInspiratoryMinuteVolumeAlarmThreshold)
 Set alarm threshold for low inspiratory minute volume. More...
 
void onHighInspiratoryMinuteVolumeAlarmThresholdSet (uint16_t p_highInspiratoryMinuteVolumeAlarmThreshold)
 Set alarm threshold for high inspiratory minute volume. More...
 
void onLowExpiratoryMinuteVolumeAlarmThresholdSet (uint16_t p_lowExpiratoryMinuteVolumeAlarmThreshold)
 Set alarm threshold for low expiratory minute volume. More...
 
void onHighExpiratoryMinuteVolumeAlarmThresholdSet (uint16_t p_highExpiratoryMinuteVolumeAlarmThreshold)
 Set alarm threshold for high expiratory minute volume. More...
 
void onlowRespiratoryRateAlarmThresholdSet (uint16_t p_lowRespiratoryRateAlarmThreshold)
 Set alarm threshold for low respiratory rate. More...
 
void onhighRespiratoryRateAlarmThresholdSet (uint16_t p_highRespiratoryRateAlarmThreshold)
 Set alarm threshold for high respiratory rate. More...
 
void onTargetTidalVolumeSet (uint16_t p_targetTidalVolume)
 Set target tidal volume (used in VC modes) More...
 
void onLowTidalVolumeAlarmThresholdSet (uint16_t p_lowTidalVolumeAlarmThreshold)
 Set threshold on tidal volume below which an alarm is raised. More...
 
void onHighTidalVolumeAlarmThresholdSet (uint16_t p_highTidalVolumeAlarmThreshold)
 Set threshold on tidal volume for which an alarm is raised. More...
 
void onPlateauDurationSet (uint16_t p_plateauDuration)
 Set the duration of Pause at the end of expiration in VC modes. More...
 
void onLeakAlarmThresholdSet (uint16_t p_leakAlarmThreshold)
 Set the threshold for leak that raise the alarm. More...
 
void onTargetInspiratoryFlow (uint16_t p_targetInspiratoryFlow)
 Set the inspiratory flow target. More...
 
void onInspiratoryDuration (uint16_t p_inspiratoryDuration)
 Set the inspiration duration. More...
 
void onCycleDecrease ()
 Decrease the desired number of cycles per minute. More...
 
void onCycleIncrease ()
 Increase the desired number of cycles per minute. More...
 
void onCycleSet (uint16_t p_cpm)
 Set the desired number of cycles per minute. More...
 
void onPeepPressureDecrease ()
 Decrease the minimal PEEP desired. More...
 
void onPeepPressureIncrease ()
 Increase the minimal PEEP desired. More...
 
void onPeepSet (int16_t p_peep)
 Set the desired PEEP. More...
 
void onPlateauPressureDecrease ()
 Decrease the desired plateau pressure. More...
 
void onPlateauPressureIncrease ()
 Increase the desired plateau pressure. More...
 
void onPlateauPressureSet (int16_t p_plateauPressure)
 Set the desired plateau pressure. More...
 
void onPeakPressureDecrease ()
 Decrease the desired peak pressure. More...
 
void onPeakPressureIncrease ()
 Increase the desired peak pressure. More...
 
void onExpiratoryTermSet (uint16_t p_expiratoryTerm)
 Set the desired expiratory term. More...
 
void onTriggerModeEnabledSet (uint16_t p_triggerEnabled)
 Enable or disable expiratory trigger mode. More...
 
void onTriggerOffsetSet (uint16_t p_triggerOffset)
 Set the desired offset for expiratory trigger. More...
 
void onPatientHeight (int16_t p_patientHeight)
 Set the desired patient height. More...
 
void onPeakPressureAlarmThreshold (int16_t p_peakPressureAlarmThreshold)
 Set the desired threshold for max peak pressure. More...
 
void onPatientGender (int16_t p_patientGender)
 Set the desired patient gender. More...
 
void onPatientComputePreset ()
 Updates patient computed params. More...
 
int32_t patientHeight () const
 
int16_t tidalVolumeCommand () const
 
int16_t plateauDurationCommand () const
 
int16_t peakPressureCommand () const
 Get the desired max peak. More...
 
int16_t plateauPressureCommand () const
 Get the desired plateau pressure. More...
 
int16_t peepCommand () const
 Get the desired PEEP. More...
 
uint16_t cyclesPerMinuteCommand () const
 Get the desired number of cycles per minute. More...
 
const int16_t pressureTriggerOffsetCommand () const
 Get the value of the inspiratory trigger pressure command. More...
 
const bool triggerModeEnabledCommand ()
 Get the enabling state of trigger mode. More...
 
const int16_t inspiratoryTriggerFlowCommand () const
 Get the value of the inspiratory trigger flow command. More...
 
const int16_t expiratoryTriggerFlowCommand () const
 Get the value of the expiratory trigger flow command. More...
 
const int16_t tiMinCommand () const
 Get the value of the minimum duration of inspiration in ms. More...
 
const int16_t tiMaxCommand () const
 Get the value of the max duration of inspiration in ms. More...
 
const int32_t targetInspiratoryFlowCommand () const
 get target inspiratory flow in mL/min (used in VC modes) More...
 
const int16_t inspiratoryDurationCommand () const
 Get duration of inspiration command. More...
 
int16_t tidalVolumeNextCommand () const
 Get the desired tidal Volume for the next cycle (used in VC modes) More...
 
int16_t plateauDurationNextCommand () const
 
int16_t peakPressureNextCommand () const
 Get the desired max peak for the next cycle. More...
 
int16_t plateauPressureNextCommand () const
 Get the desired plateau pressure for the next cycle. More...
 
int16_t peepNextCommand () const
 Get the desired PEEP for the next cycle. More...
 
uint16_t cyclesPerMinuteNextCommand () const
 Get the desired number of cycles per minute for the next cycle. More...
 
const int16_t pressureTriggerOffsetNextCommand () const
 Get the value of the inspiratory trigger pressure command for the next cycle. More...
 
const bool triggerModeEnabledNextCommand ()
 Get the enabling state of trigger mode for the next cycle. More...
 
const int16_t inspiratoryTriggerFlowNextCommand () const
 Get the value of the inspiratory trigger flow command for the next cycle. More...
 
const int16_t expiratoryTriggerFlowNextCommand () const
 Get the value of the expiratory trigger flow command for the next cycle. More...
 
const int16_t tiMinNextCommand () const
 Get the value of the minimum duration of inspiration in ms for the next cycle. More...
 
const int16_t tiMaxNextCommand () const
 Get the value of the max duration of inspiration in ms for the next cycle. More...
 
const int32_t targetInspiratoryFlowNextCommand () const
 get target inspiratory flow in mL/min (used in VC modes) for next cycle More...
 
const int16_t inspiratoryDurationNextCommand () const
 Get duration of inspiration command fo next cycle. More...
 
const VentilationControllerventilationControllerNextCommand () const
 Ventilation controller pointer for the next cycle. More...
 
int16_t peakPressureMeasure () const
 Get the measured peak pressure. More...
 
int16_t rebouncePeakPressureMeasure () const
 Get the measured rebounce peak pressure. More...
 
int16_t plateauPressureMeasure () const
 Get the measured plateau pressure. More...
 
int16_t peepMeasure () const
 Get the measured PEEP. More...
 
uint16_t cyclesPerMinuteMeasure () const
 Get the desired number of cycles per minute. More...
 
uint16_t tidalVolumeMeasure () const
 Get the measured Tidal Volume. Updated only at the end of inspiration. More...
 
int32_t currentDeliveredVolume () const
 Get the measured Tidal Volume. Updated in real time. More...
 
uint32_t cycleNumber () const
 Get the number of past cycles since the beginning. More...
 
uint16_t ticksPerCycle () const
 Get the duration of a cycle in ticks. More...
 
uint32_t ticksPerInhalation () const
 Get the duration of an inhalation in ticks. More...
 
void ticksPerInhalationSet (uint32_t p_ticksPerInhalation)
 Get the duration of an inhalation in ticks. More...
 
int16_t pressure () const
 Get the current measured pressure. More...
 
int32_t inspiratoryFlow () const
 Get the current inspiratoryFlow. More...
 
int32_t expiratoryFlow () const
 Get the current expiratoryFlow. More...
 
int32_t dt () const
 Get the delta of time since the last cycle (in ms) More...
 
uint32_t tick () const
 Get the tick number of the current cycle. More...
 
int32_t pressureCommand () const
 Get the pressure command. More...
 
CyclePhases phase () const
 Get the current cycle phase. More...
 
const bool triggered () const
 Get the state of the inspiratory trigger. More...
 
const void setTrigger (bool triggerValue)
 Reset the trigger to false. More...
 
const bool isPeepDetected ()
 Get if the PEEP has been detected during this cycle. More...
 
int16_t * lastPressureValues ()
 Get last pressure values. More...
 
uint16_t lastPressureValuesIndex ()
 Get last pressure values index. More...
 
void updateDt (int32_t p_dt)
 Input the real duration since the last pressure controller computation. More...
 
void updateCurrentDeliveredVolume (int32_t p_currentDeliveredVolume)
 Input the current delivered volume in inspiratory branch since beginning of the respiratory cycle. More...
 
void updateCurrentExpiratoryVolume (int32_t p_expiratoryVolume)
 
void reachSafetyPosition ()
 Put actuators in safety position. More...
 
void stop (uint32_t p_currentMillis)
 Stop the breathing. More...
 
void sendStopMessageToUi ()
 Send a "stopped" telemetry message. More...
 
void sendMachineState ()
 Send a "machine state snapshot" telemetry message. More...
 

Private Member Functions

void updatePhase ()
 Update the cycle phase. More...
 
void inhale ()
 Perform the pressure control and compute the actuators commands during the inhalation phase. More...
 
void exhale ()
 Perform the pressure control and compute the actuators commands during the exhalation phase. More...
 
void computeTickParameters ()
 Compute various cycle durations given the desired number of cycles per minute. More...
 
void executeCommands ()
 Send the computed commands to actuators. More...
 
void checkCycleAlarm ()
 At the end of a respiratory cycle, check if some alarms are triggered. More...
 
void calculateBlowerIncrement ()
 
void printDebugValues ()
 Print debug values, used to tweak PID, and triggers. More...
 

Private Attributes

uint32_t m_tick
 Actual tick number (given by the main state machine) More...
 
uint16_t m_cyclesPerMinuteCommand
 Actual desired number of cycles per minute. More...
 
uint16_t m_cyclesPerMinuteNextCommand
 Number of cycles per minute desired by the operator for the next cycle. More...
 
uint32_t m_cyclesPerMinuteMeasure
 Measured number of cycles per minute. More...
 
uint32_t m_lastBreathPeriodsMs [NUMBER_OF_BREATH_PERIOD]
 Period durations of last beathings. More...
 
uint32_t m_lastBreathPeriodsMsIndex
 Index for the m_lastBreathPeriodsMs array. More...
 
uint32_t m_lastEndOfRespirationDateMs
 Date of the last ending of a respiration. More...
 
int16_t m_peakPressureCommand
 Actual desired peak pressure. More...
 
int16_t m_peakPressureMeasure
 Measured value of peak pressure. More...
 
int16_t m_rebouncePeakPressureMeasure
 Measured value of rebounce peak pressure. More...
 
int16_t m_peakPressureNextCommand
 Peak pressure desired by the operator for the next cycle. More...
 
int16_t m_plateauPressureCommand
 Actual desired plateau pressure. More...
 
int16_t m_plateauPressureNextCommand
 Plateau pressure desired by the operator for the next cycle. More...
 
int16_t m_plateauPressureMeasure
 Measured value of the plateau pressure. More...
 
int16_t m_plateauPressureToDisplay
 Measured value of the plateau pressure for display. More...
 
int64_t m_PlateauMeasureSum
 Sum for calulating plateau value. More...
 
uint16_t m_PlateauMeasureCount
 Count for calulating plateau value. More...
 
uint32_t m_plateauDurationMs
 Duration of the plateau. More...
 
int16_t m_peepCommand
 Actual desired PEEP. More...
 
int16_t m_peepNextCommand
 Desired PEEP for the next cycle. More...
 
int16_t m_peepMeasure
 Measured value of the PEEP. More...
 
bool m_isPeepDetected
 Is PEEP pressure detected in the cycle? More...
 
int16_t m_pressureTriggerOffsetCommand
 Actual pressure trigger offset. More...
 
int16_t m_pressureTriggerOffsetNextCommand
 Desired pressure trigger offset for the next cycle. More...
 
bool m_triggered
 Is inspiratory triggered or not? More...
 
bool m_triggerModeEnabledCommand
 Actual state of enabling of trigger mode. More...
 
bool m_triggerModeEnabledNextCommand
 Desired state of enabling of trigger mode for the next cycle. More...
 
bool m_tidalVolumeAlreadyRead
 True if Tidal volume has already been read during cycle. More...
 
uint16_t m_expiratoryTermCommand
 Actual expiratory term. More...
 
uint16_t m_expiratoryTermNextCommand
 Desired expiratory term for the next cycle. More...
 
int16_t m_inspiratoryTriggerFlowCommand
 Desired inspiratory trigger flow. More...
 
int16_t m_inspiratoryTriggerFlowNextCommand
 Desired inspiratory trigger flow for next cycle. More...
 
int16_t m_expiratoryTriggerFlowCommand
 Desired expiratory trigger flow (in percent of max flow) More...
 
int16_t m_expiratoryTriggerFlowNextCommand
 Desired expiratory trigger flow for next cycle (in percent of max flow) More...
 
int16_t m_tiMinCommand
 Minimum duration of inspiration in ms. More...
 
int16_t m_tiMaxCommand
 Max duration of inspiration in ms. More...
 
int16_t m_tiMinNextCommand
 Minimum duration of inspiration in ms for next cycle. More...
 
int16_t m_tiMaxNextCommand
 Max duration of inspiration in ms for next cycle. More...
 
VentilationControllerm_ventilationController
 Ventilation controller in use (for everything related to breathing control) More...
 
VentilationControllerm_ventilationControllerNextCommand
 Ventilation controller for the next cycle. More...
 
VentilationControllerm_ventilationControllersTable [NUMBER_OF_VENTILATION_MODES+1u]
 Array containing pointers to different ventilation controllers. More...
 
VentilationModes m_ventilationControllerMode
 
int16_t m_tidalVolumeMeasure
 Measured value of the Tidal volume (volume of air pushed in patient lungs in last inspiration) More...
 
int16_t m_tidalVolumeCommand
 Tidal volume command (used in VC modes) More...
 
int16_t m_tidalVolumeNextCommand
 Tidal volume command for next cycle. More...
 
int16_t m_plateauDurationCommand
 Plateau duration command (used in VC modes) More...
 
int16_t m_plateauDurationNextCommand
 Plateau duration command for next cycle. More...
 
int32_t m_targetInspiratoryFlowCommand
 inspiratory flow required (used in VC modes) More...
 
int32_t m_targetInspiratoryFlowNextCommand
 inspiratory flow required (used in VC modes) for next cycle More...
 
int16_t m_inspiratoryDurationCommand
 Duration of inspiration. More...
 
int16_t m_inspiratoryDurationNextCommand
 Duration of inspiration. More...
 
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdCommand
 Threshold for low inspiratory minute volume alarm. More...
 
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand
 Threshold for low inspiratory minute volume alarm for next cycle. More...
 
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdCommand
 Threshold for high inspiratory minute volume alarm. More...
 
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand
 Threshold for high inspiratory minute volume alarm for next cycle. More...
 
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdCommand
 Threshold for low inspiratory minute volume alarm. More...
 
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand
 Threshold for low inspiratory minute volume alarm for next cycle. More...
 
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdCommand
 Threshold for high inspiratory minute volume alarm. More...
 
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand
 Threshold for high inspiratory minute volume alarm for next cycle. More...
 
int32_t m_lowRespiratoryRateAlarmThresholdCommand
 Threshold for low respiratory rate. More...
 
int32_t m_lowRespiratoryRateAlarmThresholdNextCommand
 Threshold for low respiratory rate for next cycle. More...
 
int32_t m_highRespiratoryRateAlarmThresholdCommand
 Threshold for low respiratory rate. More...
 
int32_t m_highRespiratoryRateAlarmThresholdNextCommand
 Threshold for low respiratory rate for next cycle. More...
 
int32_t m_lowTidalVolumeAlarmThresholdCommand
 Threshold for low tidal Volume Alarm. More...
 
int32_t m_lowTidalVolumeAlarmThresholdNextCommand
 Threshold for low tidal Volume Alarm next cycle. More...
 
int32_t m_highTidalVolumeAlarmThresholdCommand
 Threshold for high tidal Volume Alarm. More...
 
int32_t m_highTidalVolumeAlarmThresholdNextCommand
 Threshold for high tidal Volume Alarm next cycle. More...
 
int32_t m_leakAlarmThresholdCommand
 Threshold for leak alarm. More...
 
int32_t m_leakAlarmThresholdNextCommand
 Threshold for leak alarm for next cycle. More...
 
int16_t m_peakPressureAlarmThresholdCommand
 Threshold for peak pressure alarm. More...
 
int16_t m_peakPressureAlarmThresholdNextCommand
 Threshold for peak pressure alarmfor next cycle. More...
 
int32_t m_expiratoryVolume
 Volume expired by the patient during the exhalation phase. More...
 
uint16_t m_ticksPerCycle
 Number of hundredth of second per cycle. More...
 
uint32_t m_ticksPerInhalation
 Number of hundredth of second per inhalation. More...
 
int16_t m_pressure
 Measured pressure. More...
 
int32_t m_inspiratoryFlow
 Measured inspiratory flow. More...
 
int32_t m_maxInspiratoryFlow
 Measured max inspiratory flow. More...
 
int32_t m_expiratoryFlow
 Measured inspiratory flow. More...
 
int32_t m_maxExpiratoryFlow
 Measured max inspiratory flow. More...
 
int32_t m_lastMaxExpiratoryFlow
 Measured max inspiratory flow. More...
 
int32_t m_currentDeliveredVolume
 Current delivered volume by the blower. More...
 
int16_t m_inhalationLastPressure
 Last pressure of inhalation. More...
 
uint32_t m_inspiratoryValveAngle
 Blower valve angle at peak. More...
 
CyclePhases m_phase
 Current respiratory cycle phase. More...
 
uint32_t m_cycleNb
 Number of elapsed cycles since beginning. More...
 
int32_t m_dt
 Time since the last computation (in microsecond) More...
 
int32_t m_pressureCommand
 Requested pressure at a given point in time. More...
 
int16_t m_lastPressureValues [MAX_PRESSURE_SAMPLES]
 Last pressure values. More...
 
uint16_t m_lastPressureValuesIndex
 Last pressure index. More...
 
uint32_t m_sumOfPressures
 Sum of the current cycle's pressures. More...
 
uint16_t m_numberOfPressures
 Number of the current cycle's pressures. More...
 
int32_t m_patientHeight
 
int32_t m_patientGender
 

Detailed Description

Controls breathing cycle.

Definition at line 36 of file main_controller.h.

Constructor & Destructor Documentation

◆ MainController()

MainController::MainController ( )

Default constructor.

Definition at line 26 of file main_controller.cpp.

26  {
27  m_tick = 0;
29 
32  m_expiratoryFlow = 0;
37 
62 
69 
74 
79 
84 
89 
92 
95 
98 
101 
104 
107 
113 
115 
118 
128 
131 
132  m_cycleNb = 0;
133 
135 
136  m_sumOfPressures = 0;
140 
141  m_triggered = false;
142  m_isPeepDetected = false;
143  m_tidalVolumeAlreadyRead = false;
145 
146  m_patientHeight = 0;
147  m_patientGender = 0;
148 
150 
152 
154  for (uint8_t i = 0u; i < MAX_PRESSURE_SAMPLES; i++) {
155  m_lastPressureValues[i] = 0;
156  }
157 
159  for (uint8_t i = 0u; i < NUMBER_OF_BREATH_PERIOD; i++) {
161  }
162 }
int16_t m_pressure
Measured pressure.
uint16_t m_PlateauMeasureCount
Count for calulating plateau value.
int16_t m_tiMaxNextCommand
Max duration of inspiration in ms for next cycle.
uint32_t m_cycleNb
Number of elapsed cycles since beginning.
uint16_t m_expiratoryTermCommand
Actual expiratory term.
int16_t m_plateauPressureCommand
Actual desired plateau pressure.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
int16_t m_expiratoryTriggerFlowNextCommand
Desired expiratory trigger flow for next cycle (in percent of max flow)
int16_t m_peakPressureNextCommand
Peak pressure desired by the operator for the next cycle.
int16_t m_inspiratoryDurationNextCommand
Duration of inspiration.
VentilationController * m_ventilationControllerNextCommand
Ventilation controller for the next cycle.
uint32_t m_tick
Actual tick number (given by the main state machine)
int16_t m_tiMinCommand
Minimum duration of inspiration in ms.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
uint16_t m_cyclesPerMinuteNextCommand
Number of cycles per minute desired by the operator for the next cycle.
uint16_t m_cyclesPerMinuteCommand
Actual desired number of cycles per minute.
int16_t m_lastPressureValues[MAX_PRESSURE_SAMPLES]
Last pressure values.
int16_t m_plateauDurationCommand
Plateau duration command (used in VC modes)
int32_t m_highRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
int16_t m_tidalVolumeMeasure
Measured value of the Tidal volume (volume of air pushed in patient lungs in last inspiration)
int16_t m_rebouncePeakPressureMeasure
Measured value of rebounce peak pressure.
int32_t m_leakAlarmThresholdCommand
Threshold for leak alarm.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
int32_t m_highTidalVolumeAlarmThresholdCommand
Threshold for high tidal Volume Alarm.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
int32_t m_maxExpiratoryFlow
Measured max inspiratory flow.
int16_t m_plateauPressureMeasure
Measured value of the plateau pressure.
int32_t m_highTidalVolumeAlarmThresholdNextCommand
Threshold for high tidal Volume Alarm next cycle.
int32_t m_patientHeight
VentilationController * m_ventilationController
Ventilation controller in use (for everything related to breathing control)
int32_t m_pressureCommand
Requested pressure at a given point in time.
uint16_t m_numberOfPressures
Number of the current cycle's pressures.
uint32_t m_plateauDurationMs
Duration of the plateau.
bool m_isPeepDetected
Is PEEP pressure detected in the cycle?
int16_t m_tidalVolumeCommand
Tidal volume command (used in VC modes)
int16_t m_tiMinNextCommand
Minimum duration of inspiration in ms for next cycle.
int16_t m_peakPressureAlarmThresholdNextCommand
Threshold for peak pressure alarmfor next cycle.
uint32_t m_inspiratoryValveAngle
Blower valve angle at peak.
int16_t m_pressureTriggerOffsetNextCommand
Desired pressure trigger offset for the next cycle.
uint32_t m_lastBreathPeriodsMsIndex
Index for the m_lastBreathPeriodsMs array.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
int16_t m_tiMaxCommand
Max duration of inspiration in ms.
uint32_t m_sumOfPressures
Sum of the current cycle's pressures.
int32_t m_lowRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_inspiratoryTriggerFlowNextCommand
Desired inspiratory trigger flow for next cycle.
int32_t m_lowTidalVolumeAlarmThresholdCommand
Threshold for low tidal Volume Alarm.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
int16_t m_inhalationLastPressure
Last pressure of inhalation.
int32_t m_patientGender
void computeTickParameters()
Compute various cycle durations given the desired number of cycles per minute.
bool m_tidalVolumeAlreadyRead
True if Tidal volume has already been read during cycle.
int32_t m_expiratoryVolume
Volume expired by the patient during the exhalation phase.
int16_t m_peepMeasure
Measured value of the PEEP.
int32_t m_dt
Time since the last computation (in microsecond)
uint32_t m_cyclesPerMinuteMeasure
Measured number of cycles per minute.
bool m_triggered
Is inspiratory triggered or not?
int32_t m_currentDeliveredVolume
Current delivered volume by the blower.
CyclePhases m_phase
Current respiratory cycle phase.
int32_t m_leakAlarmThresholdNextCommand
Threshold for leak alarm for next cycle.
int16_t m_inspiratoryTriggerFlowCommand
Desired inspiratory trigger flow.
int16_t m_peakPressureMeasure
Measured value of peak pressure.
int32_t m_lowTidalVolumeAlarmThresholdNextCommand
Threshold for low tidal Volume Alarm next cycle.
int16_t m_pressureTriggerOffsetCommand
Actual pressure trigger offset.
int32_t m_targetInspiratoryFlowNextCommand
inspiratory flow required (used in VC modes) for next cycle
int16_t m_plateauPressureNextCommand
Plateau pressure desired by the operator for the next cycle.
int64_t m_PlateauMeasureSum
Sum for calulating plateau value.
int32_t m_targetInspiratoryFlowCommand
inspiratory flow required (used in VC modes)
int16_t m_plateauPressureToDisplay
Measured value of the plateau pressure for display.
VentilationController * m_ventilationControllersTable[NUMBER_OF_VENTILATION_MODES+1u]
Array containing pointers to different ventilation controllers.
int16_t m_peakPressureCommand
Actual desired peak pressure.
int16_t m_expiratoryTriggerFlowCommand
Desired expiratory trigger flow (in percent of max flow)
int32_t m_highRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_peepCommand
Actual desired PEEP.
int16_t m_inspiratoryDurationCommand
Duration of inspiration.
uint32_t m_lastBreathPeriodsMs[NUMBER_OF_BREATH_PERIOD]
Period durations of last beathings.
int16_t m_plateauDurationNextCommand
Plateau duration command for next cycle.
uint32_t m_lastEndOfRespirationDateMs
Date of the last ending of a respiration.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
uint16_t m_lastPressureValuesIndex
Last pressure index.
int16_t m_tidalVolumeNextCommand
Tidal volume command for next cycle.
int32_t m_expiratoryFlow
Measured inspiratory flow.
int16_t m_peepNextCommand
Desired PEEP for the next cycle.
int32_t m_maxInspiratoryFlow
Measured max inspiratory flow.
int32_t m_inspiratoryFlow
Measured inspiratory flow.
bool m_triggerModeEnabledNextCommand
Desired state of enabling of trigger mode for the next cycle.
VentilationModes m_ventilationControllerMode
uint16_t m_expiratoryTermNextCommand
Desired expiratory term for the next cycle.
bool m_triggerModeEnabledCommand
Actual state of enabling of trigger mode.
int32_t m_lowRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
int16_t m_peakPressureAlarmThresholdCommand
Threshold for peak pressure alarm.
int32_t m_lastMaxExpiratoryFlow
Measured max inspiratory flow.
@ PC_CMV
PC-CMV (default)
Definition: cycle.h:24
@ VC_AC
VC-AC.
Definition: cycle.h:32
@ VC_CMV
VC-CMV.
Definition: cycle.h:28
@ PC_AC
PC-AC.
Definition: cycle.h:26
@ PC_VSAI
PC-VSAI.
Definition: cycle.h:30
@ INHALATION
Inspiration and inspiration holding.
Definition: cycle.h:16
#define MAX_PRESSURE_SAMPLES
Number of values to aggregate when computing plateau pressure.
uint16_t i
#define DEFAULT_INSPIRATORY_TRIGGER_FLOW_COMMAND
Definition: parameters.h:95
#define TRIGGER_MODE_ENABLED_BY_DEFAULT
Definition: parameters.h:127
#define DEFAULT_LEAK_ALARM_THRESHOLD
Definition: parameters.h:109
#define DEFAULT_MIN_INSPIRATION_DURATION_COMMAND
Definition: parameters.h:97
#define DEFAULT_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:108
#define DEFAULT_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:101
#define DEFAULT_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:103
#define DEFAULT_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:107
#define DEFAULT_EXPIRATORY_TRIGGER_FLOW_COMMAND
Definition: parameters.h:96
#define MAIN_CONTROLLER_COMPUTE_PERIOD_MICROSECONDS
Definition: parameters.h:30
#define DEFAULT_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:102
#define DEFAULT_PLATEAU_DURATION_COMMAND
Definition: parameters.h:93
#define DEFAULT_PLATEAU_COMMAND
Definition: parameters.h:89
#define DEFAULT_CYCLE_PER_MINUTE_COMMAND
Definition: parameters.h:117
#define DEFAULT_MAX_INSPIRATION_DURATION_COMMAND
Definition: parameters.h:98
#define VALVE_CLOSED_STATE
Angle when closed.
Definition: parameters.h:170
#define DEFAULT_TIDAL_VOLUME_COMMAND
Definition: parameters.h:92
#define DEFAULT_EXPIRATORY_TERM_COMMAND
Definition: parameters.h:91
#define DEFAULT_PEEP_COMMAND
Definition: parameters.h:88
#define DEFAULT_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:105
#define NUMBER_OF_BREATH_PERIOD
Number of periods used for calculating the respiratory rate.
Definition: parameters.h:157
#define DEFAULT_INSPIRATORY_DURATION
Definition: parameters.h:100
#define DEFAULT_TARGET_FLOW_COMMAND
Definition: parameters.h:99
#define CONST_INITIAL_ZERO_VOLUME
Definition: parameters.h:42
#define DEFAULT_PEAK_PRESSURE_COMMAND
Definition: parameters.h:90
#define DEFAULT_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:110
#define DEFAULT_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:104
#define CONST_INITIAL_ZERO_PRESSURE
Definition: parameters.h:41
#define DEFAULT_TRIGGER_OFFSET
Definition: parameters.h:94
#define DEFAULT_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:106
PC_AC_Controller pcAcController
PC_CMV_Controller pcCmvController
PC_VSAI_Controller pcVsaiController
VC_AC_Controller vcAcController
VC_CMV_Controller vcCmvController

Member Function Documentation

◆ calculateBlowerIncrement()

void MainController::calculateBlowerIncrement ( )
private

◆ checkCycleAlarm()

void MainController::checkCycleAlarm ( )
private

At the end of a respiratory cycle, check if some alarms are triggered.

Definition at line 528 of file main_controller.cpp.

528  {
529  // RCM-SW-1 + RCM-SW-14: check if plateau is reached
530  int16_t minPlateauBeforeAlarm =
532  int16_t maxPlateauBeforeAlarm =
534  if ((m_plateauPressureMeasure < minPlateauBeforeAlarm)
535  || (m_plateauPressureMeasure > maxPlateauBeforeAlarm)) {
538  } else {
541  }
542 
543  // RCM-SW-2 + RCM-SW-19: check is mean pressure was < 2 cmH2O
544  int16_t meanPressure = m_sumOfPressures / m_numberOfPressures;
545  if (meanPressure <= ALARM_THRESHOLD_MIN_PRESSURE) {
547  m_pressure);
549  m_pressure);
550  } else {
553  }
554 
555  // RCM-SW-3 + RCM-SW-15
556  int16_t PeepBeforeAlarm = m_peepCommand - ALARM_THRESHOLD_DIFFERENCE_PRESSURE;
557  int16_t maxPeepBeforeAlarm = m_peepCommand + ALARM_THRESHOLD_DIFFERENCE_PRESSURE;
558  if ((m_peepMeasure < PeepBeforeAlarm) || (m_peepMeasure > maxPeepBeforeAlarm)) {
561  } else {
564  }
565 
566  // RC-SW-4 & 5 : Inspiratory minute Volume is too low/high
567  int32_t inspiratoryMinuteVolume =
568  m_tidalVolumeMeasure * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
569  if (inspiratoryMinuteVolume < m_lowInspiratoryMinuteVolumeAlarmThresholdCommand) {
572  inspiratoryMinuteVolume);
574  } else if (inspiratoryMinuteVolume > m_highInspiratoryMinuteVolumeAlarmThresholdCommand) {
577  inspiratoryMinuteVolume);
579  } else {
582  }
583 
584  // RC-SW-6 & 7 : Expiratory minute Volume is too low/high
585  int32_t expiratoryMinuteVolume =
586  m_expiratoryVolume * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
587  if (expiratoryMinuteVolume < m_lowExpiratoryMinuteVolumeAlarmThresholdCommand) {
590  expiratoryMinuteVolume);
592  } else if (expiratoryMinuteVolume > m_highExpiratoryMinuteVolumeAlarmThresholdCommand) {
595  expiratoryMinuteVolume);
597  } else {
600  }
601 
602  // RC-SW-8 & 9 : Respiratory rate is too low/high
603  if (static_cast<int32_t>(m_cyclesPerMinuteMeasure)
609  } else if (static_cast<int32_t>(m_cyclesPerMinuteMeasure)
615  } else {
618  }
619 
620  // RC-SW-20 & 21 : tidal Volume is too low/high
629  } else {
632  }
633 
634  // RCM_SW_10 : Leak is too high
635  int32_t leakPerMinute = (m_currentDeliveredVolume - m_expiratoryVolume)
636  * static_cast<int32_t>(m_cyclesPerMinuteMeasure); // In mL/min
637  if (leakPerMinute > m_leakAlarmThresholdCommand) {
639  leakPerMinute);
640  } else {
642  }
643 
646  m_pressure);
647  } else {
649  }
650 
655  } else {
657  }
658 }
AlarmController alarmController
Instance of the alarm controller.
#define RCM_SW_20
#define RCM_SW_15
#define RCM_SW_3
#define RCM_SW_5
#define RCM_SW_23
#define RCM_SW_19
#define RCM_SW_6
#define RCM_SW_1
#define RCM_SW_9
#define RCM_SW_14
#define RCM_SW_8
#define RCM_SW_4
#define RCM_SW_21
#define RCM_SW_2
#define RCM_SW_22
#define RCM_SW_10
#define RCM_SW_7
void detectedAlarm(uint8_t p_alarmCode, uint32_t p_cycleNumber, uint32_t p_expected, uint32_t p_measured)
Mark a specific alarm as detected.
void notDetectedAlarm(uint8_t p_alarmCode)
Reset detection of a specific alarm.
#define ALARM_THRESHOLD_DIFFERENCE_PERCENT
Definition: parameters.h:312
#define ALARM_THRESHOLD_DIFFERENCE_PRESSURE
Definition: parameters.h:313
#define ALARM_THRESHOLD_MIN_PRESSURE
Definition: parameters.h:311
#define MIN_EXPIRATORY_FLOW_OFFSET
Definition: parameters.h:125

◆ compute()

void MainController::compute ( )

Perform the pressure control.

Parameters
p_tickDuration in hundredth of second from the begining of the cycle

Definition at line 248 of file main_controller.cpp.

248  {
249  // Update the cycle phase
250  updatePhase();
251 
252  // Compute metrics for alarms
253  m_sumOfPressures += static_cast<uint32_t>(m_pressure);
255 
256  // Store last pressure values only every 10ms
257  uint32_t moduloValue = max(1u, (10u / MAIN_CONTROLLER_COMPUTE_PERIOD_MS));
258  if ((m_tick % moduloValue) == 0u) {
259  // Store the current pressure to compute aggregates
262 
263  // Start over if we reached the max samples number
264  if (m_lastPressureValuesIndex >= static_cast<uint16_t>(MAX_PRESSURE_SAMPLES)) {
266  }
267  }
268 
269  // Act accordingly
270  switch (m_phase) {
272  inhale();
274  break;
275 
277  exhale();
278  break;
279 
280  default:
281  // Do nothing
282  break;
283  }
284 
286 
287  // Send data snaphshot only every 10 ms
288  if ((m_tick % moduloValue) == 0u) {
291  max(int32_t(0), m_inspiratoryFlow / 10),
292  max(int32_t(0), m_expiratoryFlow / 10));
293  }
294 
295  executeCommands();
296 
297 #ifdef MASS_FLOW_METER_ENABLED
298  // Measure volume only during inspiration
299  // Add 100 ms to allow valve to close completely
303  int32_t volume = m_currentDeliveredVolume;
305  ((volume > 0xFFFE) || (volume < 0)) ? 0xFFFFu : static_cast<uint16_t>(volume);
306  }
307 
308 #else
309  m_tidalVolumeMeasure = UINT16_MAX;
310 #endif
312 }
uint32_t getBatteryLevel()
Returns battery level.
Definition: battery.cpp:123
Blower blower
Definition: blower.cpp:20
void updateCoreData(uint32_t p_tick, uint16_t p_pressure, CyclePhases p_phase, uint32_t p_cycle_number)
Update internal state of alarm controller with data from pressure controller.
uint16_t getSpeed() const
Get speed value.
Definition: blower.cpp:101
void executeCommands()
Send the computed commands to actuators.
void updatePhase()
Update the cycle phase.
void exhale()
Perform the pressure control and compute the actuators commands during the exhalation phase.
uint32_t m_ticksPerInhalation
Number of hundredth of second per inhalation.
void printDebugValues()
Print debug values, used to tweak PID, and triggers.
void inhale()
Perform the pressure control and compute the actuators commands during the inhalation phase.
uint16_t position
Current aperture.
@ EXHALATION
Exhalation and pause.
Definition: cycle.h:18
#define MAIN_CONTROLLER_COMPUTE_PERIOD_MS
Definition: parameters.h:28
PressureValve inspiratoryValve
PressureValve expiratoryValve
void sendDataSnapshot(uint16_t centileValue, int16_t pressureValue, CyclePhases phase, uint8_t blowerValvePosition, uint8_t patientValvePosition, uint8_t blowerRpm, uint8_t batteryLevel, int16_t inspiratoryFlowValue, int16_t expiratoryFlowValue)
Send a "data snapshot" message.
Definition: telemetry.cpp:481

◆ computeTickParameters()

void MainController::computeTickParameters ( )
private

Compute various cycle durations given the desired number of cycles per minute.

  • duration of a cycle in hundredth of second
  • duration of the inhalation phase in hundredth of second

    Note
    Inhalation lasts 1/3 of a cycle while exhalation lasts 2/3 of a cycle

Definition at line 501 of file main_controller.cpp.

501  {
503 
508 }
uint16_t m_ticksPerCycle
Number of hundredth of second per cycle.

◆ currentDeliveredVolume()

int32_t MainController::currentDeliveredVolume ( ) const
inline

Get the measured Tidal Volume. Updated in real time.

Definition at line 343 of file main_controller.h.

343 { return m_currentDeliveredVolume; }

◆ cycleNumber()

uint32_t MainController::cycleNumber ( ) const
inline

Get the number of past cycles since the beginning.

Definition at line 346 of file main_controller.h.

346 { return m_cycleNb; }

◆ cyclesPerMinuteCommand()

uint16_t MainController::cyclesPerMinuteCommand ( ) const
inline

Get the desired number of cycles per minute.

Definition at line 261 of file main_controller.h.

261 { return m_cyclesPerMinuteCommand; }

◆ cyclesPerMinuteMeasure()

uint16_t MainController::cyclesPerMinuteMeasure ( ) const
inline

Get the desired number of cycles per minute.

Definition at line 339 of file main_controller.h.

339 { return m_cyclesPerMinuteMeasure; }

◆ cyclesPerMinuteNextCommand()

uint16_t MainController::cyclesPerMinuteNextCommand ( ) const
inline

Get the desired number of cycles per minute for the next cycle.

Definition at line 298 of file main_controller.h.

◆ dt()

int32_t MainController::dt ( ) const
inline

Get the delta of time since the last cycle (in ms)

Definition at line 369 of file main_controller.h.

369 { return m_dt; }

◆ endRespiratoryCycle()

void MainController::endRespiratoryCycle ( uint32_t  p_currentMillis)

End a respiratory cycle.

Definition at line 372 of file main_controller.cpp.

372  {
373  // Compute the respiratory rate: average on NUMBER_OF_BREATH_PERIOD breaths
374  uint32_t currentMillis = p_currentMillis;
376  currentMillis - m_lastEndOfRespirationDateMs;
380  }
381  uint32_t sum = 0;
382  for (uint8_t i = 0u; i < NUMBER_OF_BREATH_PERIOD; i++) {
383  sum += m_lastBreathPeriodsMs[i];
384  }
385  // Add "+(sum-1u)" to round instead of truncate
386  m_cyclesPerMinuteMeasure = (((NUMBER_OF_BREATH_PERIOD * 60u) * 1000u) + (sum - 1u)) / sum;
387  m_lastEndOfRespirationDateMs = currentMillis;
388 
389  // Plateau pressure is the mean pressure during plateau
390  m_plateauPressureMeasure = max(0, static_cast<int16_t>(m_PlateauMeasureSum)
391  / static_cast<int16_t>(m_PlateauMeasureCount));
392 
393  checkCycleAlarm();
394 
396 
397  // Send telemetry machine state snapshot message
399 
401 }
void checkCycleAlarm()
At the end of a respiratory cycle, check if some alarms are triggered.
void sendMachineState()
Send a "machine state snapshot" telemetry message.
virtual void endCycle()=0
End the current breathing cycle.

◆ executeCommands()

void MainController::executeCommands ( )
private

Send the computed commands to actuators.

Definition at line 510 of file main_controller.cpp.

510  {
511  if (m_pressure
518  m_pressure);
519  } else {
521  }
522 
525  blower.execute();
526 }
#define RCM_SW_18
void execute()
Definition: blower.cpp:55
void execute()
Command the valve to go to the requested aperture.
void open()
Request opening of the Pressure Valve.
void close()
Request closing of the Pressure Valve.
#define AIR_EXHAUST_THRESHOLD_FROM_PEAK_PRESSURE_ALARM
Definition: parameters.h:115

◆ exhale()

void MainController::exhale ( )
private

Perform the pressure control and compute the actuators commands during the exhalation phase.

Definition at line 346 of file main_controller.cpp.

346  {
347  // Control loop
349 
350  // Compute the PEEP pressure
351  int16_t minValue = m_lastPressureValues[0u];
352  int16_t maxValue = m_lastPressureValues[0u];
353  int16_t totalValues = m_lastPressureValues[0u];
354  for (uint8_t index = 1u; index < MAX_PRESSURE_SAMPLES; index++) {
355  minValue = min(minValue, m_lastPressureValues[index]);
356  maxValue = max(maxValue, m_lastPressureValues[index]);
357  totalValues += m_lastPressureValues[index];
358  }
359 
360  // Update PEEP value, when pressure is stable and close to target pressure
361  if (((maxValue - minValue) < 5) && (abs(m_pressure - m_peepCommand) < 30)) {
362  m_isPeepDetected = true;
363  m_peepMeasure = max(0, totalValues / static_cast<int16_t>(MAX_PRESSURE_SAMPLES));
364  }
365 
366  // This case is usefull when PEEP is never detected during the cycle
367  if (!m_isPeepDetected) {
368  m_peepMeasure = max(static_cast<int16_t>(0), m_pressure);
369  }
370 }
virtual void exhale()=0
Control the exhalation.

◆ expiratoryFlow()

int32_t MainController::expiratoryFlow ( ) const
inline

Get the current expiratoryFlow.

Definition at line 366 of file main_controller.h.

366 { return m_expiratoryFlow; }

◆ expiratoryTriggerFlowCommand()

const int16_t MainController::expiratoryTriggerFlowCommand ( ) const
inline

Get the value of the expiratory trigger flow command.

Definition at line 273 of file main_controller.h.

273  {
275  }

◆ expiratoryTriggerFlowNextCommand()

const int16_t MainController::expiratoryTriggerFlowNextCommand ( ) const
inline

Get the value of the expiratory trigger flow command for the next cycle.

Definition at line 310 of file main_controller.h.

310  {
312  }

◆ inhale()

void MainController::inhale ( )
private

Perform the pressure control and compute the actuators commands during the inhalation phase.

Definition at line 325 of file main_controller.cpp.

325  {
326  // Control loop
328 
329  // Update peak pressure and rebounce peak pressure
331  m_peakPressureMeasure = max((int16_t)0, m_pressure);
335  } else {
336  // Do nothing
337  }
338 
339  // Compute plateau at the end of the cycle
342  m_PlateauMeasureCount += 1u;
343  }
344 }
virtual void inhale()=0
Control the inhalation.

◆ initRespiratoryCycle()

void MainController::initRespiratoryCycle ( )

Begin a respiratory cycle.

Definition at line 175 of file main_controller.cpp.

175  {
176  m_expiratoryVolume = 0;
177  DBG_DO(Serial.println("Init respiratory cycle");)
178  m_cycleNb++;
180 
182  m_triggered = false;
183  m_isPeepDetected = false;
184  m_tidalVolumeAlreadyRead = false;
185 
186  // Update new settings at the beginning of the respiratory cycle
201 
206 
211 
214 
217 
220 
221  // Run setup of the controller only if different from previous cycle
226  }
227 
229 
230  for (uint8_t i = 0u; i < MAX_PRESSURE_SAMPLES; i++) {
231  m_lastPressureValues[i] = 0;
232  }
234 
235  m_sumOfPressures = 0u;
236  m_numberOfPressures = 0u;
237 
238  m_PlateauMeasureSum = 0u;
240 
244 
246 }
void updateEnabledAlarms(Alarms enabledAlarms)
Update the list of enabled alarms (alarms not provided here will have no effects)
virtual struct Alarms enabledAlarms() const =0
List of alarms that must be enabled for this mode.
virtual void initCycle()=0
Begin a new breathing cycle.
virtual void setup()=0
Initialize controller.
#define DBG_DO(statement)
Expand arbitrary code only when in debug mode.
Definition: debug.h:24

◆ inspiratoryDurationCommand()

const int16_t MainController::inspiratoryDurationCommand ( ) const
inline

Get duration of inspiration command.

Definition at line 285 of file main_controller.h.

◆ inspiratoryDurationNextCommand()

const int16_t MainController::inspiratoryDurationNextCommand ( ) const
inline

Get duration of inspiration command fo next cycle.

Definition at line 322 of file main_controller.h.

322  {
324  }

◆ inspiratoryFlow()

int32_t MainController::inspiratoryFlow ( ) const
inline

Get the current inspiratoryFlow.

Definition at line 363 of file main_controller.h.

363 { return m_inspiratoryFlow; }

◆ inspiratoryTriggerFlowCommand()

const int16_t MainController::inspiratoryTriggerFlowCommand ( ) const
inline

Get the value of the inspiratory trigger flow command.

Definition at line 269 of file main_controller.h.

269  {
271  }

◆ inspiratoryTriggerFlowNextCommand()

const int16_t MainController::inspiratoryTriggerFlowNextCommand ( ) const
inline

Get the value of the inspiratory trigger flow command for the next cycle.

Definition at line 306 of file main_controller.h.

306  {
308  }

◆ isPeepDetected()

const bool MainController::isPeepDetected ( )
inline

Get if the PEEP has been detected during this cycle.

Definition at line 387 of file main_controller.h.

387 { return m_isPeepDetected; }

◆ lastPressureValues()

int16_t* MainController::lastPressureValues ( )
inline

Get last pressure values.

Definition at line 390 of file main_controller.h.

390 { return m_lastPressureValues; }

◆ lastPressureValuesIndex()

uint16_t MainController::lastPressureValuesIndex ( )
inline

Get last pressure values index.

Definition at line 393 of file main_controller.h.

393 { return m_lastPressureValuesIndex; }

◆ onCycleDecrease()

void MainController::onCycleDecrease ( )

Decrease the desired number of cycles per minute.

Definition at line 754 of file main_controller.cpp.

754  {
755  DBG_DO(Serial.println("Cycle --");)
756 
758 
761  }
762  // Send acknowledgment to the UI
764 }
#define CONST_MIN_CYCLE
Definition: parameters.h:119
void sendControlAck(uint8_t setting, uint16_t valueValue)
Send a "control ack" message.
Definition: telemetry.cpp:1109

◆ onCycleIncrease()

void MainController::onCycleIncrease ( )

Increase the desired number of cycles per minute.

Definition at line 766 of file main_controller.cpp.

766  {
767  DBG_DO(Serial.println("Cycle ++");)
768 
770 
773  }
774 
775  // Send acknowledgment to the UI
777 }
#define CONST_MAX_CYCLE
Definition: parameters.h:118

◆ onCycleSet()

void MainController::onCycleSet ( uint16_t  p_cpm)

Set the desired number of cycles per minute.

Parameters
p_cpmDesired number of cycles per minute

Definition at line 780 of file main_controller.cpp.

780  {
781  if (p_cpm < CONST_MIN_CYCLE) {
783  } else if (p_cpm > CONST_MAX_CYCLE) {
785  } else {
787  }
788 
789  // Send acknowledgment to the UI
791 }

◆ onExpiratoryTermSet()

void MainController::onExpiratoryTermSet ( uint16_t  p_expiratoryTerm)

Set the desired expiratory term.

Parameters
p_expiratoryTermExpiration term in the "Inspiration/Expiration" ratio given that Inspiration = 10

Definition at line 936 of file main_controller.cpp.

936  {
937  if (p_expiratoryTerm > CONST_MAX_EXPIRATORY_TERM) {
939  } else if (p_expiratoryTerm < CONST_MIN_EXPIRATORY_TERM) {
941  } else {
942  m_expiratoryTermNextCommand = p_expiratoryTerm;
943  }
944 
945  // Send acknowledgment to the UI
947 }
#define CONST_MAX_EXPIRATORY_TERM
Definition: parameters.h:86
#define CONST_MIN_EXPIRATORY_TERM
Definition: parameters.h:85

◆ onExpiratoryTriggerFlowSet()

void MainController::onExpiratoryTriggerFlowSet ( uint16_t  p_expiratoryTriggerFlow)

Set expiratory trigger flow.

Definition at line 987 of file main_controller.cpp.

987  {
988  // CONST_MIN_EXPIRATORY_TRIGGER_FLOW might not be equal to 0
989  // cppcheck-suppress unsignedPositive
990  if ((p_expiratoryTriggerFlow >= CONST_MIN_EXPIRATORY_TRIGGER_FLOW)
991  && (p_expiratoryTriggerFlow <= CONST_MAX_EXPIRATORY_TRIGGER_FLOW)) {
992  m_expiratoryTriggerFlowNextCommand = p_expiratoryTriggerFlow;
993  }
994 
995  // Send acknowledgment to the UI
997 }
#define CONST_MIN_EXPIRATORY_TRIGGER_FLOW
Definition: parameters.h:48
#define CONST_MAX_EXPIRATORY_TRIGGER_FLOW
Definition: parameters.h:47

◆ onHighExpiratoryMinuteVolumeAlarmThresholdSet()

void MainController::onHighExpiratoryMinuteVolumeAlarmThresholdSet ( uint16_t  p_highExpiratoryMinuteVolumeAlarmThreshold)

Set alarm threshold for high expiratory minute volume.

Definition at line 1073 of file main_controller.cpp.

1074  {
1075  if ((p_highExpiratoryMinuteVolumeAlarmThreshold
1077  && (p_highExpiratoryMinuteVolumeAlarmThreshold
1080  1000 * (int32_t)p_highExpiratoryMinuteVolumeAlarmThreshold;
1081  }
1082 
1083  // Send acknowledgment to the UI
1085 }
#define CONST_MAX_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:66
#define CONST_MIN_HIGH_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:65

◆ onHighInspiratoryMinuteVolumeAlarmThresholdSet()

void MainController::onHighInspiratoryMinuteVolumeAlarmThresholdSet ( uint16_t  p_highInspiratoryMinuteVolumeAlarmThreshold)

Set alarm threshold for high inspiratory minute volume.

Definition at line 1040 of file main_controller.cpp.

1041  {
1042  if ((p_highInspiratoryMinuteVolumeAlarmThreshold
1044  && (p_highInspiratoryMinuteVolumeAlarmThreshold
1047  1000 * (int32_t)p_highInspiratoryMinuteVolumeAlarmThreshold;
1048  }
1049 
1050  // Send acknowledgment to the UI
1052 }
#define CONST_MIN_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:63
#define CONST_MAX_HIGH_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:64

◆ onhighRespiratoryRateAlarmThresholdSet()

void MainController::onhighRespiratoryRateAlarmThresholdSet ( uint16_t  p_highRespiratoryRateAlarmThreshold)

Set alarm threshold for high respiratory rate.

Definition at line 1100 of file main_controller.cpp.

1101  {
1102  if ((p_highRespiratoryRateAlarmThreshold >= CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD)
1103  && (p_highRespiratoryRateAlarmThreshold
1105  m_highRespiratoryRateAlarmThresholdNextCommand = p_highRespiratoryRateAlarmThreshold;
1106  }
1107 
1108  // Send acknowledgment to the UI
1110 }
#define CONST_MIN_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:69
#define CONST_MAX_HIGH_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:70

◆ onHighTidalVolumeAlarmThresholdSet()

void MainController::onHighTidalVolumeAlarmThresholdSet ( uint16_t  p_highTidalVolumeAlarmThreshold)

Set threshold on tidal volume for which an alarm is raised.

Definition at line 1136 of file main_controller.cpp.

1136  {
1137  if ((p_highTidalVolumeAlarmThreshold >= CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD)
1138  && (p_highTidalVolumeAlarmThreshold <= CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD)) {
1139  m_highTidalVolumeAlarmThresholdNextCommand = p_highTidalVolumeAlarmThreshold;
1140  }
1141 
1142  // Send acknowledgment to the UI
1144 }
#define CONST_MIN_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:73
#define CONST_MAX_HIGH_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:74

◆ onInspiratoryDuration()

void MainController::onInspiratoryDuration ( uint16_t  p_inspiratoryDuration)

Set the inspiration duration.

Definition at line 1183 of file main_controller.cpp.

1183  {
1184  if ((p_inspiratoryDuration >= CONST_MIN_INSPIRATORY_DURATION)
1185  && (p_inspiratoryDuration <= CONST_MAX_INSPIRATORY_DURATION)) {
1186  m_inspiratoryDurationNextCommand = p_inspiratoryDuration;
1187  }
1188 
1189  // Send acknowledgment to the UI
1191 }
#define CONST_MAX_INSPIRATORY_DURATION
Definition: parameters.h:58
#define CONST_MIN_INSPIRATORY_DURATION
Definition: parameters.h:57

◆ onInspiratoryTriggerFlowSet()

void MainController::onInspiratoryTriggerFlowSet ( uint16_t  p_inspiratoryTriggerFlow)

Set inspiratory trigger flow.

Definition at line 974 of file main_controller.cpp.

974  {
975  // CONST_MIN_INSPIRATORY_TRIGGER_FLOW might not be equal to 0
976  // cppcheck-suppress unsignedPositive
977  if ((p_inspiratoryTriggerFlow >= CONST_MIN_INSPIRATORY_TRIGGER_FLOW)
978  && (p_inspiratoryTriggerFlow <= CONST_MAX_INSPIRATORY_TRIGGER_FLOW)) {
979  m_inspiratoryTriggerFlowNextCommand = p_inspiratoryTriggerFlow;
980  }
981 
982  // Send acknowledgment to the UI
984 }
#define CONST_MAX_INSPIRATORY_TRIGGER_FLOW
Definition: parameters.h:45
#define CONST_MIN_INSPIRATORY_TRIGGER_FLOW
Definition: parameters.h:46

◆ onLeakAlarmThresholdSet()

void MainController::onLeakAlarmThresholdSet ( uint16_t  p_leakAlarmThreshold)

Set the threshold for leak that raise the alarm.

Definition at line 1160 of file main_controller.cpp.

1160  {
1161  if ((p_leakAlarmThreshold >= CONST_MIN_LEAK_ALARM_THRESHOLD)
1162  && (p_leakAlarmThreshold <= CONST_MIN_LEAK_ALARM_THRESHOLD)) {
1163  m_leakAlarmThresholdNextCommand = 10u * p_leakAlarmThreshold;
1164  }
1165 
1166  // Send acknowledgment to the UI
1168 }
#define CONST_MIN_LEAK_ALARM_THRESHOLD
Definition: parameters.h:76

◆ onLowExpiratoryMinuteVolumeAlarmThresholdSet()

void MainController::onLowExpiratoryMinuteVolumeAlarmThresholdSet ( uint16_t  p_lowExpiratoryMinuteVolumeAlarmThreshold)

Set alarm threshold for low expiratory minute volume.

Definition at line 1055 of file main_controller.cpp.

1056  {
1057  // CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD might not be equal to 0
1058  if ((p_lowExpiratoryMinuteVolumeAlarmThreshold
1059  // cppcheck-suppress unsignedPositive ;
1061  && (p_lowExpiratoryMinuteVolumeAlarmThreshold
1064  // cppcheck-suppress cert-INT31-c ;
1065  1000 * (int32_t)p_lowExpiratoryMinuteVolumeAlarmThreshold;
1066  }
1067 
1068  // Send acknowledgment to the UI
1070 }
#define CONST_MIN_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:61
#define CONST_MAX_LOW_EXPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:62

◆ onLowInspiratoryMinuteVolumeAlarmThresholdSet()

void MainController::onLowInspiratoryMinuteVolumeAlarmThresholdSet ( uint16_t  p_lowInspiratoryMinuteVolumeAlarmThreshold)

Set alarm threshold for low inspiratory minute volume.

Definition at line 1022 of file main_controller.cpp.

1023  {
1024  // CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD might not be equal to 0
1025  if ((p_lowInspiratoryMinuteVolumeAlarmThreshold
1026  // cppcheck-suppress unsignedPositive ;
1028  && (p_lowInspiratoryMinuteVolumeAlarmThreshold
1031  // cppcheck-suppress cert-INT31-c ;
1032  1000 * (int32_t)p_lowInspiratoryMinuteVolumeAlarmThreshold;
1033  }
1034 
1035  // Send acknowledgment to the UI
1037 }
#define CONST_MAX_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:60
#define CONST_MIN_LOW_INSPIRATORY_MINUTE_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:59

◆ onlowRespiratoryRateAlarmThresholdSet()

void MainController::onlowRespiratoryRateAlarmThresholdSet ( uint16_t  p_lowRespiratoryRateAlarmThreshold)

Set alarm threshold for low respiratory rate.

Definition at line 1088 of file main_controller.cpp.

1089  {
1090  if ((p_lowRespiratoryRateAlarmThreshold >= CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD)
1091  && (p_lowRespiratoryRateAlarmThreshold <= CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD)) {
1092  m_lowRespiratoryRateAlarmThresholdNextCommand = p_lowRespiratoryRateAlarmThreshold;
1093  }
1094 
1095  // Send acknowledgment to the UI
1097 }
#define CONST_MIN_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:67
#define CONST_MAX_LOW_RESPIRATORY_RATE_ALARM_THRESHOLD
Definition: parameters.h:68

◆ onLowTidalVolumeAlarmThresholdSet()

void MainController::onLowTidalVolumeAlarmThresholdSet ( uint16_t  p_lowTidalVolumeAlarmThreshold)

Set threshold on tidal volume below which an alarm is raised.

Definition at line 1123 of file main_controller.cpp.

1123  {
1124  // CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD might not be equal to 0
1125  // cppcheck-suppress unsignedPositive ;
1126  if ((p_lowTidalVolumeAlarmThreshold >= CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD)
1127  && (p_lowTidalVolumeAlarmThreshold <= CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD)) {
1128  m_lowTidalVolumeAlarmThresholdNextCommand = p_lowTidalVolumeAlarmThreshold;
1129  }
1130 
1131  // Send acknowledgment to the UI
1133 }
#define CONST_MAX_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:72
#define CONST_MIN_LOW_TIDAL_VOLUME_ALARM_THRESHOLD
Definition: parameters.h:71

◆ onPatientComputePreset()

void MainController::onPatientComputePreset ( )

Updates patient computed params.

Definition at line 1235 of file main_controller.cpp.

1235  {
1236  int32_t theoricalWeight = 0;
1237  int32_t tidalVolume = 0;
1238 
1239  // Male
1240  if (m_patientGender == 0) {
1241  theoricalWeight = 23 * (m_patientHeight * m_patientHeight) / 10000;
1242  } else {
1243  theoricalWeight = 21 * (m_patientHeight * m_patientHeight) / 10000;
1244  }
1245 
1246  tidalVolume = theoricalWeight * 7;
1247 
1248  tidalVolume = tidalVolume - (tidalVolume % 10);
1249 
1250  m_tidalVolumeNextCommand = tidalVolume;
1251  m_peepNextCommand = 50u;
1253  m_plateauPressureNextCommand = m_peepNextCommand + ((172 * tidalVolume) / 1000);
1254 
1256  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) - 1500;
1258  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) + 1500;
1260  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) - 1500;
1262  (static_cast<int32_t>(m_cyclesPerMinuteCommand) * tidalVolume) + 1500;
1265  m_lowTidalVolumeAlarmThresholdNextCommand = tidalVolume - 100;
1266  m_highTidalVolumeAlarmThresholdNextCommand = tidalVolume + 100;
1269 }
#define PEAK_PRESSURE_ALARM_THRESHOLD_OFFSET_FROM_PLATEAU
Definition: parameters.h:114

◆ onPatientGender()

void MainController::onPatientGender ( int16_t  p_patientGender)

Set the desired patient gender.

Parameters
p_patientGenderpatient gender 0 = male, 1 = female

Definition at line 1220 of file main_controller.cpp.

1220  {
1221  if ((p_patientGender >= CONST_MIN_PATIENT_GENDER)
1222  && (p_patientGender <= CONST_MAX_PATIENT_GENDER)) {
1223  m_patientGender = p_patientGender;
1224  } else {
1226  }
1227 
1228  // Send acknowledgment to the UI
1230 
1232 }
void onPatientComputePreset()
Updates patient computed params.
MainController mainController
#define CONST_MIN_PATIENT_GENDER
Definition: parameters.h:81
#define DEFAULT_PATIENT_GENDER
Definition: parameters.h:112
#define CONST_MAX_PATIENT_GENDER
Definition: parameters.h:82

◆ onPatientHeight()

void MainController::onPatientHeight ( int16_t  p_patientHeight)

Set the desired patient height.

Parameters
p_patientHeightDesired patient height in cm

Definition at line 1205 of file main_controller.cpp.

1205  {
1206  if ((p_patientHeight >= CONST_MIN_PATIENT_HEIGHT)
1207  && (p_patientHeight <= CONST_MAX_PATIENT_HEIGHT)) {
1208  m_patientHeight = p_patientHeight;
1209  } else {
1211  }
1212 
1213  // Send acknowledgment to the UI
1215 
1217 }
#define CONST_MAX_PATIENT_HEIGHT
Definition: parameters.h:80
#define CONST_MIN_PATIENT_HEIGHT
Definition: parameters.h:79
#define DEFAULT_PATIENT_HEIGHT
Definition: parameters.h:111

◆ onPeakPressureAlarmThreshold()

void MainController::onPeakPressureAlarmThreshold ( int16_t  p_peakPressureAlarmThreshold)

Set the desired threshold for max peak pressure.

Parameters
p_peakPressureAlarmThresholdDesired threshold in mmH2O

Definition at line 1194 of file main_controller.cpp.

1194  {
1195  if ((p_peakPressureAlarmThreshold >= CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD)
1196  && (p_peakPressureAlarmThreshold <= CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD)) {
1197  m_peakPressureAlarmThresholdNextCommand = p_peakPressureAlarmThreshold;
1198  }
1199 
1200  // Send acknowledgment to the UI
1202 }
#define CONST_MIN_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:77
#define CONST_MAX_PEAK_PRESSURE_ALARM_THRESHOLD
Definition: parameters.h:78

◆ onPeakPressureDecrease()

void MainController::onPeakPressureDecrease ( )

Decrease the desired peak pressure.

Deprecated:
Peak pressure is now based on plateau pressure

Definition at line 885 of file main_controller.cpp.

885  {
886  DBG_DO(Serial.println("Peak Pressure --");)
887 #if DEBUG != 0
888  switch (m_ventilationControllerMode) {
889  case PC_CMV:
891  break;
892  case PC_AC:
894  break;
895  case VC_CMV:
897  break;
898  case PC_VSAI:
900  break;
901  default:
902  // Do nothing
903  break;
904  }
906 
907 #endif
908 }

◆ onPeakPressureIncrease()

void MainController::onPeakPressureIncrease ( )

Increase the desired peak pressure.

Deprecated:
Peak pressure is now based on plateau pressure

Definition at line 910 of file main_controller.cpp.

910  {
911  DBG_DO(Serial.println("Peak Pressure ++");)
912 #if DEBUG != 0
913  switch (m_ventilationControllerMode) {
914  case PC_CMV:
916  break;
917  case PC_AC:
919  break;
920  case VC_CMV:
922  break;
923  case PC_VSAI:
925  break;
926  default:
927  // Do nothing
928  break;
929  }
931 
932 #endif
933 }

◆ onPeepPressureDecrease()

void MainController::onPeepPressureDecrease ( )

Decrease the minimal PEEP desired.

Definition at line 793 of file main_controller.cpp.

793  {
794  DBG_DO(Serial.println("Peep Pressure --");)
795 
796  if (m_peepNextCommand >= 10) {
798  } else {
799  // Do nothing
800  }
801 
802  // Send acknowledgment to the UI
804 }

◆ onPeepPressureIncrease()

void MainController::onPeepPressureIncrease ( )

Increase the minimal PEEP desired.

Definition at line 806 of file main_controller.cpp.

806  {
807  DBG_DO(Serial.println("Peep Pressure ++");)
808 
809  // Peep target should be lower than plateau target
812  }
813 
816  }
817 
818  // Send acknowledgment to the UI
820 }
#define CONST_MAX_PEEP_PRESSURE
Definition: parameters.h:37

◆ onPeepSet()

void MainController::onPeepSet ( int16_t  p_peep)

Set the desired PEEP.

Parameters
p_peepDesired PEEP in mmH2O

Definition at line 823 of file main_controller.cpp.

823  {
824  if (p_peep > CONST_MAX_PEEP_PRESSURE) {
826  // cppcheck-suppress unsignedLessThanZero ; CONST_MIN_PEEP_PRESSURE might not be equal to 0
827  } else if (p_peep < CONST_MIN_PEEP_PRESSURE) {
829  } else {
830  m_peepNextCommand = p_peep;
831  }
832 
833  // Send acknowledgment to the UI
835 }
#define CONST_MIN_PEEP_PRESSURE
Definition: parameters.h:38

◆ onPlateauDurationSet()

void MainController::onPlateauDurationSet ( uint16_t  p_plateauDuration)

Set the duration of Pause at the end of expiration in VC modes.

Definition at line 1147 of file main_controller.cpp.

1147  {
1148  // CONST_MIN_PLATEAU_DURATION might not be equal to 0
1149  // cppcheck-suppress unsignedPositive ;
1150  if ((p_plateauDuration >= CONST_MIN_PLATEAU_DURATION)
1151  && (p_plateauDuration <= CONST_MAX_PLATEAU_DURATION)) {
1152  m_plateauDurationNextCommand = p_plateauDuration;
1153  }
1154 
1155  // Send acknowledgment to the UI
1157 }
#define CONST_MAX_PLATEAU_DURATION
Definition: parameters.h:54
#define CONST_MIN_PLATEAU_DURATION
Definition: parameters.h:53

◆ onPlateauPressureDecrease()

void MainController::onPlateauPressureDecrease ( )

Decrease the desired plateau pressure.

Definition at line 837 of file main_controller.cpp.

837  {
838  DBG_DO(Serial.println("Plateau Pressure --");)
839 
842  }
843 
846  }
847 
850 
851  // Send acknowledgment to the UI
853 }
#define CONST_MIN_PLATEAU_PRESSURE
Definition: parameters.h:36

◆ onPlateauPressureIncrease()

void MainController::onPlateauPressureIncrease ( )

Increase the desired plateau pressure.

Definition at line 855 of file main_controller.cpp.

855  {
856  DBG_DO(Serial.println("Plateau Pressure ++");)
857 
859 
861  min(m_plateauPressureNextCommand, static_cast<int16_t>(CONST_MAX_PLATEAU_PRESSURE));
864 
865  // Send acknowledgment to the UI
867 }
#define CONST_MAX_PLATEAU_PRESSURE
Definition: parameters.h:35

◆ onPlateauPressureSet()

void MainController::onPlateauPressureSet ( int16_t  p_plateauPressure)

Set the desired plateau pressure.

Parameters
p_plateauPressureDesired plateau pressure in mmH2O

Definition at line 870 of file main_controller.cpp.

870  {
871  if (p_plateauPressure > CONST_MAX_PLATEAU_PRESSURE) {
873  } else if (p_plateauPressure < CONST_MIN_PLATEAU_PRESSURE) {
875  } else {
876  m_plateauPressureNextCommand = p_plateauPressure;
877  }
880 
881  // Send acknowledgment to the UI
883 }

◆ onTargetInspiratoryFlow()

void MainController::onTargetInspiratoryFlow ( uint16_t  p_targetInspiratoryFlow)

Set the inspiratory flow target.

Definition at line 1171 of file main_controller.cpp.

1171  {
1172  int32_t temporaryValue = static_cast<int32_t>(p_targetInspiratoryFlow) * 1000;
1173  if ((temporaryValue >= CONST_MIN_INSPIRATORY_FLOW)
1174  && (temporaryValue <= CONST_MAX_INSPIRATORY_FLOW)) {
1175  m_targetInspiratoryFlowNextCommand = temporaryValue;
1176  }
1177 
1178  // Send acknowledgment to the UI
1179  sendControlAck(25, static_cast<uint16_t>(m_targetInspiratoryFlowNextCommand / 1000));
1180 }
#define CONST_MIN_INSPIRATORY_FLOW
Definition: parameters.h:55
#define CONST_MAX_INSPIRATORY_FLOW
Definition: parameters.h:56

◆ onTargetTidalVolumeSet()

void MainController::onTargetTidalVolumeSet ( uint16_t  p_targetTidalVolume)

Set target tidal volume (used in VC modes)

Definition at line 1113 of file main_controller.cpp.

1113  {
1114  if ((p_targetTidalVolume >= CONST_MIN_TIDAL_VOLUME)
1115  && (p_targetTidalVolume <= CONST_MAX_TIDAL_VOLUME)) {
1116  m_tidalVolumeNextCommand = p_targetTidalVolume;
1117  }
1118  // Send acknowledgment to the UI
1120 }
#define CONST_MIN_TIDAL_VOLUME
Definition: parameters.h:43
#define CONST_MAX_TIDAL_VOLUME
Definition: parameters.h:44

◆ onTiMaxSet()

void MainController::onTiMaxSet ( uint16_t  p_tiMax)

Set max inspiratory time.

Definition at line 1011 of file main_controller.cpp.

1011  {
1012  if ((p_tiMax >= CONST_MIN_MAX_INSPIRATION_DURATION)
1013  && (p_tiMax <= CONST_MAX_MAX_INSPIRATION_DURATION)) {
1014  m_tiMaxNextCommand = p_tiMax;
1015  }
1016 
1017  // Send acknowledgment to the UI
1019 }
#define CONST_MAX_MAX_INSPIRATION_DURATION
Definition: parameters.h:52
#define CONST_MIN_MAX_INSPIRATION_DURATION
Definition: parameters.h:51

◆ onTiMinSet()

void MainController::onTiMinSet ( uint16_t  p_tiMin)

Set min inspiratory time.

Definition at line 1000 of file main_controller.cpp.

1000  {
1001  if ((p_tiMin >= CONST_MIN_MIN_INSPIRATION_DURATION)
1002  && (p_tiMin <= CONST_MAX_MIN_INSPIRATION_DURATION)) {
1003  m_tiMinNextCommand = p_tiMin;
1004  }
1005 
1006  // Send acknowledgment to the UI
1008 }
#define CONST_MIN_MIN_INSPIRATION_DURATION
Definition: parameters.h:49
#define CONST_MAX_MIN_INSPIRATION_DURATION
Definition: parameters.h:50

◆ onTriggerModeEnabledSet()

void MainController::onTriggerModeEnabledSet ( uint16_t  p_triggerEnabled)

Enable or disable expiratory trigger mode.

Parameters
p_triggerEnabled0: disable trigger mode, 1: enable trigger mode

Definition at line 950 of file main_controller.cpp.

950  {
951  if ((p_triggerEnabled == 0u) || (p_triggerEnabled == 1u)) {
952  m_triggerModeEnabledNextCommand = p_triggerEnabled;
953  }
954  // Send acknowledgment to the UI
956 }

◆ onTriggerOffsetSet()

void MainController::onTriggerOffsetSet ( uint16_t  p_triggerOffset)

Set the desired offset for expiratory trigger.

Parameters
p_triggerOffsetDesired trigger offset in mmH2O

Definition at line 959 of file main_controller.cpp.

959  {
960  if (p_triggerOffset > CONST_MAX_TRIGGER_OFFSET) {
962  // cppcheck-suppress unsignedLessThanZero
963  } else if (p_triggerOffset < CONST_MIN_TRIGGER_OFFSET) {
965  } else {
966  m_pressureTriggerOffsetNextCommand = p_triggerOffset;
967  }
968 
969  // Send acknowledgment to the UI
971 }
#define CONST_MAX_TRIGGER_OFFSET
Definition: parameters.h:40
#define CONST_MIN_TRIGGER_OFFSET
Definition: parameters.h:39

◆ onVentilationModeSet()

void MainController::onVentilationModeSet ( uint16_t  p_ventilationControllerMode)

Set ventilation mode.

Definition at line 741 of file main_controller.cpp.

741  {
742  // cppcheck-suppress misra-c2012-10.4
743  if ((m_ventilationControllerMode >= 1u)
744  // cppcheck-suppress misra-c2012-10.4
746  m_ventilationControllerMode = static_cast<VentilationModes>(p_ventilationControllerMode);
749  }
750  // Send acknowledgment to the UI
752 }
VentilationModes
Supported ventilation modes.
Definition: cycle.h:22
#define NUMBER_OF_VENTILATION_MODES
Definition: cycle.h:9

◆ patientHeight()

int32_t MainController::patientHeight ( ) const
inline

Definition at line 249 of file main_controller.h.

249 { return m_patientHeight; }

◆ peakPressureCommand()

int16_t MainController::peakPressureCommand ( ) const
inline

Get the desired max peak.

Definition at line 255 of file main_controller.h.

255 { return m_peakPressureCommand; }

◆ peakPressureMeasure()

int16_t MainController::peakPressureMeasure ( ) const
inline

Get the measured peak pressure.

Definition at line 331 of file main_controller.h.

331 { return m_peakPressureMeasure; }

◆ peakPressureNextCommand()

int16_t MainController::peakPressureNextCommand ( ) const
inline

Get the desired max peak for the next cycle.

Definition at line 292 of file main_controller.h.

292 { return m_peakPressureNextCommand; }

◆ peepCommand()

int16_t MainController::peepCommand ( ) const
inline

Get the desired PEEP.

Definition at line 259 of file main_controller.h.

259 { return m_peepNextCommand; }

◆ peepMeasure()

int16_t MainController::peepMeasure ( ) const
inline

Get the measured PEEP.

Definition at line 337 of file main_controller.h.

337 { return m_peepMeasure; }

◆ peepNextCommand()

int16_t MainController::peepNextCommand ( ) const
inline

Get the desired PEEP for the next cycle.

Definition at line 296 of file main_controller.h.

296 { return m_peepNextCommand; }

◆ phase()

CyclePhases MainController::phase ( ) const
inline

Get the current cycle phase.

Definition at line 378 of file main_controller.h.

378 { return m_phase; }

◆ plateauDurationCommand()

int16_t MainController::plateauDurationCommand ( ) const
inline

Definition at line 253 of file main_controller.h.

253 { return m_plateauDurationCommand; }

◆ plateauDurationNextCommand()

int16_t MainController::plateauDurationNextCommand ( ) const
inline

Definition at line 290 of file main_controller.h.

◆ plateauPressureCommand()

int16_t MainController::plateauPressureCommand ( ) const
inline

Get the desired plateau pressure.

Definition at line 257 of file main_controller.h.

257 { return m_plateauPressureCommand; }

◆ plateauPressureMeasure()

int16_t MainController::plateauPressureMeasure ( ) const
inline

Get the measured plateau pressure.

Definition at line 335 of file main_controller.h.

335 { return m_plateauPressureMeasure; }

◆ plateauPressureNextCommand()

int16_t MainController::plateauPressureNextCommand ( ) const
inline

Get the desired plateau pressure for the next cycle.

Definition at line 294 of file main_controller.h.

◆ pressure()

int16_t MainController::pressure ( ) const
inline

Get the current measured pressure.

Definition at line 360 of file main_controller.h.

360 { return m_pressure; }

◆ pressureCommand()

int32_t MainController::pressureCommand ( ) const
inline

Get the pressure command.

Definition at line 375 of file main_controller.h.

375 { return m_pressureCommand; }

◆ pressureTriggerOffsetCommand()

const int16_t MainController::pressureTriggerOffsetCommand ( ) const
inline

Get the value of the inspiratory trigger pressure command.

Definition at line 263 of file main_controller.h.

263  {
265  }

◆ pressureTriggerOffsetNextCommand()

const int16_t MainController::pressureTriggerOffsetNextCommand ( ) const
inline

Get the value of the inspiratory trigger pressure command for the next cycle.

Definition at line 300 of file main_controller.h.

300  {
302  }

◆ printDebugValues()

void MainController::printDebugValues ( )
private

Print debug values, used to tweak PID, and triggers.

Definition at line 403 of file main_controller.cpp.

403  {
404 #if DEBUG == 2
405  Serial.print(m_pressure);
406  Serial.print(",");
407  Serial.print(m_pressureCommand);
408  Serial.print(",");
409  Serial.print(m_inspiratoryFlow / 100); // division by 100 for homogenous scale in debug
410  Serial.print(",");
411  Serial.print(m_expiratoryFlow / 100); // division by 100 for homogenous scale in debug
412  Serial.print(",");
413  Serial.print(inspiratoryValve.command);
414  Serial.print(",");
415  Serial.print(expiratoryValve.command);
416  Serial.print(",");
417  Serial.print(blower.getSpeed() / 10); // division by 10 for homogenous scale in debug
418  Serial.println();
419 #endif
420 }
uint16_t command
Value of the requested aperture.

◆ reachSafetyPosition()

void MainController::reachSafetyPosition ( )

Put actuators in safety position.

Definition at line 660 of file main_controller.cpp.

660  {
663  executeCommands();
664 }

◆ rebouncePeakPressureMeasure()

int16_t MainController::rebouncePeakPressureMeasure ( ) const
inline

Get the measured rebounce peak pressure.

Definition at line 333 of file main_controller.h.

◆ sendMachineState()

void MainController::sendMachineState ( )

Send a "machine state snapshot" telemetry message.

Definition at line 715 of file main_controller.cpp.

715  {
716  // Send the next command, because command has not been updated yet (will be at the beginning of
717  // the next cycle)
735  static_cast<uint8_t>(m_targetInspiratoryFlowNextCommand / 1000),
739 }
uint32_t getBatteryLevelX100()
Returns battery level x100 for better accuracy.
Definition: battery.cpp:129
bool isSnoozed() const
Check if alarms are currently snoozed.
uint8_t * triggeredAlarms()
Get the alarms triggered during this cycle.
uint8_t readCpuLoadPercent(void)
Get the value of the CPU load.
Definition: cpu_load.cpp:39
uint8_t mmH2OtoCmH2O(uint16_t pressure)
Convert and round a pressure in mmH2O to a pressure in cmH2O.
Definition: telemetry.cpp:1459
void sendMachineStateSnapshot(uint32_t cycleValue, uint8_t peakCommand, uint8_t plateauCommand, uint8_t peepCommand, uint8_t cpmCommand, uint16_t previousPeakPressureValue, uint16_t previousPlateauPressureValue, uint16_t previousPeepPressureValue, uint8_t currentAlarmCodes[ALARMS_SIZE], uint16_t volumeValue, uint8_t expiratoryTerm, bool triggerEnabled, uint8_t triggerOffset, uint8_t previouscpmValue, bool alarmSnoozed, uint8_t cpuLoad, VentilationModes ventilationMode, uint8_t inspiratoryTriggerFlow, uint8_t expiratoryTriggerFlow, uint16_t tiMinValue, uint16_t tiMaxValue, uint8_t lowInspiratoryMinuteVolumeAlarmThreshold, uint8_t highInspiratoryMinuteVolumeAlarmThreshold, uint8_t lowExpiratoryMinuteVolumeAlarmThreshold, uint8_t highExpiratoryMinuteVolumeAlarmThreshold, uint8_t lowRespiratoryRateAlarmThreshold, uint8_t highRespiratoryRateAlarmThreshold, uint16_t targetTidalVolumeValue, uint16_t lowTidalVolumeAlarmThresholdValue, uint16_t highTidalVolumeAlarmThresholdValue, uint16_t plateauDurationValue, uint16_t leakAlarmThresholdValue, uint8_t targetInspiratoryFlow, uint16_t inspiratoryDurationCommandValue, uint16_t previousInspiratoryDurationValue, uint16_t batteryLevelValue, uint16_t localeValue, uint8_t patientHeight, uint8_t patientGender, uint16_t peakPressureAlarmThresholdValue)
Send a "machine state snapshot" message.
Definition: telemetry.cpp:592

◆ sendStopMessageToUi()

void MainController::sendStopMessageToUi ( )

Send a "stopped" telemetry message.

Definition at line 666 of file main_controller.cpp.

666  {
681  static_cast<uint8_t>(m_targetInspiratoryFlowNextCommand / 1000),
684 }
void sendStoppedMessage(uint8_t peakCommand, uint8_t plateauCommand, uint8_t peepCommand, uint8_t cpmCommand, uint8_t expiratoryTerm, bool triggerEnabled, uint8_t triggerOffset, bool alarmSnoozed, uint8_t cpuLoad, VentilationModes ventilationMode, uint8_t inspiratoryTriggerFlow, uint8_t expiratoryTriggerFlow, uint16_t tiMinValue, uint16_t tiMaxValue, uint8_t lowInspiratoryMinuteVolumeAlarmThreshold, uint8_t highInspiratoryMinuteVolumeAlarmThreshold, uint8_t lowExpiratoryMinuteVolumeAlarmThreshold, uint8_t highExpiratoryMinuteVolumeAlarmThreshold, uint8_t lowRespiratoryRateAlarmThreshold, uint8_t highRespiratoryRateAlarmThreshold, uint16_t targetTidalVolumeValue, uint16_t lowTidalVolumeAlarmThresholdValue, uint16_t highTidalVolumeAlarmThresholdValue, uint16_t plateauDurationValue, uint16_t leakAlarmThresholdValue, uint8_t targetInspiratoryFlow, uint16_t inspiratoryDurationCommandValue, uint16_t batteryLevelValue, uint8_t currentAlarmCodes[ALARMS_SIZE], uint16_t localeValue, uint8_t patientHeight, uint8_t patientGender, uint16_t peakPressureAlarmThresholdValue)
Send a "stopped" message.
Definition: telemetry.cpp:164

◆ setTrigger()

const void MainController::setTrigger ( bool  triggerValue)
inline

Reset the trigger to false.

Definition at line 384 of file main_controller.h.

384 { m_triggered = triggerValue; }

◆ setup()

void MainController::setup ( )

Initialize actuators.

Definition at line 164 of file main_controller.cpp.

164  {
165  DBG_DO(Serial.println(VERSION);)
166  DBG_DO(Serial.println("Setup the controller");)
167 
169 
171 
172  alarmController.updateEnabledAlarms(m_ventilationController->enabledAlarms());
173 }
void setup()
Initialize actuators.
void reachSafetyPosition()
Put actuators in safety position.
#define VERSION
Current version of the software.
Definition: parameters.h:20

◆ stop()

void MainController::stop ( uint32_t  p_currentMillis)

Stop the breathing.

Definition at line 686 of file main_controller.cpp.

686  {
687  blower.stop();
689  // When stopped, open the valves
691  m_lastEndOfRespirationDateMs = p_currentMillis;
692 
693  // Stop alarms related to breathing cycle
712  digitalWrite(PIN_LED_START, LED_START_INACTIVE);
713 }
void stop()
Stops the blower.
Definition: blower.cpp:105
void sendStopMessageToUi()
Send a "stopped" telemetry message.
#define LED_START_INACTIVE
Definition: parameters.h:258
#define PIN_LED_START
Definition: parameters.h:252

◆ targetInspiratoryFlowCommand()

const int32_t MainController::targetInspiratoryFlowCommand ( ) const
inline

get target inspiratory flow in mL/min (used in VC modes)

Definition at line 281 of file main_controller.h.

281  {
283  }

◆ targetInspiratoryFlowNextCommand()

const int32_t MainController::targetInspiratoryFlowNextCommand ( ) const
inline

get target inspiratory flow in mL/min (used in VC modes) for next cycle

Definition at line 318 of file main_controller.h.

318  {
320  }

◆ tick()

uint32_t MainController::tick ( ) const
inline

Get the tick number of the current cycle.

Definition at line 372 of file main_controller.h.

372 { return m_tick; }

◆ ticksPerCycle()

uint16_t MainController::ticksPerCycle ( ) const
inline

Get the duration of a cycle in ticks.

Definition at line 349 of file main_controller.h.

349 { return m_ticksPerCycle; }

◆ ticksPerInhalation()

uint32_t MainController::ticksPerInhalation ( ) const
inline

Get the duration of an inhalation in ticks.

Definition at line 352 of file main_controller.h.

352 { return m_ticksPerInhalation; }

◆ ticksPerInhalationSet()

void MainController::ticksPerInhalationSet ( uint32_t  p_ticksPerInhalation)
inline

Get the duration of an inhalation in ticks.

Definition at line 355 of file main_controller.h.

355  {
356  m_ticksPerInhalation = p_ticksPerInhalation;
357  }

◆ tidalVolumeCommand()

int16_t MainController::tidalVolumeCommand ( ) const
inline

Definition at line 251 of file main_controller.h.

251 { return m_tidalVolumeCommand; }

◆ tidalVolumeMeasure()

uint16_t MainController::tidalVolumeMeasure ( ) const
inline

Get the measured Tidal Volume. Updated only at the end of inspiration.

Definition at line 341 of file main_controller.h.

341 { return m_tidalVolumeMeasure; }

◆ tidalVolumeNextCommand()

int16_t MainController::tidalVolumeNextCommand ( ) const
inline

Get the desired tidal Volume for the next cycle (used in VC modes)

Definition at line 288 of file main_controller.h.

288 { return m_tidalVolumeNextCommand; }

◆ tiMaxCommand()

const int16_t MainController::tiMaxCommand ( ) const
inline

Get the value of the max duration of inspiration in ms.

Definition at line 279 of file main_controller.h.

279 { return m_tiMaxCommand; }

◆ tiMaxNextCommand()

const int16_t MainController::tiMaxNextCommand ( ) const
inline

Get the value of the max duration of inspiration in ms for the next cycle.

Definition at line 316 of file main_controller.h.

316 { return m_tiMaxNextCommand; }

◆ tiMinCommand()

const int16_t MainController::tiMinCommand ( ) const
inline

Get the value of the minimum duration of inspiration in ms.

Definition at line 277 of file main_controller.h.

277 { return m_tiMinCommand; }

◆ tiMinNextCommand()

const int16_t MainController::tiMinNextCommand ( ) const
inline

Get the value of the minimum duration of inspiration in ms for the next cycle.

Definition at line 314 of file main_controller.h.

314 { return m_tiMinNextCommand; }

◆ triggered()

const bool MainController::triggered ( ) const
inline

Get the state of the inspiratory trigger.

Definition at line 381 of file main_controller.h.

381 { return m_triggered; }

◆ triggerModeEnabledCommand()

const bool MainController::triggerModeEnabledCommand ( )
inline

Get the enabling state of trigger mode.

Definition at line 267 of file main_controller.h.

267 { return m_triggerModeEnabledCommand; }

◆ triggerModeEnabledNextCommand()

const bool MainController::triggerModeEnabledNextCommand ( )
inline

Get the enabling state of trigger mode for the next cycle.

Definition at line 304 of file main_controller.h.

◆ updateCurrentDeliveredVolume()

void MainController::updateCurrentDeliveredVolume ( int32_t  p_currentDeliveredVolume)

Input the current delivered volume in inspiratory branch since beginning of the respiratory cycle.

Parameters
p_currentDeliveredVolumeDelivered Volume in mL/s

Definition at line 489 of file main_controller.cpp.

489  {
490  if (p_currentDeliveredVolume != MASS_FLOW_ERROR_VALUE) {
491  m_currentDeliveredVolume = p_currentDeliveredVolume;
492  }
493 }
#define MASS_FLOW_ERROR_VALUE
Definition: parameters.h:302

◆ updateCurrentExpiratoryVolume()

void MainController::updateCurrentExpiratoryVolume ( int32_t  p_expiratoryVolume)

Definition at line 495 of file main_controller.cpp.

495  {
496  if (p_expiratoryVolume != MASS_FLOW_ERROR_VALUE) {
497  m_expiratoryVolume = p_expiratoryVolume;
498  }
499 }

◆ updateDt()

void MainController::updateDt ( int32_t  p_dt)

Input the real duration since the last pressure controller computation.

Parameters
p_dtDuration in microsecond

Definition at line 424 of file main_controller.cpp.

424 { m_dt = p_dt; }

◆ updateExpiratoryFlow()

void MainController::updateExpiratoryFlow ( int32_t  p_currentExpiratoryFlow)

Input an expiratory flow reading.

Parameters
p_currentExpiratoryFlowMeasured expiratory flow

Definition at line 439 of file main_controller.cpp.

439  {
440  if (p_currentExpiratoryFlow != MASS_FLOW_ERROR_VALUE) {
441  m_expiratoryFlow = p_currentExpiratoryFlow;
442 
445  }
446  }
447 }

◆ updateFakeExpiratoryFlow()

void MainController::updateFakeExpiratoryFlow ( )

Calculate expiratory flow from pressure and valve angle.

Definition at line 450 of file main_controller.cpp.

450  {
451  // get section in mm2 x 100
452  int32_t A2MultiplyBy100 = expiratoryValve.getSectionBigHoseX100();
453  int32_t A1MultiplyBy100 = 7853;
454  int32_t rhoMultiplyBy10 = 12;
455  int32_t pressure = max(int32_t(0), m_pressure - int32_t(50));
456  int32_t divider = (rhoMultiplyBy10
457  * (10000
458  - (100 * A2MultiplyBy100 / A1MultiplyBy100)
459  * (100 * A2MultiplyBy100 / A1MultiplyBy100)));
460  int32_t tempRatioX100 = (divider <= 0) ? 0 : (100 * (2 * pressure * 980000 / divider));
462  (tempRatioX100 < 0) ? 0 : (A2MultiplyBy100 * sqrt(tempRatioX100) * 60) / 1000;
463  /*if (openning == 125) {
464  m_expiratoryFlow = 0;
465  } else {
466  int32_t aMultiplyBy100 =
467  ((((-585 * openning) * openning) / 100000) + ((118 * openning) / 100)) - 62;
468  int32_t bMultiplyBy100 = ((((195 * openning) * openning) / 100) + 33300 - (489 * openning));
469  int32_t cMultiplyBy100 = 279000 - (2170 * openning);
470 
471  int32_t p = m_pressure;
472  m_expiratoryFlow =
473  (((aMultiplyBy100 * p) * p) + (bMultiplyBy100 * p) + cMultiplyBy100) / 100;
474  }*/
475 
476  /*Serial.print(A2MultiplyBy100);
477  Serial.print(",");
478  Serial.print(m_pressure);
479  Serial.print(",");
480  Serial.print(tempRatioX100);
481  Serial.print(",");
482  Serial.print(m_expiratoryFlow);
483  Serial.print(",");
484  Serial.println();*/
485 
486  m_expiratoryVolume += ((m_expiratoryFlow / 60) * m_dt) / 1000000;
487 }
int16_t pressure() const
Get the current measured pressure.
int32_t getSectionBigHoseX100()

◆ updateInspiratoryFlow()

void MainController::updateInspiratoryFlow ( int32_t  p_currentInspiratoryFlow)

Input an inspiratory flow reading.

Parameters
p_currentInspiratoryFlowMeasured inspiratory flow

Definition at line 428 of file main_controller.cpp.

428  {
429  if (p_currentInspiratoryFlow != MASS_FLOW_ERROR_VALUE) {
430  m_inspiratoryFlow = p_currentInspiratoryFlow;
431 
434  }
435  }
436 }

◆ updatePhase()

void MainController::updatePhase ( )
private

Update the cycle phase.

Parameters
p_tickDuration from the begining of the cycle in hundredth of second

Definition at line 314 of file main_controller.cpp.

314  {
318 
319  } else {
322  }
323 }

◆ updatePressure()

void MainController::updatePressure ( int16_t  p_currentPressure)

Input a pressure reading.

Parameters
p_currentPressureMeasured pressure

Definition at line 422 of file main_controller.cpp.

422 { m_pressure = p_currentPressure; }

◆ updateTick()

void MainController::updateTick ( uint32_t  p_tick)

Input a tick number.

Parameters
p_tickTick number

Definition at line 426 of file main_controller.cpp.

426 { m_tick = p_tick; }

◆ ventilationControllerNextCommand()

const VentilationController* MainController::ventilationControllerNextCommand ( ) const
inline

Ventilation controller pointer for the next cycle.

Definition at line 326 of file main_controller.h.

326  {
328  }

Member Data Documentation

◆ m_currentDeliveredVolume

int32_t MainController::m_currentDeliveredVolume
private

Current delivered volume by the blower.

Note
This is not equal to Vt, because of recirculation during exhale

Definition at line 692 of file main_controller.h.

◆ m_cycleNb

uint32_t MainController::m_cycleNb
private

Number of elapsed cycles since beginning.

Definition at line 704 of file main_controller.h.

◆ m_cyclesPerMinuteCommand

uint16_t MainController::m_cyclesPerMinuteCommand
private

Actual desired number of cycles per minute.

Definition at line 467 of file main_controller.h.

◆ m_cyclesPerMinuteMeasure

uint32_t MainController::m_cyclesPerMinuteMeasure
private

Measured number of cycles per minute.

Definition at line 471 of file main_controller.h.

◆ m_cyclesPerMinuteNextCommand

uint16_t MainController::m_cyclesPerMinuteNextCommand
private

Number of cycles per minute desired by the operator for the next cycle.

Definition at line 469 of file main_controller.h.

◆ m_dt

int32_t MainController::m_dt
private

Time since the last computation (in microsecond)

Definition at line 707 of file main_controller.h.

◆ m_expiratoryFlow

int32_t MainController::m_expiratoryFlow
private

Measured inspiratory flow.

Definition at line 679 of file main_controller.h.

◆ m_expiratoryTermCommand

uint16_t MainController::m_expiratoryTermCommand
private

Actual expiratory term.

E term of the I:E ratio. I = 10, and E is in [10;60]

Definition at line 547 of file main_controller.h.

◆ m_expiratoryTermNextCommand

uint16_t MainController::m_expiratoryTermNextCommand
private

Desired expiratory term for the next cycle.

Definition at line 549 of file main_controller.h.

◆ m_expiratoryTriggerFlowCommand

int16_t MainController::m_expiratoryTriggerFlowCommand
private

Desired expiratory trigger flow (in percent of max flow)

Definition at line 557 of file main_controller.h.

◆ m_expiratoryTriggerFlowNextCommand

int16_t MainController::m_expiratoryTriggerFlowNextCommand
private

Desired expiratory trigger flow for next cycle (in percent of max flow)

Definition at line 559 of file main_controller.h.

◆ m_expiratoryVolume

int32_t MainController::m_expiratoryVolume
private

Volume expired by the patient during the exhalation phase.

Definition at line 661 of file main_controller.h.

◆ m_highExpiratoryMinuteVolumeAlarmThresholdCommand

int32_t MainController::m_highExpiratoryMinuteVolumeAlarmThresholdCommand
private

Threshold for high inspiratory minute volume alarm.

Definition at line 622 of file main_controller.h.

◆ m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand

int32_t MainController::m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand
private

Threshold for high inspiratory minute volume alarm for next cycle.

Definition at line 625 of file main_controller.h.

◆ m_highInspiratoryMinuteVolumeAlarmThresholdCommand

int32_t MainController::m_highInspiratoryMinuteVolumeAlarmThresholdCommand
private

Threshold for high inspiratory minute volume alarm.

Definition at line 610 of file main_controller.h.

◆ m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand

int32_t MainController::m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand
private

Threshold for high inspiratory minute volume alarm for next cycle.

Definition at line 613 of file main_controller.h.

◆ m_highRespiratoryRateAlarmThresholdCommand

int32_t MainController::m_highRespiratoryRateAlarmThresholdCommand
private

Threshold for low respiratory rate.

Definition at line 634 of file main_controller.h.

◆ m_highRespiratoryRateAlarmThresholdNextCommand

int32_t MainController::m_highRespiratoryRateAlarmThresholdNextCommand
private

Threshold for low respiratory rate for next cycle.

Definition at line 637 of file main_controller.h.

◆ m_highTidalVolumeAlarmThresholdCommand

int32_t MainController::m_highTidalVolumeAlarmThresholdCommand
private

Threshold for high tidal Volume Alarm.

Definition at line 645 of file main_controller.h.

◆ m_highTidalVolumeAlarmThresholdNextCommand

int32_t MainController::m_highTidalVolumeAlarmThresholdNextCommand
private

Threshold for high tidal Volume Alarm next cycle.

Definition at line 648 of file main_controller.h.

◆ m_inhalationLastPressure

int16_t MainController::m_inhalationLastPressure
private

Last pressure of inhalation.

Definition at line 695 of file main_controller.h.

◆ m_inspiratoryDurationCommand

int16_t MainController::m_inspiratoryDurationCommand
private

Duration of inspiration.

Definition at line 599 of file main_controller.h.

◆ m_inspiratoryDurationNextCommand

int16_t MainController::m_inspiratoryDurationNextCommand
private

Duration of inspiration.

Definition at line 601 of file main_controller.h.

◆ m_inspiratoryFlow

int32_t MainController::m_inspiratoryFlow
private

Measured inspiratory flow.

Definition at line 673 of file main_controller.h.

◆ m_inspiratoryTriggerFlowCommand

int16_t MainController::m_inspiratoryTriggerFlowCommand
private

Desired inspiratory trigger flow.

Definition at line 552 of file main_controller.h.

◆ m_inspiratoryTriggerFlowNextCommand

int16_t MainController::m_inspiratoryTriggerFlowNextCommand
private

Desired inspiratory trigger flow for next cycle.

Definition at line 554 of file main_controller.h.

◆ m_inspiratoryValveAngle

uint32_t MainController::m_inspiratoryValveAngle
private

Blower valve angle at peak.

Definition at line 698 of file main_controller.h.

◆ m_isPeepDetected

bool MainController::m_isPeepDetected
private

Is PEEP pressure detected in the cycle?

Definition at line 526 of file main_controller.h.

◆ m_lastBreathPeriodsMs

uint32_t MainController::m_lastBreathPeriodsMs[NUMBER_OF_BREATH_PERIOD]
private

Period durations of last beathings.

Note
Used to compute cpm with a moving mean on several cycles

Definition at line 477 of file main_controller.h.

◆ m_lastBreathPeriodsMsIndex

uint32_t MainController::m_lastBreathPeriodsMsIndex
private

Index for the m_lastBreathPeriodsMs array.

Definition at line 479 of file main_controller.h.

◆ m_lastEndOfRespirationDateMs

uint32_t MainController::m_lastEndOfRespirationDateMs
private

Date of the last ending of a respiration.

Definition at line 481 of file main_controller.h.

◆ m_lastMaxExpiratoryFlow

int32_t MainController::m_lastMaxExpiratoryFlow
private

Measured max inspiratory flow.

Definition at line 685 of file main_controller.h.

◆ m_lastPressureValues

int16_t MainController::m_lastPressureValues[MAX_PRESSURE_SAMPLES]
private

Last pressure values.

Definition at line 713 of file main_controller.h.

◆ m_lastPressureValuesIndex

uint16_t MainController::m_lastPressureValuesIndex
private

Last pressure index.

Definition at line 716 of file main_controller.h.

◆ m_leakAlarmThresholdCommand

int32_t MainController::m_leakAlarmThresholdCommand
private

Threshold for leak alarm.

Definition at line 651 of file main_controller.h.

◆ m_leakAlarmThresholdNextCommand

int32_t MainController::m_leakAlarmThresholdNextCommand
private

Threshold for leak alarm for next cycle.

Definition at line 653 of file main_controller.h.

◆ m_lowExpiratoryMinuteVolumeAlarmThresholdCommand

int32_t MainController::m_lowExpiratoryMinuteVolumeAlarmThresholdCommand
private

Threshold for low inspiratory minute volume alarm.

Definition at line 616 of file main_controller.h.

◆ m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand

int32_t MainController::m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand
private

Threshold for low inspiratory minute volume alarm for next cycle.

Definition at line 619 of file main_controller.h.

◆ m_lowInspiratoryMinuteVolumeAlarmThresholdCommand

int32_t MainController::m_lowInspiratoryMinuteVolumeAlarmThresholdCommand
private

Threshold for low inspiratory minute volume alarm.

Definition at line 604 of file main_controller.h.

◆ m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand

int32_t MainController::m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand
private

Threshold for low inspiratory minute volume alarm for next cycle.

Definition at line 607 of file main_controller.h.

◆ m_lowRespiratoryRateAlarmThresholdCommand

int32_t MainController::m_lowRespiratoryRateAlarmThresholdCommand
private

Threshold for low respiratory rate.

Definition at line 628 of file main_controller.h.

◆ m_lowRespiratoryRateAlarmThresholdNextCommand

int32_t MainController::m_lowRespiratoryRateAlarmThresholdNextCommand
private

Threshold for low respiratory rate for next cycle.

Definition at line 631 of file main_controller.h.

◆ m_lowTidalVolumeAlarmThresholdCommand

int32_t MainController::m_lowTidalVolumeAlarmThresholdCommand
private

Threshold for low tidal Volume Alarm.

Definition at line 640 of file main_controller.h.

◆ m_lowTidalVolumeAlarmThresholdNextCommand

int32_t MainController::m_lowTidalVolumeAlarmThresholdNextCommand
private

Threshold for low tidal Volume Alarm next cycle.

Definition at line 642 of file main_controller.h.

◆ m_maxExpiratoryFlow

int32_t MainController::m_maxExpiratoryFlow
private

Measured max inspiratory flow.

Definition at line 682 of file main_controller.h.

◆ m_maxInspiratoryFlow

int32_t MainController::m_maxInspiratoryFlow
private

Measured max inspiratory flow.

Definition at line 676 of file main_controller.h.

◆ m_numberOfPressures

uint16_t MainController::m_numberOfPressures
private

Number of the current cycle's pressures.

Definition at line 722 of file main_controller.h.

◆ m_patientGender

int32_t MainController::m_patientGender
private

Definition at line 728 of file main_controller.h.

◆ m_patientHeight

int32_t MainController::m_patientHeight
private

Definition at line 725 of file main_controller.h.

◆ m_peakPressureAlarmThresholdCommand

int16_t MainController::m_peakPressureAlarmThresholdCommand
private

Threshold for peak pressure alarm.

Definition at line 656 of file main_controller.h.

◆ m_peakPressureAlarmThresholdNextCommand

int16_t MainController::m_peakPressureAlarmThresholdNextCommand
private

Threshold for peak pressure alarmfor next cycle.

Definition at line 658 of file main_controller.h.

◆ m_peakPressureCommand

int16_t MainController::m_peakPressureCommand
private

Actual desired peak pressure.

Definition at line 484 of file main_controller.h.

◆ m_peakPressureMeasure

int16_t MainController::m_peakPressureMeasure
private

Measured value of peak pressure.

Definition at line 486 of file main_controller.h.

◆ m_peakPressureNextCommand

int16_t MainController::m_peakPressureNextCommand
private

Peak pressure desired by the operator for the next cycle.

Definition at line 490 of file main_controller.h.

◆ m_peepCommand

int16_t MainController::m_peepCommand
private

Actual desired PEEP.

Definition at line 520 of file main_controller.h.

◆ m_peepMeasure

int16_t MainController::m_peepMeasure
private

Measured value of the PEEP.

Definition at line 524 of file main_controller.h.

◆ m_peepNextCommand

int16_t MainController::m_peepNextCommand
private

Desired PEEP for the next cycle.

Definition at line 522 of file main_controller.h.

◆ m_phase

CyclePhases MainController::m_phase
private

Current respiratory cycle phase.

Definition at line 701 of file main_controller.h.

◆ m_plateauDurationCommand

int16_t MainController::m_plateauDurationCommand
private

Plateau duration command (used in VC modes)

Definition at line 590 of file main_controller.h.

◆ m_plateauDurationMs

uint32_t MainController::m_plateauDurationMs
private

Duration of the plateau.

Note
This setting is used in trigger mode

Definition at line 517 of file main_controller.h.

◆ m_plateauDurationNextCommand

int16_t MainController::m_plateauDurationNextCommand
private

Plateau duration command for next cycle.

Definition at line 592 of file main_controller.h.

◆ m_PlateauMeasureCount

uint16_t MainController::m_PlateauMeasureCount
private

Count for calulating plateau value.

Definition at line 511 of file main_controller.h.

◆ m_PlateauMeasureSum

int64_t MainController::m_PlateauMeasureSum
private

Sum for calulating plateau value.

Definition at line 509 of file main_controller.h.

◆ m_plateauPressureCommand

int16_t MainController::m_plateauPressureCommand
private

Actual desired plateau pressure.

Definition at line 493 of file main_controller.h.

◆ m_plateauPressureMeasure

int16_t MainController::m_plateauPressureMeasure
private

Measured value of the plateau pressure.

Note
Can sometimes have the special value of MAXINT

Definition at line 501 of file main_controller.h.

◆ m_plateauPressureNextCommand

int16_t MainController::m_plateauPressureNextCommand
private

Plateau pressure desired by the operator for the next cycle.

Definition at line 495 of file main_controller.h.

◆ m_plateauPressureToDisplay

int16_t MainController::m_plateauPressureToDisplay
private

Measured value of the plateau pressure for display.

Note
Special value of MAXINT in m_plateauPressureMeasure is replaced by 0

Definition at line 507 of file main_controller.h.

◆ m_pressure

int16_t MainController::m_pressure
private

Measured pressure.

Definition at line 670 of file main_controller.h.

◆ m_pressureCommand

int32_t MainController::m_pressureCommand
private

Requested pressure at a given point in time.

Definition at line 710 of file main_controller.h.

◆ m_pressureTriggerOffsetCommand

int16_t MainController::m_pressureTriggerOffsetCommand
private

Actual pressure trigger offset.

Definition at line 529 of file main_controller.h.

◆ m_pressureTriggerOffsetNextCommand

int16_t MainController::m_pressureTriggerOffsetNextCommand
private

Desired pressure trigger offset for the next cycle.

Definition at line 531 of file main_controller.h.

◆ m_rebouncePeakPressureMeasure

int16_t MainController::m_rebouncePeakPressureMeasure
private

Measured value of rebounce peak pressure.

Definition at line 488 of file main_controller.h.

◆ m_sumOfPressures

uint32_t MainController::m_sumOfPressures
private

Sum of the current cycle's pressures.

Definition at line 719 of file main_controller.h.

◆ m_targetInspiratoryFlowCommand

int32_t MainController::m_targetInspiratoryFlowCommand
private

inspiratory flow required (used in VC modes)

Definition at line 595 of file main_controller.h.

◆ m_targetInspiratoryFlowNextCommand

int32_t MainController::m_targetInspiratoryFlowNextCommand
private

inspiratory flow required (used in VC modes) for next cycle

Definition at line 597 of file main_controller.h.

◆ m_tick

uint32_t MainController::m_tick
private

Actual tick number (given by the main state machine)

Definition at line 464 of file main_controller.h.

◆ m_ticksPerCycle

uint16_t MainController::m_ticksPerCycle
private

Number of hundredth of second per cycle.

Definition at line 664 of file main_controller.h.

◆ m_ticksPerInhalation

uint32_t MainController::m_ticksPerInhalation
private

Number of hundredth of second per inhalation.

Definition at line 667 of file main_controller.h.

◆ m_tidalVolumeAlreadyRead

bool MainController::m_tidalVolumeAlreadyRead
private

True if Tidal volume has already been read during cycle.

Definition at line 541 of file main_controller.h.

◆ m_tidalVolumeCommand

int16_t MainController::m_tidalVolumeCommand
private

Tidal volume command (used in VC modes)

Definition at line 585 of file main_controller.h.

◆ m_tidalVolumeMeasure

int16_t MainController::m_tidalVolumeMeasure
private

Measured value of the Tidal volume (volume of air pushed in patient lungs in last inspiration)

Definition at line 582 of file main_controller.h.

◆ m_tidalVolumeNextCommand

int16_t MainController::m_tidalVolumeNextCommand
private

Tidal volume command for next cycle.

Definition at line 587 of file main_controller.h.

◆ m_tiMaxCommand

int16_t MainController::m_tiMaxCommand
private

Max duration of inspiration in ms.

Definition at line 564 of file main_controller.h.

◆ m_tiMaxNextCommand

int16_t MainController::m_tiMaxNextCommand
private

Max duration of inspiration in ms for next cycle.

Definition at line 568 of file main_controller.h.

◆ m_tiMinCommand

int16_t MainController::m_tiMinCommand
private

Minimum duration of inspiration in ms.

Definition at line 562 of file main_controller.h.

◆ m_tiMinNextCommand

int16_t MainController::m_tiMinNextCommand
private

Minimum duration of inspiration in ms for next cycle.

Definition at line 566 of file main_controller.h.

◆ m_triggered

bool MainController::m_triggered
private

Is inspiratory triggered or not?

Definition at line 533 of file main_controller.h.

◆ m_triggerModeEnabledCommand

bool MainController::m_triggerModeEnabledCommand
private

Actual state of enabling of trigger mode.

Definition at line 536 of file main_controller.h.

◆ m_triggerModeEnabledNextCommand

bool MainController::m_triggerModeEnabledNextCommand
private

Desired state of enabling of trigger mode for the next cycle.

Definition at line 538 of file main_controller.h.

◆ m_ventilationController

VentilationController* MainController::m_ventilationController
private

Ventilation controller in use (for everything related to breathing control)

Definition at line 571 of file main_controller.h.

◆ m_ventilationControllerMode

VentilationModes MainController::m_ventilationControllerMode
private

Definition at line 578 of file main_controller.h.

◆ m_ventilationControllerNextCommand

VentilationController* MainController::m_ventilationControllerNextCommand
private

Ventilation controller for the next cycle.

Definition at line 573 of file main_controller.h.

◆ m_ventilationControllersTable

VentilationController* MainController::m_ventilationControllersTable[NUMBER_OF_VENTILATION_MODES+1u]
private

Array containing pointers to different ventilation controllers.

Definition at line 576 of file main_controller.h.


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