Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GHVentilatorChannel.h@2:1578ecfa9377, 2020-04-07 (annotated)
- Committer:
- kabukistarship
- Date:
- Tue Apr 07 13:10:45 2020 +0000
- Revision:
- 2:1578ecfa9377
- Child:
- 3:d15b6579b5ae
Almost finished with the change from Flowerbed to a ventilator.
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:1578ecfa9377 | 22 | volatile int CurrentChannel = -1; |
kabukistarship | 2:1578ecfa9377 | 23 | volatile bool TooMuchAir = false; |
kabukistarship | 2:1578ecfa9377 | 24 | |
kabukistarship | 2:1578ecfa9377 | 25 | namespace SickBay { |
kabukistarship | 2:1578ecfa9377 | 26 | |
kabukistarship | 2:1578ecfa9377 | 27 | /* A Gravity Hookah Ventilator channel for one patient. */ |
kabukistarship | 2:1578ecfa9377 | 28 | class GHVentilatorChannel { |
kabukistarship | 2:1578ecfa9377 | 29 | public: |
kabukistarship | 2:1578ecfa9377 | 30 | |
kabukistarship | 2:1578ecfa9377 | 31 | int Ticks, //< Ticks since the beginning of the inhale. |
kabukistarship | 2:1578ecfa9377 | 32 | TicksInhale, //< The ticks in the inhale duty half-period. |
kabukistarship | 2:1578ecfa9377 | 33 | TicksExhale; //< The period of the breathing. |
kabukistarship | 2:1578ecfa9377 | 34 | volatile int TicksFlowLast, //< The previous saved count. |
kabukistarship | 2:1578ecfa9377 | 35 | TicksFlow; //< Flow sensor pulse count. |
kabukistarship | 2:1578ecfa9377 | 36 | float ReferencePressure, //< The pressure in the mask at one atmosphere. |
kabukistarship | 2:1578ecfa9377 | 37 | ReferenceTemperature; //< The refernce temperature. |
kabukistarship | 2:1578ecfa9377 | 38 | BMP280 Atmosphere; //< The air Atmosphere going to the patient. |
kabukistarship | 2:1578ecfa9377 | 39 | InterruptIn Sensor; //< The flow sensor pin. |
kabukistarship | 2:1578ecfa9377 | 40 | DigitalOut Valve, //< The Solenoid valve. |
kabukistarship | 2:1578ecfa9377 | 41 | Status; //< The Status LED and optional alarm. |
kabukistarship | 2:1578ecfa9377 | 42 | PwmOut Servo; //< The Servo for reducing the pressrue. |
kabukistarship | 2:1578ecfa9377 | 43 | AnalogIn PulseOximeter; //< The PulseOximeterentiometer pin. |
kabukistarship | 2:1578ecfa9377 | 44 | |
kabukistarship | 2:1578ecfa9377 | 45 | /* Constructs a smart waterer. */ |
kabukistarship | 2:1578ecfa9377 | 46 | GHVentilatorChannel (PinName SensorPin, |
kabukistarship | 2:1578ecfa9377 | 47 | PinName PulseOximeterPin, |
kabukistarship | 2:1578ecfa9377 | 48 | PinName SolenoidPin, |
kabukistarship | 2:1578ecfa9377 | 49 | PinName StatusPin, |
kabukistarship | 2:1578ecfa9377 | 50 | PinName ServoPin, |
kabukistarship | 2:1578ecfa9377 | 51 | I2C& I2CBus, char I2CAddress); |
kabukistarship | 2:1578ecfa9377 | 52 | |
kabukistarship | 2:1578ecfa9377 | 53 | /* Returns a pointer to this. */ |
kabukistarship | 2:1578ecfa9377 | 54 | GHVentilatorChannel* This(); |
kabukistarship | 2:1578ecfa9377 | 55 | |
kabukistarship | 2:1578ecfa9377 | 56 | /* Sets the Breath period in seconds. */ |
kabukistarship | 2:1578ecfa9377 | 57 | void BreathPeriodSet(float Period); |
kabukistarship | 2:1578ecfa9377 | 58 | |
kabukistarship | 2:1578ecfa9377 | 59 | /* Sets the Breath duty cycle between a 1-to-1 and 1-to-3 ratio. */ |
kabukistarship | 2:1578ecfa9377 | 60 | void DutyCycleSet(float Period); |
kabukistarship | 2:1578ecfa9377 | 61 | |
kabukistarship | 2:1578ecfa9377 | 62 | /* BreatheStarts to the begining of the watering cycle. */ |
kabukistarship | 2:1578ecfa9377 | 63 | void BreatheStart (int Index); |
kabukistarship | 2:1578ecfa9377 | 64 | |
kabukistarship | 2:1578ecfa9377 | 65 | /* Increments theflow rate sensor pulse counter. */ |
kabukistarship | 2:1578ecfa9377 | 66 | void PulseFlowSensor (); |
kabukistarship | 2:1578ecfa9377 | 67 | |
kabukistarship | 2:1578ecfa9377 | 68 | /* Prints the state of object to the debug stream. */ |
kabukistarship | 2:1578ecfa9377 | 69 | void Print (int Index); |
kabukistarship | 2:1578ecfa9377 | 70 | |
kabukistarship | 2:1578ecfa9377 | 71 | /* Polls the PulseOximeter and updates the target flow. */ |
kabukistarship | 2:1578ecfa9377 | 72 | void Update (int Index); |
kabukistarship | 2:1578ecfa9377 | 73 | |
kabukistarship | 2:1578ecfa9377 | 74 | /* Updates the float rate. */ |
kabukistarship | 2:1578ecfa9377 | 75 | bool CheckIfDoneBreathing (int Index); |
kabukistarship | 2:1578ecfa9377 | 76 | |
kabukistarship | 2:1578ecfa9377 | 77 | /* Opens the solenoid valve. */ |
kabukistarship | 2:1578ecfa9377 | 78 | void Inhale (); |
kabukistarship | 2:1578ecfa9377 | 79 | |
kabukistarship | 2:1578ecfa9377 | 80 | /* Closes the solenoid valve. */ |
kabukistarship | 2:1578ecfa9377 | 81 | void Exhale (); |
kabukistarship | 2:1578ecfa9377 | 82 | |
kabukistarship | 2:1578ecfa9377 | 83 | /* Samples the Atmospheric pressure and temperature. */ |
kabukistarship | 2:1578ecfa9377 | 84 | void Tare (); |
kabukistarship | 2:1578ecfa9377 | 85 | |
kabukistarship | 2:1578ecfa9377 | 86 | /* Updates the channel with the DeviceTick. */ |
kabukistarship | 2:1578ecfa9377 | 87 | void Update(); |
kabukistarship | 2:1578ecfa9377 | 88 | |
kabukistarship | 2:1578ecfa9377 | 89 | private: |
kabukistarship | 2:1578ecfa9377 | 90 | |
kabukistarship | 2:1578ecfa9377 | 91 | /* Calculates the pulse target value from the PulseOximeter value. */ |
kabukistarship | 2:1578ecfa9377 | 92 | inline int CalcPulseTarget (); |
kabukistarship | 2:1578ecfa9377 | 93 | }; |
kabukistarship | 2:1578ecfa9377 | 94 | } //< namespace SickBay |
kabukistarship | 2:1578ecfa9377 | 95 | #endif //< GHVentilatorChannelDecl |