Kabuki Starship / Mbed 2 deprecated GHVentilator

Dependencies:   mbed SickBayTek

Committer:
kabukistarship
Date:
Wed Apr 08 07:16:51 2020 +0000
Revision:
3:d15b6579b5ae
Parent:
2:1578ecfa9377
Child:
4:de69851cf725
Updates from PandemicCookbook#75

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kabukistarship 2:1578ecfa9377 1 /** Gravity Hookah Ventilator @version 0.x
kabukistarship 2:1578ecfa9377 2 @link https://github.com/KabukiStarship/SickBay.git
kabukistarship 2:1578ecfa9377 3 @file /GHVentilatorChannel.h
kabukistarship 2:1578ecfa9377 4 @author Cale McCollough <https://cale-mccollough.github.io>
kabukistarship 2:1578ecfa9377 5 @license Copyright 2020 (C) Kabuki Starship <kabukistarship.com>.
kabukistarship 2:1578ecfa9377 6 This Source Code Form is subject to the terms of the Mozilla Public License,
kabukistarship 2:1578ecfa9377 7 v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain
kabukistarship 2:1578ecfa9377 8 one at <https://mozilla.org/MPL/2.0/>. */
kabukistarship 2:1578ecfa9377 9
kabukistarship 2:1578ecfa9377 10 #pragma once
kabukistarship 2:1578ecfa9377 11 #ifndef GHVentilatorChannelDecl
kabukistarship 2:1578ecfa9377 12 #define GHVentilatorChannelDecl
kabukistarship 2:1578ecfa9377 13 #include <mbedBug.h>
kabukistarship 2:1578ecfa9377 14 using namespace mbedBug;
kabukistarship 2:1578ecfa9377 15 #include "GHVentilatorConfig.h"
kabukistarship 2:1578ecfa9377 16 #include "BMP280.h"
kabukistarship 2:1578ecfa9377 17
kabukistarship 2:1578ecfa9377 18 #ifndef GHVentilatorChannelsCount
kabukistarship 2:1578ecfa9377 19 #define GHVentilatorChannelsCount 1
kabukistarship 2:1578ecfa9377 20 #endif
kabukistarship 2:1578ecfa9377 21
kabukistarship 3:d15b6579b5ae 22 #define GHVentilatorPressureHysteresis 0.000001f
kabukistarship 3:d15b6579b5ae 23 #define GHVentilatorPressureTemperature 0.000001f
kabukistarship 3:d15b6579b5ae 24
kabukistarship 2:1578ecfa9377 25 volatile int CurrentChannel = -1;
kabukistarship 2:1578ecfa9377 26 volatile bool TooMuchAir = false;
kabukistarship 2:1578ecfa9377 27
kabukistarship 2:1578ecfa9377 28 namespace SickBay {
kabukistarship 2:1578ecfa9377 29
kabukistarship 2:1578ecfa9377 30 /* A Gravity Hookah Ventilator channel for one patient. */
kabukistarship 2:1578ecfa9377 31 class GHVentilatorChannel {
kabukistarship 2:1578ecfa9377 32 public:
kabukistarship 2:1578ecfa9377 33
kabukistarship 2:1578ecfa9377 34 int Ticks, //< Ticks since the beginning of the inhale.
kabukistarship 2:1578ecfa9377 35 TicksInhale, //< The ticks in the inhale duty half-period.
kabukistarship 2:1578ecfa9377 36 TicksExhale; //< The period of the breathing.
kabukistarship 2:1578ecfa9377 37 volatile int TicksFlowLast, //< The previous saved count.
kabukistarship 3:d15b6579b5ae 38 TicksFlow; //< Flow sensor pulse count.
kabukistarship 3:d15b6579b5ae 39 int TicksFlowInhale, //< Number of flow sensor ticks on the last exhale.
kabukistarship 3:d15b6579b5ae 40 ServoClosed, //< The min servo duty cycle of no air flow.
kabukistarship 3:d15b6579b5ae 41 ServoOpen; //< The max servo duty cycle of an open tube.
kabukistarship 2:1578ecfa9377 42 float ReferencePressure, //< The pressure in the mask at one atmosphere.
kabukistarship 3:d15b6579b5ae 43 ReferenceTemperature; //< The refernce temperature,
kabukistarship 2:1578ecfa9377 44 BMP280 Atmosphere; //< The air Atmosphere going to the patient.
kabukistarship 2:1578ecfa9377 45 InterruptIn Sensor; //< The flow sensor pin.
kabukistarship 2:1578ecfa9377 46 DigitalOut Valve, //< The Solenoid valve.
kabukistarship 2:1578ecfa9377 47 Status; //< The Status LED and optional alarm.
kabukistarship 2:1578ecfa9377 48 PwmOut Servo; //< The Servo for reducing the pressrue.
kabukistarship 2:1578ecfa9377 49 AnalogIn PulseOximeter; //< The PulseOximeterentiometer pin.
kabukistarship 2:1578ecfa9377 50
kabukistarship 2:1578ecfa9377 51 /* Constructs a smart waterer. */
kabukistarship 2:1578ecfa9377 52 GHVentilatorChannel (PinName SensorPin,
kabukistarship 2:1578ecfa9377 53 PinName PulseOximeterPin,
kabukistarship 2:1578ecfa9377 54 PinName SolenoidPin,
kabukistarship 2:1578ecfa9377 55 PinName StatusPin,
kabukistarship 2:1578ecfa9377 56 PinName ServoPin,
kabukistarship 2:1578ecfa9377 57 I2C& I2CBus, char I2CAddress);
kabukistarship 2:1578ecfa9377 58
kabukistarship 2:1578ecfa9377 59 /* Returns a pointer to this. */
kabukistarship 2:1578ecfa9377 60 GHVentilatorChannel* This();
kabukistarship 2:1578ecfa9377 61
kabukistarship 3:d15b6579b5ae 62 /* Sets the number of ticks on the inhale and exhale. */
kabukistarship 3:d15b6579b5ae 63 void TicksInhaleExhaleSet (int NewTicksInhale, int NewTicksExhale);
kabukistarship 2:1578ecfa9377 64
kabukistarship 2:1578ecfa9377 65 /* BreatheStarts to the begining of the watering cycle. */
kabukistarship 2:1578ecfa9377 66 void BreatheStart (int Index);
kabukistarship 2:1578ecfa9377 67
kabukistarship 2:1578ecfa9377 68 /* Increments theflow rate sensor pulse counter. */
kabukistarship 2:1578ecfa9377 69 void PulseFlowSensor ();
kabukistarship 2:1578ecfa9377 70
kabukistarship 2:1578ecfa9377 71 /* Prints the state of object to the debug stream. */
kabukistarship 2:1578ecfa9377 72 void Print (int Index);
kabukistarship 2:1578ecfa9377 73
kabukistarship 2:1578ecfa9377 74 /* Polls the PulseOximeter and updates the target flow. */
kabukistarship 2:1578ecfa9377 75 void Update (int Index);
kabukistarship 2:1578ecfa9377 76
kabukistarship 2:1578ecfa9377 77 /* Updates the float rate. */
kabukistarship 2:1578ecfa9377 78 bool CheckIfDoneBreathing (int Index);
kabukistarship 2:1578ecfa9377 79
kabukistarship 2:1578ecfa9377 80 /* Opens the solenoid valve. */
kabukistarship 2:1578ecfa9377 81 void Inhale ();
kabukistarship 2:1578ecfa9377 82
kabukistarship 2:1578ecfa9377 83 /* Closes the solenoid valve. */
kabukistarship 2:1578ecfa9377 84 void Exhale ();
kabukistarship 2:1578ecfa9377 85
kabukistarship 3:d15b6579b5ae 86 /* Handles any errors. */
kabukistarship 3:d15b6579b5ae 87 void HandleError ();
kabukistarship 3:d15b6579b5ae 88
kabukistarship 2:1578ecfa9377 89 /* Samples the Atmospheric pressure and temperature. */
kabukistarship 2:1578ecfa9377 90 void Tare ();
kabukistarship 2:1578ecfa9377 91
kabukistarship 2:1578ecfa9377 92 /* Updates the channel with the DeviceTick. */
kabukistarship 2:1578ecfa9377 93 void Update();
kabukistarship 2:1578ecfa9377 94
kabukistarship 2:1578ecfa9377 95 private:
kabukistarship 2:1578ecfa9377 96
kabukistarship 2:1578ecfa9377 97 /* Calculates the pulse target value from the PulseOximeter value. */
kabukistarship 2:1578ecfa9377 98 inline int CalcPulseTarget ();
kabukistarship 2:1578ecfa9377 99 };
kabukistarship 2:1578ecfa9377 100 } //< namespace SickBay
kabukistarship 2:1578ecfa9377 101 #endif //< GHVentilatorChannelDecl