diff --git a/arduino/breathing_with_comms/src/common.cpp b/arduino/breathing_with_comms/src/common.cpp index bf6e25a47632f80aa8d9ca62dfd87093be43a5b0..26263011273d4c9184aa22280d6a32448b3a0835 100644 --- a/arduino/breathing_with_comms/src/common.cpp +++ b/arduino/breathing_with_comms/src/common.cpp @@ -1,20 +1,32 @@ #include "common.h" -void setValves(bool vin_air, bool vin_o2, bool vinhale, bool vexhale, bool vpurge) +void setValves(bool vin_air, bool vin_o2, bool vinhale, + bool vexhale, bool vpurge, bool vatmos) { - digitalWrite(pin_valve_air_in, vin_air); digitalWrite(pin_valve_o2_in, vin_o2); digitalWrite(pin_valve_inhale, vinhale); digitalWrite(pin_valve_exhale, vexhale); digitalWrite(pin_valve_purge, vpurge); + digitalWrite(pin_valve_atmosphere, vatmos); + + // save the state + bitWrite(valve_port_states, pin_valve_air_in, vin_air); + bitWrite(valve_port_states, pin_valve_o2_in, vin_o2); + bitWrite(valve_port_states, pin_valve_inhale, vinhale); + bitWrite(valve_port_states, pin_valve_exhale, vexhale); + bitWrite(valve_port_states, pin_valve_purge, vpurge); + bitWrite(valve_port_states, pin_valve_atmosphere, vatmos); } -void getValves(bool &vin_air, bool &vin_o2, bool &vinhale, bool &vexhale, bool &vpurge) +void getValves(bool &vin_air, bool &vin_o2, bool &vinhale, + bool &vexhale, bool &vpurge, bool &vatmos) { - vin_air = bitRead(PORTD, pin_valve_air_in); - vin_o2 = bitRead(PORTD, pin_valve_o2_in ); - vinhale = bitRead(PORTD, pin_valve_inhale); - vexhale = bitRead(PORTD, pin_valve_exhale); - vpurge = bitRead(PORTD, pin_valve_purge); + // read the state + vin_air = bitRead(valve_port_states, pin_valve_air_in); + vin_o2 = bitRead(valve_port_states, pin_valve_o2_in ); + vinhale = bitRead(valve_port_states, pin_valve_inhale); + vexhale = bitRead(valve_port_states, pin_valve_exhale); + vpurge = bitRead(valve_port_states, pin_valve_purge); + vatmos = bitRead(valve_port_states, pin_valve_atmosphere); } \ No newline at end of file diff --git a/arduino/breathing_with_comms/src/common.h b/arduino/breathing_with_comms/src/common.h index 2f2234e10e13777c65c4f65c0e2f173824cf3b31..c61edfca56242d15abec8f07c205cb8a1afc7123 100644 --- a/arduino/breathing_with_comms/src/common.h +++ b/arduino/breathing_with_comms/src/common.h @@ -33,10 +33,14 @@ enum hev_modes : byte enum valve_states : bool { - V_OPEN = LOW, - V_CLOSED = HIGH + V_OPEN = HIGH, + V_CLOSED = LOW }; -void setValves(bool vin_air, bool vin_o2, bool vinhale, bool vexhale, bool vpurge); -void getValves(bool &vin_air, bool &vin_o2, bool &vinhale, bool &vexhale, bool &vpurge); +static uint32_t valve_port_states = 0x0; + +void setValves(bool vin_air, bool vin_o2, bool vinhale, + bool vexhale, bool vpurge, bool vatmos); +void getValves(bool &vin_air, bool &vin_o2, bool &vinhale, + bool &vexhale, bool &vpurge, bool &vatmos); diff --git a/arduino/breathing_with_comms/src/main.cpp b/arduino/breathing_with_comms/src/main.cpp index 23dfdc3f141418ed2a47dbed22148c50f0829808..621a77b47892619b5ae10b3ef5e2a67ed2273df6 100644 --- a/arduino/breathing_with_comms/src/main.cpp +++ b/arduino/breathing_with_comms/src/main.cpp @@ -99,13 +99,15 @@ void loop() data.pressure_buffer = analogRead(pin_p_buffer); data.pressure_inhale = analogRead(pin_p_inhale); - bool vin_air, vin_o2, vinhale, vexhale, vpurge; - getValves(vin_air, vin_o2, vinhale, vexhale, vpurge); + bool vin_air, vin_o2, vinhale, vexhale, vpurge, vatmos; + getValves(vin_air, vin_o2, vinhale, vexhale, vpurge, vatmos); data.readback_valve_air_in = vin_air; data.readback_valve_o2_in = vin_o2; data.readback_valve_inhale = vinhale; data.readback_valve_exhale = vexhale; data.readback_valve_purge = vpurge; + // TODO ; add to dataFormat + // data.readback_valve_atmosphere = vpurge; //breath_cycle(); FSM_assignment(); diff --git a/arduino/breathing_with_comms/src/test_hw_loop.cpp b/arduino/breathing_with_comms/src/test_hw_loop.cpp index d1bd1f1598bb88e658020a3842fb8ae134ecc295..2e84c744712b25789c44b47c2d663f6df5786d52 100644 --- a/arduino/breathing_with_comms/src/test_hw_loop.cpp +++ b/arduino/breathing_with_comms/src/test_hw_loop.cpp @@ -104,18 +104,18 @@ void FSM_breath_cycle() } else { timeout = 1000; } - setValves(V_CLOSED, V_CLOSED, V_OPEN, V_OPEN, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_OPEN, V_OPEN, V_CLOSED, V_CLOSED); break; case BS_BUFF_PREFILL: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); timeout = 100; break; case BS_BUFF_FILL: - setValves(V_OPEN, V_OPEN, V_CLOSED, V_OPEN, V_CLOSED); + setValves(V_OPEN, V_OPEN, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); timeout = 1200; break; case BS_BUFF_LOADED: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); switch (lab_cycle_mode) { case LAB_MODE_FLUSH: @@ -131,40 +131,38 @@ void FSM_breath_cycle() } break; case BS_BUFF_PRE_INHALE: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED); timeout = 100; break; case BS_INHALE: - setValves(V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED, V_CLOSED); timeout =1600; break; case BS_PAUSE: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED, V_CLOSED); timeout = 200; break; case BS_EXHALE_FILL: - setValves(V_OPEN, V_OPEN, V_CLOSED, V_OPEN, V_CLOSED); + setValves(V_OPEN, V_OPEN, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); timeout =1200; break; case BS_EXHALE: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_CLOSED, V_CLOSED); timeout = 400; break; case BS_BUFF_PURGE: - setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_OPEN); + setValves(V_CLOSED, V_CLOSED, V_CLOSED, V_OPEN, V_OPEN, V_CLOSED); timeout =1000; break; case BS_BUFF_FLUSH: - setValves(V_CLOSED, V_CLOSED, V_OPEN, V_OPEN, V_CLOSED); + setValves(V_CLOSED, V_CLOSED, V_OPEN, V_OPEN, V_CLOSED, V_CLOSED); timeout =1000; break; - - } // Serial.println("state FSM_breath_cycle: " + String(bs_state)); diff --git a/raspberry-dataserver/commsDebug.py b/raspberry-dataserver/commsDebug.py old mode 100644 new mode 100755 index 5f11a172dc50f4cccc8d3c7d170e9ccfe966458c..47effb6beadd140ddf674c8cc381cd669fda4edd --- a/raspberry-dataserver/commsDebug.py +++ b/raspberry-dataserver/commsDebug.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from commsControl import commsControl import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')