12 #include "../includes/parameters.h"
14 #include <IWatchdog.h>
16 #include "../includes/activation.h"
17 #include "../includes/battery.h"
18 #include "../includes/buzzer_control.h"
19 #include "../includes/debug.h"
20 #include "../includes/keyboard.h"
21 #include "../includes/main_controller.h"
22 #include "../includes/main_state_machine.h"
23 #include "../includes/mass_flow_meter.h"
24 #include "../includes/pressure.h"
25 #include "../includes/rpi_watchdog.h"
26 #include "../includes/screen.h"
27 #include "../includes/serial_control.h"
28 #include "../includes/telemetry.h"
66 #if (STM32_CORE_VERSION < 0x01090000)
97 DBG_DO(Serial.println(
"resetting LCD screen");)
144 #ifdef MASS_FLOW_METER_ENABLED
147 #ifdef MASS_FLOW_METER_ENABLED&& MASS_FLOW_METER_SENSOR_EXPI
153 uint32_t currentMillis = millis();
160 uint32_t currentMicro = micros();
161 int32_t inspiratoryflow = 0;
162 int32_t expiratoryflow = 0;
163 #ifdef MASS_FLOW_METER_ENABLED
169 #ifdef MASS_FLOW_METER_ENABLED&& MASS_FLOW_METER_SENSOR_EXPI
229 ::msmTimer->setMode(1, TIMER_OUTPUT_COMPARE, NC);
ActivationController activationController
Instance of the activation controller.
AlarmController alarmController
Instance of the alarm controller.
bool isBatteryDeepDischarged()
Check if battery is deeply discharged.
void batteryLoop(uint32_t p_cycleNumber)
Handle battery events.
bool isRunning() const
Return if breathing is activated or not.
void refreshState()
Refresh the current state.
void runAlarmEffects(uint32_t p_tick)
Run effects (buzzer, LCD message, LED) according to the currently triggered alarms.
const bool triggered() const
Get the state of the inspiratory trigger.
void updateFakeExpiratoryFlow()
Calculate expiratory flow from pressure and valve angle.
uint16_t tidalVolumeMeasure() const
Get the measured Tidal Volume. Updated only at the end of inspiration.
int16_t peepNextCommand() const
Get the desired PEEP for the next cycle.
int16_t plateauPressureNextCommand() const
Get the desired plateau pressure for the next cycle.
int32_t patientHeight() const
int16_t peakPressureNextCommand() const
Get the desired max peak for the next cycle.
void endRespiratoryCycle(uint32_t p_currentMillis)
End a respiratory cycle.
uint16_t ticksPerCycle() const
Get the duration of a cycle in ticks.
uint16_t cyclesPerMinuteNextCommand() const
Get the desired number of cycles per minute for the next cycle.
void updateDt(int32_t p_dt)
Input the real duration since the last pressure controller computation.
void updateExpiratoryFlow(int32_t p_currentExpiratoryFlow)
Input an expiratory flow reading.
void updateCurrentExpiratoryVolume(int32_t p_expiratoryVolume)
void updateCurrentDeliveredVolume(int32_t p_currentDeliveredVolume)
Input the current delivered volume in inspiratory branch since beginning of the respiratory cycle.
int16_t peakPressureMeasure() const
Get the measured peak pressure.
void updatePressure(int16_t p_currentPressure)
Input a pressure reading.
int16_t peepMeasure() const
Get the measured PEEP.
void setup()
Initialize actuators.
void initRespiratoryCycle()
Begin a respiratory cycle.
void onPatientHeight(int16_t p_patientHeight)
Set the desired patient height.
void stop(uint32_t p_currentMillis)
Stop the breathing.
void compute()
Perform the pressure control.
int16_t plateauPressureMeasure() const
Get the measured plateau pressure.
void updateTick(uint32_t p_tick)
Input a tick number.
void updateInspiratoryFlow(int32_t p_currentInspiratoryFlow)
Input an inspiratory flow reading.
uint32_t cycleNumber() const
Get the number of past cycles since the beginning.
void setupAndStart()
Run the state machine.
MainStateMachine()
Default constructor.
void ScreenUpdate()
Display information on screen.
bool isRunning()
Check if the state machine is enabled.
bool isMsmActive
Main state machine activation state.
int32_t read()
Read the current pressure for the feedback control.
void update()
This should be called by the main state machine every 1s.
#define DBG_DO(statement)
Expand arbitrary code only when in debug mode.
void keyboardLoop()
Handle button events.
MainController mainController
MainStateMachine mainStateMachine
uint32_t lastMainControllerCall
void millisecondTimerMSM(HardwareTimer *)
int32_t MFM_read_airflow(void)
Read instant air flow.
int32_t MFM_expi_read_airflow(void)
Read instant air flow.
int32_t MFM_read_milliliters(bool reset_after_read)
Get the number of milliliters since last reset.
int32_t MFM_expi_read_milliliters(bool reset_after_read)
Get the number of milliliters since last reset for expiratory sensor.
#define MAIN_CONTROLLER_COMPUTE_PERIOD_MS
#define DEFAULT_PATIENT_HEIGHT
PressureSensor inspiratoryPressureSensor
void displayMachineStopped()
Display a message when the machine is stopped.
void displayCurrentSettings(uint16_t peakPressureMax, uint16_t plateauPressureMax, uint16_t peepMin)
Display the current settings.
void clearAlarmDisplayCache()
Force clear the alarm display cache.
void displayCurrentVolume(int32_t volumeMassFlow, uint16_t cyclesPerMinute)
Display the current injected air volume.
void resetScreen()
Erase everything that is on the screen.
void displayCurrentInformation(uint16_t peakPressure, uint16_t plateauPressure, uint16_t peep)
Display relevant values from the ongoing cycle.
void serialControlLoop()
Parse input and handle changes of settings.