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@9:256989faeb3b, 2020-04-10 (annotated)
- Committer:
- kabukistarship
- Date:
- Fri Apr 10 11:56:58 2020 +0000
- Revision:
- 9:256989faeb3b
- Parent:
- 8:fa5cc1397510
Change.GHVentilator.Firmware.Switch to Arduino and mbed compatible format. #74
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 | 9:256989faeb3b | 20 | StateOff = 0, //< Both Machine calibrating and off states. |
kabukistarship | 9:256989faeb3b | 21 | StateCalibrate = 0, //< The Calibrate state where the Tick is 0. |
kabukistarship | 9:256989faeb3b | 22 | StateRising = 1, //< The Running state first Tick. |
kabukistarship | 9:256989faeb3b | 23 | StateSinking = -1, //< The Running state first Tick. |
kabukistarship | 9:256989faeb3b | 24 | StatusCodeCount = 1, //< The number of status codes. |
kabukistarship | 9:256989faeb3b | 25 | ChannelCount = GHVentilatorChannelCount, //< Number of ventilator channels. |
kabukistarship | 3:d15b6579b5ae | 26 | }; |
kabukistarship | 3:d15b6579b5ae | 27 | |
kabukistarship | 9:256989faeb3b | 28 | volatile int Status; //< The status of the Device. |
kabukistarship | 3:d15b6579b5ae | 29 | // The tick and negative calibrating positive running states. |
kabukistarship | 6:b2672da545f1 | 30 | volatile int Ticks; |
kabukistarship | 9:256989faeb3b | 31 | int TicksMonitor, //< The max ticks between the Device monitor updates. |
kabukistarship | 6:b2672da545f1 | 32 | TicksSecond, //< The number of Ticks per Second. |
kabukistarship | 6:b2672da545f1 | 33 | TicksInhaleMin, //< The min inhale ticks. |
kabukistarship | 6:b2672da545f1 | 34 | TicksInhaleMax, //< The max breath period of 20 seconds. |
kabukistarship | 6:b2672da545f1 | 35 | TicksExhaleMin, //< The min ticks in an exhale. |
kabukistarship | 6:b2672da545f1 | 36 | TicksExhaleMax, //< The max ticks in an exhale. |
kabukistarship | 9:256989faeb3b | 37 | TicksPEEP, //< The max number of PEEP Ticks before inhaling. |
kabukistarship | 9:256989faeb3b | 38 | TicksCalibration; //< The number of ticks in the calibration state. |
kabukistarship | 9:256989faeb3b | 39 | int32_t Temperature, //< The Temperature in the tank. |
kabukistarship | 9:256989faeb3b | 40 | TemperatureReference; //< The Temperature in the tank. |
kabukistarship | 9:256989faeb3b | 41 | uint32_t Pressure, //< The Pressure in the tank. |
kabukistarship | 6:b2672da545f1 | 42 | PressureReference, //< The Pressure when the device is tared. |
kabukistarship | 6:b2672da545f1 | 43 | PressureMin, //< The min Pressure. |
kabukistarship | 6:b2672da545f1 | 44 | PressureMax, //< The max Pressure. |
kabukistarship | 9:256989faeb3b | 45 | HysteresisChamber, //< The pressure chamber hystersis +/- delta. |
kabukistarship | 9:256989faeb3b | 46 | HysteresisPatient; //< The patient Hystersis + delta. |
kabukistarship | 9:256989faeb3b | 47 | GHVentilatorChannel Channels[ChannelCount]; |
kabukistarship | 3:d15b6579b5ae | 48 | |
kabukistarship | 9:256989faeb3b | 49 | /* Sets some of the varaibles to default requiring a call to Init. */ |
kabukistarship | 9:256989faeb3b | 50 | GHVentilator (); |
kabukistarship | 6:b2672da545f1 | 51 | |
kabukistarship | 9:256989faeb3b | 52 | /* Initializes the ventilator with the given values. */ |
kabukistarship | 9:256989faeb3b | 53 | void Init (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 9:256989faeb3b | 54 | float PressureHysteresis, float HysteresisPatient); |
kabukistarship | 8:fa5cc1397510 | 55 | |
kabukistarship | 6:b2672da545f1 | 56 | /* Enters the Calibration State. */ |
kabukistarship | 6:b2672da545f1 | 57 | void StateCalibrateEnter (); |
kabukistarship | 6:b2672da545f1 | 58 | |
kabukistarship | 6:b2672da545f1 | 59 | /* Enters the Calibration State. */ |
kabukistarship | 6:b2672da545f1 | 60 | void StateCalibrateExit (); |
kabukistarship | 6:b2672da545f1 | 61 | |
kabukistarship | 9:256989faeb3b | 62 | /* Returns true if the Chamber is over-pressure. */ |
kabukistarship | 9:256989faeb3b | 63 | bool IsOverPressure (); |
kabukistarship | 9:256989faeb3b | 64 | |
kabukistarship | 9:256989faeb3b | 65 | /* Returns true if the Chamber is under-pressure. */ |
kabukistarship | 9:256989faeb3b | 66 | bool IsUnderPressure (); |
kabukistarship | 9:256989faeb3b | 67 | |
kabukistarship | 9:256989faeb3b | 68 | /* Turns on the blower fan. */ |
kabukistarship | 9:256989faeb3b | 69 | void BlowerTurnOn (); |
kabukistarship | 9:256989faeb3b | 70 | |
kabukistarship | 9:256989faeb3b | 71 | /* Turns off the blower fan. */ |
kabukistarship | 9:256989faeb3b | 72 | void BlowerTurnOff (); |
kabukistarship | 9:256989faeb3b | 73 | |
kabukistarship | 9:256989faeb3b | 74 | /* Turns the Blower off and sets the Ticks to StateSinking. */ |
kabukistarship | 9:256989faeb3b | 75 | void StateSinkingEnter (); |
kabukistarship | 9:256989faeb3b | 76 | |
kabukistarship | 9:256989faeb3b | 77 | /* Turns the Blower On and sets the Ticks to StateRising. */ |
kabukistarship | 9:256989faeb3b | 78 | void StateRisingEnter (); |
kabukistarship | 9:256989faeb3b | 79 | |
kabukistarship | 9:256989faeb3b | 80 | /* Sets the TicksPEEP given 1/64 second > NewTicksPEEP < 1 second. */ |
kabukistarship | 9:256989faeb3b | 81 | void TicksPEEPSet (int NewTicksPEEP); |
kabukistarship | 9:256989faeb3b | 82 | |
kabukistarship | 9:256989faeb3b | 83 | /* Enters the Off State. */ |
kabukistarship | 9:256989faeb3b | 84 | void StateCalibrateOff (); |
kabukistarship | 6:b2672da545f1 | 85 | |
kabukistarship | 6:b2672da545f1 | 86 | /* Monitors this Device and it's channels. */ |
kabukistarship | 6:b2672da545f1 | 87 | void Monitor (); |
kabukistarship | 6:b2672da545f1 | 88 | |
kabukistarship | 6:b2672da545f1 | 89 | /* Turns off the Device and all of it's chanels. */ |
kabukistarship | 6:b2672da545f1 | 90 | void TurnOff (); |
kabukistarship | 6:b2672da545f1 | 91 | |
kabukistarship | 6:b2672da545f1 | 92 | /* Turns on the Device and all of it's chanels to the Inhale state. */ |
kabukistarship | 6:b2672da545f1 | 93 | void TurnOnAll (); |
kabukistarship | 4:de69851cf725 | 94 | |
kabukistarship | 3:d15b6579b5ae | 95 | /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ |
kabukistarship | 5:da629056644f | 96 | void Tare(); |
kabukistarship | 3:d15b6579b5ae | 97 | |
kabukistarship | 4:de69851cf725 | 98 | /* Sets the inhale and exhale ticks for the give channel Index. */ |
kabukistarship | 4:de69851cf725 | 99 | int TicksInhaleExhaleSet (int Index, int TicksInhale, int TicksExhale); |
kabukistarship | 3:d15b6579b5ae | 100 | |
kabukistarship | 3:d15b6579b5ae | 101 | /* Starts the system. */ |
kabukistarship | 4:de69851cf725 | 102 | void Run (); |
kabukistarship | 3:d15b6579b5ae | 103 | |
kabukistarship | 9:256989faeb3b | 104 | void ChannelValveSet (GHVentilatorChannel* Channel, int Value); |
kabukistarship | 9:256989faeb3b | 105 | |
kabukistarship | 9:256989faeb3b | 106 | /* Sets the Channel 1 solenoid valve to the given Value. */ |
kabukistarship | 9:256989faeb3b | 107 | void Channel1ValveSet (int Value); |
kabukistarship | 9:256989faeb3b | 108 | #if GHVentilatorChannelCount >= 2 |
kabukistarship | 9:256989faeb3b | 109 | /* Sets the Channel 2 solenoid valve to the given Value. */ |
kabukistarship | 9:256989faeb3b | 110 | void Channel2ValveSet (int Value); |
kabukistarship | 9:256989faeb3b | 111 | #endif |
kabukistarship | 9:256989faeb3b | 112 | #if GHVentilatorChannelCount >= 3 |
kabukistarship | 9:256989faeb3b | 113 | /* Sets the Channel 3 solenoid valve to the given Value. */ |
kabukistarship | 9:256989faeb3b | 114 | void Channel3ValveSet (int Value); |
kabukistarship | 9:256989faeb3b | 115 | #endif |
kabukistarship | 9:256989faeb3b | 116 | #if GHVentilatorChannelCount >= 4 |
kabukistarship | 9:256989faeb3b | 117 | /* Sets the Channel 4 solenoid valve to the given Value. */ |
kabukistarship | 9:256989faeb3b | 118 | void Channel4ValveSet (int Value); |
kabukistarship | 9:256989faeb3b | 119 | #endif |
kabukistarship | 9:256989faeb3b | 120 | |
kabukistarship | 3:d15b6579b5ae | 121 | /* Updates the main device and it's channels. */ |
kabukistarship | 3:d15b6579b5ae | 122 | void Update (); |
kabukistarship | 9:256989faeb3b | 123 | |
kabukistarship | 2:1578ecfa9377 | 124 | }; |
kabukistarship | 2:1578ecfa9377 | 125 | |
kabukistarship | 2:1578ecfa9377 | 126 | } //< namespace SickBay |
kabukistarship | 2:1578ecfa9377 | 127 | #endif |
kabukistarship | 9:256989faeb3b | 128 | #undef GHVentilatorChannelCount |
kabukistarship | 9:256989faeb3b | 129 | #undef GHVentilatorStateRising |
kabukistarship | 9:256989faeb3b | 130 | #undef GHVentilatorStateSinking |