Kabuki Starship / Mbed 2 deprecated GHVentilator

Dependencies:   mbed SickBayTek

Revision:
9:256989faeb3b
Parent:
8:fa5cc1397510
diff -r fa5cc1397510 -r 256989faeb3b GHVentilator.h
--- a/GHVentilator.h	Thu Apr 09 03:18:31 2020 +0000
+++ b/GHVentilator.h	Fri Apr 10 11:56:58 2020 +0000
@@ -17,75 +17,41 @@
   public:
   
   enum {
-    ChannelCountMax = 4,
-    StateCalibrateEnterTicks = -1,
-    StateRunningEnter = 1,
+    StateOff = 0,         //< Both Machine calibrating and off states.
+    StateCalibrate = 0,   //< The Calibrate state where the Tick is 0.
+    StateRising = 1,      //< The Running state first Tick.
+    StateSinking = -1,    //< The Running state first Tick.
+    StatusCodeCount = 1,  //< The number of status codes.
+    ChannelCount = GHVentilatorChannelCount,  //< Number of ventilator channels.
   };
   
+  volatile int Status;    //< The status of the Device.
   // The tick and negative calibrating positive running states.
   volatile int Ticks;
-  int TicksMonitor,       //< The max ticks between the Device monitors.
+  int TicksMonitor,       //< The max ticks between the Device monitor updates.
     TicksSecond,          //< The number of Ticks per Second.
     TicksInhaleMin,       //< The min inhale ticks.
     TicksInhaleMax,       //< The max breath period of 20 seconds.
     TicksExhaleMin,       //< The min ticks in an exhale.
     TicksExhaleMax,       //< The max ticks in an exhale.
-    TicksCalibration,     //< The number of ticks in the calibration state.
-    ChannelsCount;        //< The number of GHVentilatorChannels.
-  GHVentilatorChannel* Channels[ChannelCountMax];
-  BMP280 Atmosphere;      //< Pressure sensor for the air tank.
-  float Temperature,      //< The Temperature in the tank.
-    TemperatureReference, //< The Temperature in the tank.
-    Pressure,             //< The Pressure in the tank.
+    TicksPEEP,            //< The max number of PEEP Ticks before inhaling.
+    TicksCalibration;     //< The number of ticks in the calibration state.
+  int32_t Temperature,    //< The Temperature in the tank.
+    TemperatureReference; //< The Temperature in the tank.
+  uint32_t Pressure,      //< The Pressure in the tank.
     PressureReference,    //< The Pressure when the device is tared.
     PressureMin,          //< The min Pressure.
     PressureMax,          //< The max Pressure.
-    HysteresisChamber,    //< The pressure chamber hystersis +/- percent.
-    HysteresisPatient;    //< The patient Hystersis percent muliplier.
-  DigitalOut Blower,      //< A blower powered by a Solid State Relay.
-             Status;      //< Status pin for outputing the Device status.
-  Ticker UpdateTicker;    //< The x times per second update ticker.
+    HysteresisChamber,    //< The pressure chamber hystersis +/- delta.
+    HysteresisPatient;    //< The patient Hystersis + delta.
+  GHVentilatorChannel Channels[ChannelCount];
   
