Skip to content
Snippets Groups Projects
Commit 7c16cbab authored by Karol Hennessy's avatar Karol Hennessy
Browse files

several improvements - added enables, new valve states, safety check

parent 76610f23
Branches
No related merge requests found
......@@ -14,7 +14,7 @@ public:
int doAlarm(alarm_format *af);
alarm_thresholds& getThresholdsMin() { return _thresholds_min; }
alarm_thresholds& getThresholdsMax() { return _thresholds_min; }
alarm_thresholds& getThresholdsMax() { return _thresholds_max; }
private:
alarm_thresholds _thresholds_min;
alarm_thresholds _thresholds_max;
......
......@@ -14,6 +14,7 @@ BreathingLoop::BreathingLoop()
_bl_state = BL_STATES::IDLE;
_running = false;
_reset = false;
_safe = true;
initCalib();
resetReadingSums();
......@@ -26,14 +27,6 @@ BreathingLoop::BreathingLoop()
+_states_durations.exhale;
_total_cycle_duration[2] = _total_cycle_duration[1] = _total_cycle_duration[0];
_valve_inhale_percent = 0; // replaced by a min level and a max level; bias inhale level. very slightly open at "closed" position
_valve_exhale_percent = 0;
_valve_air_in_enable = 1;
_valve_o2_in_enable = 1;
_valve_purge_enable = 1;
_inhale_trigger_enable = 0; // params - associated val of peak flow
_exhale_trigger_enable = 0;
_flow = 0;
_volume = 0;
_airway_pressure = 0;
......@@ -265,13 +258,17 @@ void BreathingLoop::FSM_assignment( ) {
break;
case BL_STATES::EXHALE:
if (_running == false) {
next_state = BL_STATES::IDLE;
next_state = BL_STATES::STOP;
} else {
next_state = BL_STATES::BUFF_LOADED;
}
break;
case BL_STATES::BUFF_PURGE:
if (_running == false) {
if (_reset == true ){
next_state = BL_STATES::IDLE;
} else if (_safe == false ){
next_state = BL_STATES::BUFF_PURGE;
} else if (_running == false) {
next_state = BL_STATES::IDLE;
} else {
next_state = BL_STATES::BUFF_PREFILL;
......@@ -281,7 +278,7 @@ void BreathingLoop::FSM_assignment( ) {
next_state = BL_STATES::IDLE;
break;
case BL_STATES::STOP:
if (_reset == true) {
if (_reset == true or _running == true) {
next_state = BL_STATES::IDLE;
} else {
next_state = BL_STATES::STOP;
......@@ -295,12 +292,18 @@ void BreathingLoop::FSM_assignment( ) {
// set flag to discard readings due to the mode change
_readings_reset = true;
}
// safety check
if (tnow - _fsm_time > 10) {
if (_safe == false){
_bl_state = BL_STATES::BUFF_PURGE;
// TODO RAISE ALARM
_fsm_timeout = 0;
}
}
}
void BreathingLoop::FSM_breathCycle()
{
// basic cycle for testing hardware
// start = digitalRead(pin_button_0);
switch (_bl_state) {
case BL_STATES::IDLE:
......@@ -309,35 +312,30 @@ void BreathingLoop::FSM_breathCycle()
} else {
_fsm_timeout = 1000;
}
// TODO
// air, o2, purge are based on button states in idle
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED);
initCalib();
break;
case BL_STATES::CALIBRATION :
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::OPEN);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CALIB_OPEN, VALVE_STATE::CALIB_OPEN, VALVE_STATE::OPEN);
calibrate();
// TODO
// do calib - measure P_regulated for 10 s and calc mean
// P_patient, P_buffer and P_inhale shoudl be equal
// WHERE do I call getCalibrationOffset()?
_fsm_timeout = _states_durations.calibration;
break;
case BL_STATES::BUFF_PREFILL:
// TODO - exhale settable; timeout expert settable
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.8 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_calibrated = true;
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.buff_prefill;
break;
case BL_STATES::BUFF_FILL:
// TODO - exhale settable; timeout settable
_valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, 0.8 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.buff_fill;
break;
case BL_STATES::BUFF_LOADED:
// TODO - exhale settable
// Calc pressure and stay in loaded if not ok
// pressure settable by expert
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.8 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.buff_loaded;
break;
case BL_STATES::BUFF_PRE_INHALE:
......@@ -371,7 +369,7 @@ void BreathingLoop::FSM_breathCycle()
// TODO : spontaneous trigger
// if p_inhale > max thresh pressure(def: 50?)
// go to exhale fill
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.8*VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.inhale;
break;
......@@ -380,14 +378,14 @@ void BreathingLoop::FSM_breathCycle()
_fsm_timeout = _states_durations.pause;
break;
case BL_STATES::EXHALE_FILL:
_valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.exhale_fill;
break;
case BL_STATES::EXHALE:
// TODO: exhale timeout based on
// (inhale_time* (Exhale/Inhale ratio)) - exhale fill time
_states_durations.exhale = calculateDurationExhale();
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.exhale;
//update total cycle time
updateTotalCycleDuration(_states_durations.buff_loaded
......@@ -398,11 +396,11 @@ void BreathingLoop::FSM_breathCycle()
+_states_durations.exhale);
break;
case BL_STATES::BUFF_PURGE:
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::OPEN);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_OPEN, VALVE_STATE::OPEN);
_fsm_timeout = _states_durations.buff_purge;
break;
case BL_STATES::BUFF_FLUSH:
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, 0.9 * VALVE_STATE::OPEN, 0.9 * VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_OPEN, VALVE_STATE::FULLY_OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = _states_durations.buff_flush;
break;
case BL_STATES::STOP:
......@@ -411,7 +409,21 @@ void BreathingLoop::FSM_breathCycle()
_fsm_timeout = 1000;
break;
}
safetyCheck();
}
void BreathingLoop::safetyCheck()
{
// based on averages or instantaneous values?
if (_calibrated){
if (_readings_avgs.pressure_inhale > MAX_PATIENT_PRESSURE)
_safe = false;
else if (_readings_avgs.pressure_patient > MAX_PATIENT_PRESSURE)
_safe = false;
else
_safe = true;
}
}
void BreathingLoop::doStart()
......@@ -459,6 +471,7 @@ void BreathingLoop::calibrate()
void BreathingLoop::initCalib()
{ // do calibration in last sec of calibration step (normally 10s) or default to 10ms
_calibrated = false;
_calib_timeout = 10;
if (_states_durations.calibration - 1000 > 10)
_calib_timeout = _states_durations.calibration - 1000;
......@@ -495,14 +508,6 @@ ValvesController* BreathingLoop::getValvesController()
return &_valves_controller;
}
uint8_t BreathingLoop::getValveInhalePercent(){return _valve_inhale_percent;}
uint8_t BreathingLoop::getValveExhalePercent(){return _valve_exhale_percent;}
uint8_t BreathingLoop::valveAirInEnabled(){return _valve_air_in_enable;}
uint8_t BreathingLoop::valveO2InEnabled(){return _valve_o2_in_enable;}
uint8_t BreathingLoop::valvePurgeEnabled(){return _valve_purge_enable;}
uint8_t BreathingLoop::inhaleTriggerEnabled(){return _inhale_trigger_enable;}
uint8_t BreathingLoop::exhaleTriggerEnabled(){return _exhale_trigger_enable;}
void BreathingLoop::updateTotalCycleDuration(uint16_t newtotal)
{
_total_cycle_duration[0] = _total_cycle_duration[1];
......
......@@ -32,14 +32,6 @@ public:
float getIERatio();
float getMinuteVolume();
ValvesController * getValvesController();
uint8_t getValveInhalePercent();
uint8_t getValveExhalePercent();
uint8_t valveAirInEnabled();
uint8_t valveO2InEnabled();
uint8_t valvePurgeEnabled();
uint8_t inhaleTriggerEnabled();
uint8_t exhaleTriggerEnabled();
float getFlow();
float getVolume();
float getAirwayPressure();
......@@ -88,6 +80,7 @@ private:
uint32_t _calib_N;
uint32_t _calib_time;
uint32_t _calib_timeout;
bool _calibrated;
readings<int32_t> _calib_sums;
readings<int16_t> _calib_avgs;
......@@ -107,13 +100,7 @@ private:
uint32_t _readings_avgs_time;
uint32_t _readings_avgs_timeout;
uint8_t _valve_inhale_percent ; // replaced by a min level and a max level; bias inhale level. very slightly open at "closed" position
uint8_t _valve_exhale_percent ;
uint8_t _valve_air_in_enable ;
uint8_t _valve_o2_in_enable ;
uint8_t _valve_purge_enable ;
uint8_t _inhale_trigger_enable ; // params - associated val of peak flow
uint8_t _exhale_trigger_enable ;
// calculations
void updateTotalCycleDuration(uint16_t newtotal);
uint16_t _total_cycle_duration[3];
......@@ -121,6 +108,10 @@ private:
float _flow;
float _volume;
float _airway_pressure;
// safety
void safetyCheck();
uint8_t _safe;
};
......
......@@ -79,7 +79,7 @@ void UILoop::reportReadbackValues()
if (tnow - _readback_report_time > _readback_report_timeout)
{
bool vin_air, vin_o2, vpurge;
float vinhale, vexhale;
uint8_t vinhale, vexhale;
ValvesController *valves_controller = _breathing_loop->getValvesController();
valves_controller->getValves(vin_air, vin_o2, vinhale, vexhale, vpurge);
......@@ -107,13 +107,13 @@ void UILoop::reportReadbackValues()
_readback_data.valve_inhale_percent = 0; //TODO
_readback_data.valve_exhale_percent = 0; //TODO
_readback_data.valve_inhale_percent = _breathing_loop->getValveInhalePercent();
_readback_data.valve_exhale_percent = _breathing_loop->getValveInhalePercent();
_readback_data.valve_air_in_enable = _breathing_loop->valveAirInEnabled();
_readback_data.valve_o2_in_enable = _breathing_loop->valveO2InEnabled();
_readback_data.valve_purge_enable = _breathing_loop->valvePurgeEnabled();
_readback_data.inhale_trigger_enable = _breathing_loop->inhaleTriggerEnabled();
_readback_data.exhale_trigger_enable = _breathing_loop->exhaleTriggerEnabled();
_readback_data.valve_inhale_percent = valves_controller->getValveInhalePercent();
_readback_data.valve_exhale_percent = valves_controller->getValveInhalePercent();
_readback_data.valve_air_in_enable = valves_controller->valveAirInEnabled();
_readback_data.valve_o2_in_enable = valves_controller->valveO2InEnabled();
_readback_data.valve_purge_enable = valves_controller->valvePurgeEnabled();
_readback_data.inhale_trigger_enable = valves_controller->inhaleTriggerEnabled();
_readback_data.exhale_trigger_enable = valves_controller->exhaleTriggerEnabled();
// _readback_data.peep = _breathing_loop->peep();
_readback_data.inhale_exhale_ratio = _breathing_loop->getIERatio();
......@@ -157,6 +157,9 @@ int UILoop::doCommand(cmd_format &cf)
case CMD_TYPE::SET_THRESHOLD_MAX :
cmdSetThresholdMax(cf);
break;
case CMD_TYPE::SET_VALVE:
cmdSetValve(cf);
break;
default:
break;
}
......@@ -182,6 +185,7 @@ void UILoop::cmdSetMode(cmd_format &cf) {
;
}
// FIXME shouldn't these use setThresholdMin,Max ...?
void UILoop::cmdSetThresholdMin(cmd_format &cf) {
setThreshold(static_cast<ALARM_CODES>(cf.cmd_code), _alarm_loop->getThresholdsMin(), cf.param);
}
......@@ -190,4 +194,6 @@ void UILoop::cmdSetThresholdMax(cmd_format &cf) {
setThreshold(static_cast<ALARM_CODES>(cf.cmd_code), _alarm_loop->getThresholdsMax(), cf.param);
}
void UILoop::cmdSetValve(cmd_format &cf) {
setValveParam(static_cast<CMD_SET_VALVE>(cf.cmd_code), _breathing_loop->getValvesController(), cf.param);
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ private:
void cmdSetMode(cmd_format &cf);
void cmdSetThresholdMin(cmd_format &cf);
void cmdSetThresholdMax(cmd_format &cf);
void cmdSetValve(cmd_format &cf);
BreathingLoop *_breathing_loop;
......
......@@ -13,11 +13,11 @@ ValvesController::ValvesController()
_inhale.pin = pin_valve_inhale;
_inhale.proportional = true;
_inhale.state = VALVE_STATE::CLOSED;
_inhale.state = VALVE_STATE::FULLY_CLOSED;
_exhale.pin = pin_valve_exhale;
_exhale.proportional = true;
_exhale.state = VALVE_STATE::CLOSED;
_exhale.state = VALVE_STATE::FULLY_CLOSED;
_purge.pin = pin_valve_purge;
_purge.proportional = false;
......@@ -25,6 +25,18 @@ ValvesController::ValvesController()
_pin_to_chan[pin_valve_inhale] = pwm_chan_inhale;
_pin_to_chan[pin_valve_exhale] = pwm_chan_exhale;
_inhale_duty_cycle = 0;
_inhale_open_max = MAX_VALVE_FRAC_OPEN;
_inhale_open_min = 0;
_valve_inhale_percent = 0; // replaced by a min level and a max level; bias inhale level. very slightly open at "closed" position
_valve_exhale_percent = 0;
_valve_air_in_enable = 1;
_valve_o2_in_enable = 1;
_valve_purge_enable = 1;
_inhale_trigger_enable = 0; // params - associated val of peak flow
_exhale_trigger_enable = 0;
}
ValvesController::~ValvesController()
......@@ -59,14 +71,87 @@ void ValvesController::setPWMValve(int pin, float frac_open)
#endif
}
void ValvesController::setValves(bool vin_air, bool vin_o2, float vinhale,
float vexhale, bool vpurge)
// might want to change these to float :
void ValvesController::setInhaleDutyCycle(uint32_t value)
{
float fdc = value / 100.0;
if (fdc > MAX_VALVE_FRAC_OPEN )
fdc = MAX_VALVE_FRAC_OPEN;
_inhale_duty_cycle = fdc;
}
void ValvesController::setInhaleOpenMin(uint32_t value)
{
float fop_min = value / 100.0;
if (fop_min > MAX_VALVE_FRAC_OPEN )
fop_min = MAX_VALVE_FRAC_OPEN;
_inhale_open_min = fop_min;
}
void ValvesController::setInhaleOpenMax(uint32_t value)
{
digitalWrite(_air_in.pin, vin_air);
digitalWrite(_o2_in.pin, vin_o2);
setPWMValve(_inhale.pin, vinhale);
setPWMValve(_exhale.pin, vexhale);
digitalWrite(_purge.pin, vpurge);
float fop_max = value / 100.0;
if (fop_max > MAX_VALVE_FRAC_OPEN )
fop_max = MAX_VALVE_FRAC_OPEN;
_inhale_open_max = fop_max;
}
void ValvesController::setValves(bool vin_air, bool vin_o2, uint8_t vinhale,
uint8_t vexhale, bool vpurge)
{
digitalWrite(_air_in.pin, vin_air * _valve_air_in_enable);
digitalWrite(_o2_in.pin, vin_o2 * _valve_o2_in_enable);
digitalWrite(_purge.pin, vpurge * _valve_purge_enable);
switch(vinhale){
case VALVE_STATE::FULLY_CLOSED:
setPWMValve(_inhale.pin, 0.0);
break;
case VALVE_STATE::FULLY_OPEN:
setPWMValve(_inhale.pin, MAX_VALVE_FRAC_OPEN);
break;
case VALVE_STATE::OPEN:
setPWMValve(_inhale.pin, _inhale_open_max);
break;
case VALVE_STATE::CALIB_OPEN:
setPWMValve(_inhale.pin, 0.9);
break;
case VALVE_STATE::CLOSED:
setPWMValve(_inhale.pin, _inhale_open_min);
break;
case VALVE_STATE::PID:
// placeholder - this should be replaced by:
//doPID(_inhale.pin);
setPWMValve(_inhale.pin, _inhale_open_max);
break;
default:
break;
}
switch(vexhale){
case VALVE_STATE::FULLY_CLOSED:
setPWMValve(_exhale.pin, 0.0);
break;
case VALVE_STATE::FULLY_OPEN:
setPWMValve(_exhale.pin, MAX_VALVE_FRAC_OPEN);
break;
case VALVE_STATE::CALIB_OPEN:
setPWMValve(_exhale.pin, 0.9);
break;
case VALVE_STATE::OPEN:
setPWMValve(_exhale.pin, 0.8);
break;
case VALVE_STATE::CLOSED:
setPWMValve(_exhale.pin, 0);
break;
default:
//doPID(_exhale.pin);
break;
}
// save the state
_air_in.state = vin_air;
......@@ -76,8 +161,8 @@ void ValvesController::setValves(bool vin_air, bool vin_o2, float vinhale,
_purge.state = vpurge;
}
void ValvesController::getValves(bool &vin_air, bool &vin_o2, float &vinhale,
float &vexhale, bool &vpurge)
void ValvesController::getValves(bool &vin_air, bool &vin_o2, uint8_t &vinhale,
uint8_t &vexhale, bool &vpurge)
{
// read the state
vin_air = _air_in.state;
......@@ -86,3 +171,27 @@ void ValvesController::getValves(bool &vin_air, bool &vin_o2, float &vinhale,
vexhale = _exhale.state;
vpurge = _purge.state ;
}
uint8_t ValvesController::getValveInhalePercent(){return _valve_inhale_percent;}
uint8_t ValvesController::getValveExhalePercent(){return _valve_exhale_percent;}
uint8_t ValvesController::valveAirInEnabled(){return _valve_air_in_enable;}
uint8_t ValvesController::valveO2InEnabled(){return _valve_o2_in_enable;}
uint8_t ValvesController::valvePurgeEnabled(){return _valve_purge_enable;}
uint8_t ValvesController::inhaleTriggerEnabled(){return _inhale_trigger_enable;}
uint8_t ValvesController::exhaleTriggerEnabled(){return _exhale_trigger_enable;}
void ValvesController::enableO2InValve(bool en)
{
_valve_o2_in_enable = en;
}
void ValvesController::enablePurgeValve(bool en)
{
_valve_purge_enable = en;
}
void ValvesController::enableAirInValve(bool en)
{
_valve_air_in_enable = en;
}
......@@ -6,13 +6,17 @@
struct valve {
int pin = -1;
bool proportional = false;
float state;
uint8_t state;
};
enum VALVE_STATE : bool
enum VALVE_STATE : uint8_t
{
CLOSED = LOW,
OPEN = HIGH
CLOSED = 0,
OPEN = 1,
PID = 2,
CALIB_OPEN = 3, //
FULLY_OPEN = 4,
FULLY_CLOSED = 5
};
......@@ -24,11 +28,25 @@ public:
ValvesController();
~ValvesController();
void setPWMValve(int pin, float frac_open);
void setValves(bool vin_air, bool vin_o2, float vinhale,
float vexhale, bool vpurge);
void getValves(bool &vin_air, bool &vin_o2, float &vinhale,
float &vexhale, bool &vpurge);
void setValves(bool vin_air, bool vin_o2, uint8_t vinhale,
uint8_t vexhale, bool vpurge);
void getValves(bool &vin_air, bool &vin_o2, uint8_t &vinhale,
uint8_t &vexhale, bool &vpurge);
int calcValveDutyCycle(int pwm_resolution, float frac_open);
uint8_t getValveInhalePercent();
uint8_t getValveExhalePercent();
uint8_t valveAirInEnabled();
uint8_t valveO2InEnabled();
uint8_t valvePurgeEnabled();
uint8_t inhaleTriggerEnabled();
uint8_t exhaleTriggerEnabled();
void enableO2InValve(bool en);
void enablePurgeValve(bool en);
void enableAirInValve(bool en);
void setInhaleDutyCycle(uint32_t value);
void setInhaleOpenMin(uint32_t value);
void setInhaleOpenMax(uint32_t value);
private:
valve _air_in;
......@@ -38,6 +56,17 @@ private:
valve _purge;
uint8_t _pin_to_chan[50];
uint8_t _valve_inhale_percent ; // replaced by a min level and a max level; bias inhale level. very slightly open at "closed" position
uint8_t _valve_exhale_percent ;
uint8_t _valve_air_in_enable ;
uint8_t _valve_o2_in_enable ;
uint8_t _valve_purge_enable ;
uint8_t _inhale_trigger_enable ; // params - associated val of peak flow
uint8_t _exhale_trigger_enable ;
float _inhale_duty_cycle;
float _inhale_open_min;
float _inhale_open_max;
};
#endif
\ No newline at end of file
......@@ -123,6 +123,32 @@ void setDuration(CMD_SET_DURATION cmd, states_durations &durations, uint32_t &va
}
}
void setValveParam(CMD_SET_VALVE cmd, ValvesController *valves_controller, uint32_t &value)
{
switch(cmd){
case CMD_SET_VALVE::AIR_IN_ENABLE :
valves_controller->enableAirInValve( (value > 0) );
break;
case CMD_SET_VALVE::O2_IN_ENABLE :
valves_controller->enableO2InValve( (value > 0) );
break;
case CMD_SET_VALVE::PURGE_ENABLE :
valves_controller->enablePurgeValve( (value > 0) );
break;
case CMD_SET_VALVE::INHALE_DUTY_CYCLE :
valves_controller->setInhaleDutyCycle(value); // should be 0-100
break;
case CMD_SET_VALVE::INHALE_OPEN_MIN :
valves_controller->setInhaleOpenMin(value); // should be 0-100
break;
case CMD_SET_VALVE::INHALE_OPEN_MAX :
valves_controller->setInhaleOpenMax(value); // should be 0-100
break;
default:
break;
}
}
int16_t adcToMillibar(int16_t adc, int16_t offset = 0)
{
// TODO - a proper calibration
......
#ifndef COMMON_H
#define COMMON_H
#include <Arduino.h>
#include "ValvesController.h"
//#define HEV_MINI_SYSTEM // uncomment this if using lab 14-1-014
......@@ -30,20 +31,23 @@
//
const float MAX_VALVE_FRAC_OPEN = 0.68;
const uint8_t MAX_PATIENT_PRESSURE = 40; //mbar
// input params
enum CMD_TYPE : uint8_t {
GENERAL = 1,
SET_DURATION = 2,
SET_MODE = 3,
SET_THRESHOLD_MIN = 4,
SET_THRESHOLD_MAX = 5
SET_THRESHOLD_MAX = 5,
SET_VALVE = 6
};
enum CMD_GENERAL : uint8_t {
START = 1,
STOP = 2,
PURGE = 3,
FLUSH = 4
FLUSH = 4,
RESET = 5
};
// Taken from the FSM doc. Correct as of 1400 on 20200417
......@@ -68,6 +72,15 @@ enum CMD_SET_MODE : uint8_t {
HEV_MODE_TEST
};
enum CMD_SET_VALVE: uint8_t {
AIR_IN_ENABLE = 1,
O2_IN_ENABLE = 2,
PURGE_ENABLE = 3,
INHALE_DUTY_CYCLE = 4,
INHALE_OPEN_MIN = 5,
INHALE_OPEN_MAX = 6
};
#pragma pack(1)
struct cmd_format {
uint8_t version = HEV_FORMAT_VERSION;
......@@ -227,10 +240,10 @@ struct cycle_data_format {
#pragma pack()
enum VALVE_STATES : bool {
V_OPEN = HIGH,
V_CLOSED = LOW
};
//enum VALVE_STATES : bool {
// V_OPEN = HIGH,
// V_CLOSED = LOW
//};
struct states_durations {
uint32_t calibration;
......@@ -281,6 +294,7 @@ struct alarm_thresholds {
void setThreshold(ALARM_CODES alarm, alarm_thresholds &thresholds, uint32_t &value);
void setDuration(CMD_SET_DURATION cmd, states_durations &timeouts, uint32_t &value);
void setValveParam(CMD_SET_VALVE cmd, ValvesController *valves_controller, uint32_t &value);
int16_t adcToMillibar(int16_t adc, int16_t offset = 0);
// used for calculating averages, template due to different size for sums and averages
......
......@@ -22,6 +22,7 @@ class CMD_TYPE(Enum):
SET_MODE = 3
SET_THRESHOLD_MIN = 4
SET_THRESHOLD_MAX = 5
SET_VALVE = 6
@unique
class CMD_GENERAL(Enum):
......@@ -29,6 +30,7 @@ class CMD_GENERAL(Enum):
STOP = 2
PURGE = 3
FLUSH = 4
RESET = 5
# Taken from the FSM doc. Correct as of 1400 on 20200417
@unique
......@@ -51,6 +53,14 @@ class CMD_SET_MODE(Enum):
HEV_MODE_PRVC = 3
HEV_MODE_TEST = 4
class CMD_SET_VALVE(Enum):
AIR_IN_ENABLE = 1,
O2_IN_ENABLE = 2,
PURGE_ENABLE = 3,
INHALE_DUTY_CYCLE = 4,
INHALE_OPEN_MIN = 5,
INHALE_OPEN_MAX = 6
@unique
class ALARM_TYPE(Enum):
LP = 1
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment