Commit 89b65b22 authored by Your Name's avatar Your Name

added pre calibration

parent 46ad7962
......@@ -402,12 +402,15 @@ void BreathingLoop::FSM_assignment() {
case BL_STATES::IDLE:
if (_running == true) {
// FSM_time = millis();
next_state = BL_STATES::CALIBRATION;
next_state = BL_STATES::PRE_CALIBRATION;
} else {
next_state = BL_STATES::IDLE;
}
_reset = false;
break;
case BL_STATES::PRE_CALIBRATION:
next_state = BL_STATES::CALIBRATION;
break;
case BL_STATES::CALIBRATION:
next_state = BL_STATES::BUFF_PREFILL;
break;
......@@ -512,8 +515,12 @@ void BreathingLoop::FSM_breathCycle()
#endif
initCalib();
break;
case BL_STATES::CALIBRATION :
case BL_STATES::PRE_CALIBRATION :
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::OPEN);
_fsm_timeout = _states_durations.pre_calibration;
break;
case BL_STATES::CALIBRATION :
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::OPEN);
calibrate();
_fsm_timeout = _states_durations.calibration;
break;
......@@ -629,6 +636,9 @@ void BreathingLoop::measureDurations( ) {
uint32_t tdiff = tnow - _lasttime;
switch (_bl_laststate)
{
case BL_STATES::PRE_CALIBRATION:
_measured_durations.pre_calibration = tdiff;
break;
case BL_STATES::CALIBRATION:
_measured_durations.calibration = tdiff;
break;
......@@ -731,7 +741,7 @@ void BreathingLoop::calibrate()
_calib_avgs.pressure_buffer = static_cast<float>(_calib_sums.pressure_buffer/ _calib_N);
_calib_sums.pressure_inhale += static_cast<float>(analogRead(pin_pressure_inhale));
_calib_avgs.pressure_inhale = static_cast<float>(_calib_sums.pressure_inhale/ _calib_N);
_calib_sums.pressure_patient += static_cast<float>(analogRead(pin_pressure_patient));
_calib_sums.pressure_patient += static_cast<float>(analogRead(pin_pressure_patient));
_calib_avgs.pressure_patient = static_cast<float>(_calib_sums.pressure_patient/ _calib_N);
_calib_sums.pressure_diff_patient += static_cast<float>(analogRead(pin_pressure_diff_patient));
_calib_avgs.pressure_diff_patient = static_cast<float>(_calib_sums.pressure_diff_patient/ _calib_N);
......
......@@ -69,17 +69,18 @@ public:
enum BL_STATES : uint8_t {
UNKNOWN = 0,
IDLE = 1,
CALIBRATION = 2,
BUFF_PREFILL = 3,
BUFF_FILL = 4,
BUFF_PRE_INHALE = 5,
INHALE = 6,
PAUSE = 7,
EXHALE = 8,
STOP = 9,
BUFF_PURGE = 10,
BUFF_FLUSH = 11,
STANDBY = 12
PRE_CALIBRATION = 2,
CALIBRATION = 3,
BUFF_PREFILL = 4,
BUFF_FILL = 5,
BUFF_PRE_INHALE = 6,
INHALE = 7,
PAUSE = 8,
EXHALE = 9,
STOP = 10,
BUFF_PURGE = 11,
BUFF_FLUSH = 12,
STANDBY = 13
};
......@@ -111,8 +112,8 @@ private:
// timeouts
uint32_t calculateDurationExhale();
//durations = {calibration, buff_purge, buff_flush, buff_prefill, buff_fill, buff_pre_inhale, inhale, pause, exhale}
states_durations _states_durations = {10000, 600, 600, 100, 600, 0, 1200, 10, 1800 };
//durations = {pre_calibration, calibration, buff_purge, buff_flush, buff_prefill, buff_fill, buff_pre_inhale, inhale, pause, exhale}
states_durations _states_durations = {6000, 4000, 600, 600, 100, 600, 0, 1200, 10, 1800 };
states_durations _measured_durations = {0,0,0,0,0,0,0,0,0};
void measureDurations();
void measurePEEP();
......
......@@ -127,6 +127,7 @@ void UILoop::reportReadbackValues()
_readback_data.timestamp = static_cast<uint32_t>(tnow);
states_durations durations = _breathing_loop->getDurations();
_readback_data.duration_pre_calibration = durations.pre_calibration;
_readback_data.duration_calibration = durations.calibration;
_readback_data.duration_buff_purge = durations.buff_purge;
_readback_data.duration_buff_flush = durations.buff_flush;
......
......@@ -5,6 +5,9 @@ SystemUtils* global_sys_utils;
void setDuration(CMD_SET_DURATION cmd, states_durations &durations, float value) {
switch (cmd) {
case CMD_SET_DURATION::PRE_CALIBRATION:
durations.pre_calibration = static_cast<uint32_t>(value);
break;
case CMD_SET_DURATION::CALIBRATION:
durations.calibration = static_cast<uint32_t>(value);
break;
......
......@@ -78,15 +78,16 @@ enum CMD_GENERAL : uint8_t {
// Taken from the FSM doc. Correct as of 1400 on 20200417
enum CMD_SET_DURATION : uint8_t {
CALIBRATION = 1,
BUFF_PURGE = 2,
BUFF_FLUSH = 3,
BUFF_PREFILL = 4,
BUFF_FILL = 5,
BUFF_PRE_INHALE = 6,
INHALE = 7,
PAUSE = 8,
EXHALE = 9
PRE_CALIBRATION = 1,
CALIBRATION = 2,
BUFF_PURGE = 3,
BUFF_FLUSH = 4,
BUFF_PREFILL = 5,
BUFF_FILL = 6,
BUFF_PRE_INHALE = 7,
INHALE = 8,
PAUSE = 9,
EXHALE = 10
};
enum VENTILATION_MODE : uint8_t {
......@@ -244,6 +245,7 @@ struct readback_data_format {
uint8_t version = HEV_FORMAT_VERSION;
uint32_t timestamp = 0;
uint8_t payload_type = PAYLOAD_TYPE::READBACK;
uint16_t duration_pre_calibration = 0;
uint16_t duration_calibration = 0;
uint16_t duration_buff_purge = 0;//
uint16_t duration_buff_flush = 0;
......@@ -446,6 +448,7 @@ struct personal_data_format {
#pragma pack()
struct states_durations {
uint32_t pre_calibration;
uint32_t calibration;
uint32_t buff_purge;
uint32_t buff_flush;
......
......@@ -47,15 +47,16 @@ class CMD_GENERAL(Enum):
# Taken from the FSM doc. Correct as of 1400 on 20200417
@unique
class CMD_SET_DURATION(Enum):
CALIBRATION = 1
BUFF_PURGE = 2
BUFF_FLUSH = 3
BUFF_PREFILL = 4
BUFF_FILL = 5
BUFF_PRE_INHALE = 6
INHALE = 7
PAUSE = 8
EXHALE = 9
PRE_CALIBRATION = 1
CALIBRATION = 2
BUFF_PURGE = 3
BUFF_FLUSH = 4
BUFF_PREFILL = 5
BUFF_FILL = 6
BUFF_PRE_INHALE = 7
INHALE = 8
PAUSE = 9
EXHALE = 10
@unique
class VENTILATION_MODE(Enum):
......@@ -173,17 +174,18 @@ class CMD_MAP(Enum):
class BL_STATES(Enum):
UNKNOWN = 0
IDLE = 1
CALIBRATION = 2
BUFF_PREFILL = 3
BUFF_FILL = 4
BUFF_PRE_INHALE = 5
INHALE = 6
PAUSE = 7
EXHALE = 8
STOP = 9
BUFF_PURGE = 10
BUFF_FLUSH = 11
STANDBY = 12
PRE_CALIBRATION = 2
CALIBRATION = 3
BUFF_PREFILL = 4
BUFF_FILL = 5
BUFF_PRE_INHALE = 6
INHALE = 7
PAUSE = 8
EXHALE = 9
STOP = 10
BUFF_PURGE = 11
BUFF_FLUSH = 12
STANDBY = 13
@unique
class PAYLOAD_TYPE(IntEnum):
......@@ -348,10 +350,11 @@ class DataFormat(PayloadFormat):
# =======================================
@dataclass
class ReadbackFormat(PayloadFormat):
_dataStruct = Struct("<BIBHHHHHHHHHffBBBBBBBBBBBffffffB")
_dataStruct = Struct("<BIBHHHHHHHHHHffBBBBBBBBBBBffffffB")
payload_type: PAYLOAD_TYPE = PAYLOAD_TYPE.READBACK
duration_pre_calibration: int = 0
duration_calibration: int = 0
duration_buff_purge: int = 0
duration_buff_flush: int = 0
......@@ -394,6 +397,7 @@ class ReadbackFormat(PayloadFormat):
(self.version,
self.timestamp,
tmp_payload_type,
self.duration_pre_calibration,
self.duration_calibration,
self.duration_buff_purge,
self.duration_buff_flush,
......
Markdown is supported
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