-  /* Constructs a GHV with 1 channel. */
-  GHVentilator (int TicksPerSecond, int TicksPEEP, int TicksCalibration,
-                I2C& Bus, char BusAddress,
-                float PressureHysteresis,
-                float HysteresisPatient,
-                PinName BlowerPin, PinName StatusPin,
-                GHVentilatorChannel* A);
-      
-  /* Constructs a GHV with 2 channels. */
-  GHVentilator (int TicksPerSecond, int TicksPEEP, int TicksCalibration,
-                I2C& Bus, char BusAddress,
-                float HysteresisChamber,
-                float PressureHysteresis,
-                PinName BlowerPin, PinName StatusPin,
-                GHVentilatorChannel* A,
-                GHVentilatorChannel* B);
-      
-  /* Constructs a GHV with 3 channels. */
-  GHVentilator (int TicksPerSecond, int TicksPEEP, int TicksCalibration,
-                I2C& Bus, char BusAddress,
-                float PressureHysteresis,
-                float HysteresisPatient,
-                PinName BlowerPin, PinName StatusPin,
-                GHVentilatorChannel* A,
-                GHVentilatorChannel* B,
-                GHVentilatorChannel* C);
-      
-  /* Constructs a GHV with 4 channels. */
-  GHVentilator (int TicksPerSecond, int TicksCalibration, int TicksPEEP,
-                I2C& Bus, char BusAddress,
-                float PressureHysteresis,
-                float HysteresisPatient,
-                PinName BlowerPin, PinName StatusPin,
-                GHVentilatorChannel* A,
-                GHVentilatorChannel* B,
-                GHVentilatorChannel* C,
-                GHVentilatorChannel* D);
+  /* Sets some of the varaibles to default requiring a call to Init. */
+  GHVentilator ();
   
-  /* Sets the TicksPEEP given 1/64 second > NewTicksPEEP < 1 second. */
-  void TicksPEEPSet (int NewTicksPEEP);
+  /* Initializes the ventilator with the given values. */
+  void Init (int TicksPerSecond, int TicksCalibration,
+             float PressureHysteresis, float HysteresisPatient);
   
   /* Enters the Calibration State. */
   void StateCalibrateEnter ();
@@ -93,8 +59,29 @@
   /* Enters the Calibration State. */
   void StateCalibrateExit ();
   
-  /* Polls the hardware for changes. */ 
-  void Poll();
+  /* Returns true if the Chamber is over-pressure. */
+  bool IsOverPressure ();
+  
+  /* Returns true if the Chamber is under-pressure. */
+  bool IsUnderPressure ();
+  
+  /* Turns on the blower fan. */
+  void BlowerTurnOn ();
+  
+  /* Turns off the blower fan. */
+  void BlowerTurnOff ();
+  
+  /* Turns the Blower off and sets the Ticks to StateSinking. */
+  void StateSinkingEnter ();
+  
+  /* Turns the Blower On and sets the Ticks to StateRising. */
+  void StateRisingEnter ();
+  
+  /* Sets the TicksPEEP given 1/64 second > NewTicksPEEP < 1 second. */
+  void TicksPEEPSet (int NewTicksPEEP);
+  
+  /* Enters the Off State. */
+  void StateCalibrateOff ();
   
   /* Monitors this Device and it's channels. */
   void Monitor ();
@@ -104,10 +91,6 @@
   
   /* Turns on the Device and all of it's chanels to the Inhale state. */
   void TurnOnAll ();
-
-  /* Gets the GHVentilatorChannel with the given Index. \
-  @return Nil if the Index is out of bounds. */
-  GHVentilatorChannel* Channel(int Index);
   
   /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */
   void Tare(); 
@@ -118,10 +101,30 @@
   /* Starts the system. */   
   void Run ();
   
+  void ChannelValveSet (GHVentilatorChannel* Channel, int Value);
+  
+  /* Sets the Channel 1 solenoid valve to the given Value. */
+  void Channel1ValveSet (int Value);
+  #if GHVentilatorChannelCount >= 2
+  /* Sets the Channel 2 solenoid valve to the given Value. */
+  void Channel2ValveSet (int Value);
+  #endif
+  #if GHVentilatorChannelCount >= 3
+  /* Sets the Channel 3 solenoid valve to the given Value. */
+  void Channel3ValveSet (int Value);
+  #endif
+  #if GHVentilatorChannelCount >= 4
+  /* Sets the Channel 4 solenoid valve to the given Value. */
+  void Channel4ValveSet (int Value);
+  #endif
+  
   /* Updates the main device and it's channels. */
   void Update ();
+  
 };
 
 }   //< namespace SickBay
 #endif
-#undef GHVentilatorChannelsCount
+#undef GHVentilatorChannelCount
+#undef GHVentilatorStateRising
+#undef GHVentilatorStateSinking