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.
GHVentilator.h@6:b2672da545f1, 2020-04-09 (annotated)
- Committer:
- kabukistarship
- Date:
- Thu Apr 09 02:05:03 2020 +0000
- Revision:
- 6:b2672da545f1
- Parent:
- 5:da629056644f
- Child:
- 8:fa5cc1397510
Detail.GHVentilator.Firmware.Mbed.Move BMP280 polling code into main loop; States.Add PEEP state. #67
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 | 3:d15b6579b5ae | 2 | @link https://github.com/KabukiStarship/SickBay.git |
kabukistarship | 3:d15b6579b5ae | 3 | @file /GHVentilator.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 | #pragma once |
kabukistarship | 2:1578ecfa9377 | 10 | #ifndef GHVentilatorDecl |
kabukistarship | 2:1578ecfa9377 | 11 | #define GHVentilatorDecl |
kabukistarship | 2:1578ecfa9377 | 12 | #include "GHVentilatorChannel.h" |
kabukistarship | 2:1578ecfa9377 | 13 | namespace SickBay { |
kabukistarship | 2:1578ecfa9377 | 14 | |
kabukistarship | 2:1578ecfa9377 | 15 | /* A Gravity Hookah Ventilator. */ |
kabukistarship | 2:1578ecfa9377 | 16 | class GHVentilator { |
kabukistarship | 3:d15b6579b5ae | 17 | public: |
kabukistarship | 3:d15b6579b5ae | 18 | |
kabukistarship | 3:d15b6579b5ae | 19 | enum { |
kabukistarship | 3:d15b6579b5ae | 20 | ChannelCountMax = 4, |
kabukistarship | 6:b2672da545f1 | 21 | StateCalibrateEnterTicks = -1, |
kabukistarship | 6:b2672da545f1 | 22 | StateRunningEnter = 1, |
kabukistarship | 3:d15b6579b5ae | 23 | }; |
kabukistarship | 3:d15b6579b5ae | 24 | |
kabukistarship | 3:d15b6579b5ae | 25 | // The tick and negative calibrating positive running states. |
kabukistarship | 6:b2672da545f1 | 26 | volatile int Ticks; |
kabukistarship | 6:b2672da545f1 | 27 | int TicksMonitor, //< The max ticks between the Device monitors. |
kabukistarship | 6:b2672da545f1 | 28 | TicksSecond, //< The number of Ticks per Second. |
kabukistarship | 6:b2672da545f1 | 29 | TicksInhaleMin, //< The min inhale ticks. |
kabukistarship | 6:b2672da545f1 | 30 | TicksInhaleMax, //< The max breath period of 20 seconds. |
kabukistarship | 6:b2672da545f1 | 31 | TicksExhaleMin, //< The min ticks in an exhale. |
kabukistarship | 6:b2672da545f1 | 32 | TicksExhaleMax, //< The max ticks in an exhale. |
kabukistarship | 6:b2672da545f1 | 33 | TicksCalibration, //< The number of ticks in the calibration state. |
kabukistarship | 6:b2672da545f1 | 34 | ChannelsCount; //< The number of GHVentilatorChannels. |
kabukistarship | 4:de69851cf725 | 35 | GHVentilatorChannel* Channels[ChannelCountMax]; |
kabukistarship | 6:b2672da545f1 | 36 | BMP280 Atmosphere; //< Pressure sensor for the air tank. |
kabukistarship | 6:b2672da545f1 | 37 | float Temperature, //< The Temperature in the tank. |
kabukistarship | 6:b2672da545f1 | 38 | TemperatureReference, //< The Temperature in the tank. |
kabukistarship | 6:b2672da545f1 | 39 | Pressure, //< The Pressure in the tank. |
kabukistarship | 6:b2672da545f1 | 40 | PressureReference, //< The Pressure when the device is tared. |
kabukistarship | 6:b2672da545f1 | 41 | PressureMin, //< The min Pressure. |
kabukistarship | 6:b2672da545f1 | 42 | PressureMax, //< The max Pressure. |
kabukistarship | 6:b2672da545f1 | 43 | HysteresisChamber, //< The pressure chamber hystersis +/- percent. |
kabukistarship | 6:b2672da545f1 | 44 | HysteresisPatient; //< The patient Hystersis percent muliplier. |
kabukistarship | 6:b2672da545f1 | 45 | DigitalOut Blower, //< A blower powered by a Solid State Relay. |
kabukistarship | 6:b2672da545f1 | 46 | Status; //< Status pin for outputing the Device status. |
kabukistarship | 6:b2672da545f1 | 47 | Ticker UpdateTicker; //< The x times per second update ticker. |
kabukistarship | 3:d15b6579b5ae | 48 | |
kabukistarship | 4:de69851cf725 | 49 | /* Constructs a GHV with 1 channel. */ |
kabukistarship | 3:d15b6579b5ae | 50 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 6:b2672da545f1 | 51 | I2C& Bus, char BusAddress, |
kabukistarship | 4:de69851cf725 | 52 | float PressureHysteresis, |
kabukistarship | 5:da629056644f | 53 | float HysteresisPatient, |
kabukistarship | 4:de69851cf725 | 54 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 4:de69851cf725 | 55 | GHVentilatorChannel* A); |
kabukistarship | 3:d15b6579b5ae | 56 | |
kabukistarship | 4:de69851cf725 | 57 | /* Constructs a GHV with 2 channels. */ |
kabukistarship | 3:d15b6579b5ae | 58 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 6:b2672da545f1 | 59 | I2C& Bus, char BusAddress, |
kabukistarship | 5:da629056644f | 60 | float HysteresisChamber, |
kabukistarship | 4:de69851cf725 | 61 | float PressureHysteresis, |
kabukistarship | 4:de69851cf725 | 62 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 4:de69851cf725 | 63 | GHVentilatorChannel* A, |
kabukistarship | 4:de69851cf725 | 64 | GHVentilatorChannel* B); |
kabukistarship | 3:d15b6579b5ae | 65 | |
kabukistarship | 4:de69851cf725 | 66 | /* Constructs a GHV with 3 channels. */ |
kabukistarship | 3:d15b6579b5ae | 67 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 6:b2672da545f1 | 68 | I2C& Bus, char BusAddress, |
kabukistarship | 4:de69851cf725 | 69 | float PressureHysteresis, |
kabukistarship | 5:da629056644f | 70 | float HysteresisPatient, |
kabukistarship | 4:de69851cf725 | 71 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 4:de69851cf725 | 72 | GHVentilatorChannel* A, |
kabukistarship | 4:de69851cf725 | 73 | GHVentilatorChannel* B, |
kabukistarship | 4:de69851cf725 | 74 | GHVentilatorChannel* C); |
kabukistarship | 3:d15b6579b5ae | 75 | |
kabukistarship | 4:de69851cf725 | 76 | /* Constructs a GHV with 4 channels. */ |
kabukistarship | 4:de69851cf725 | 77 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 6:b2672da545f1 | 78 | I2C& Bus, char BusAddress, |
kabukistarship | 4:de69851cf725 | 79 | float PressureHysteresis, |
kabukistarship | 5:da629056644f | 80 | float HysteresisPatient, |
kabukistarship | 4:de69851cf725 | 81 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 4:de69851cf725 | 82 | GHVentilatorChannel* A, |
kabukistarship | 4:de69851cf725 | 83 | GHVentilatorChannel* B, |
kabukistarship | 4:de69851cf725 | 84 | GHVentilatorChannel* C, |
kabukistarship | 4:de69851cf725 | 85 | GHVentilatorChannel* D); |
kabukistarship | 6:b2672da545f1 | 86 | |
kabukistarship | 6:b2672da545f1 | 87 | /* Enters the Calibration State. */ |
kabukistarship | 6:b2672da545f1 | 88 | void StateCalibrateEnter (); |
kabukistarship | 6:b2672da545f1 | 89 | |
kabukistarship | 6:b2672da545f1 | 90 | /* Enters the Calibration State. */ |
kabukistarship | 6:b2672da545f1 | 91 | void StateCalibrateExit (); |
kabukistarship | 6:b2672da545f1 | 92 | |
kabukistarship | 6:b2672da545f1 | 93 | /* Polls the hardware for changes. */ |
kabukistarship | 6:b2672da545f1 | 94 | void Poll(); |
kabukistarship | 6:b2672da545f1 | 95 | |
kabukistarship | 6:b2672da545f1 | 96 | /* Monitors this Device and it's channels. */ |
kabukistarship | 6:b2672da545f1 | 97 | void Monitor (); |
kabukistarship | 6:b2672da545f1 | 98 | |
kabukistarship | 6:b2672da545f1 | 99 | /* Turns off the Device and all of it's chanels. */ |
kabukistarship | 6:b2672da545f1 | 100 | void TurnOff (); |
kabukistarship | 6:b2672da545f1 | 101 | |
kabukistarship | 6:b2672da545f1 | 102 | /* Turns on the Device and all of it's chanels to the Inhale state. */ |
kabukistarship | 6:b2672da545f1 | 103 | void TurnOnAll (); |
kabukistarship | 3:d15b6579b5ae | 104 | |
kabukistarship | 3:d15b6579b5ae | 105 | /* Gets the GHVentilatorChannel with the given Index. \ |
kabukistarship | 3:d15b6579b5ae | 106 | @return Nil if the Index is out of bounds. */ |
kabukistarship | 3:d15b6579b5ae | 107 | GHVentilatorChannel* Channel(int Index); |
kabukistarship | 4:de69851cf725 | 108 | |
kabukistarship | 3:d15b6579b5ae | 109 | /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ |
kabukistarship | 5:da629056644f | 110 | void Tare(); |
kabukistarship | 3:d15b6579b5ae | 111 | |
kabukistarship | 4:de69851cf725 | 112 | /* Sets the inhale and exhale ticks for the give channel Index. */ |
kabukistarship | 4:de69851cf725 | 113 | int TicksInhaleExhaleSet (int Index, int TicksInhale, int TicksExhale); |
kabukistarship | 3:d15b6579b5ae | 114 | |
kabukistarship | 3:d15b6579b5ae | 115 | /* Starts the system. */ |
kabukistarship | 4:de69851cf725 | 116 | void Run (); |
kabukistarship | 3:d15b6579b5ae | 117 | |
kabukistarship | 3:d15b6579b5ae | 118 | /* Updates the main device and it's channels. */ |
kabukistarship | 3:d15b6579b5ae | 119 | void Update (); |
kabukistarship | 2:1578ecfa9377 | 120 | }; |
kabukistarship | 2:1578ecfa9377 | 121 | |
kabukistarship | 2:1578ecfa9377 | 122 | } //< namespace SickBay |
kabukistarship | 2:1578ecfa9377 | 123 | #endif |
kabukistarship | 4:de69851cf725 | 124 | #undef GHVentilatorChannelsCount |