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.
SBVentilator.h@1:278bfa29bd0d, 2020-04-11 (annotated)
- Committer:
- kabukistarship
- Date:
- Sat Apr 11 08:48:12 2020 +0000
- Revision:
- 1:278bfa29bd0d
- Parent:
- 0:7319afbc731c
Detail.Tek.Describe The SickBay Device firmware toolkit built with Kabuki Tek. #76
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kabukistarship | 0:7319afbc731c | 1 | /** SickBay Tek @version 0.x |
kabukistarship | 0:7319afbc731c | 2 | @link https://github.com/KabukiStarship/SickBay.git |
kabukistarship | 0:7319afbc731c | 3 | @file /SBVentilator.h |
kabukistarship | 0:7319afbc731c | 4 | @author Cale McCollough <https://cale-mccollough.github.io> |
kabukistarship | 0:7319afbc731c | 5 | @license Copyright 2020 (C) Kabuki Starship <kabukistarship.com>. |
kabukistarship | 0:7319afbc731c | 6 | This Source Code Form is subject to the terms of the Mozilla Public License, |
kabukistarship | 0:7319afbc731c | 7 | v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain |
kabukistarship | 0:7319afbc731c | 8 | one at <https://mozilla.org/MPL/2.0/>. */ |
kabukistarship | 0:7319afbc731c | 9 | #pragma once |
kabukistarship | 0:7319afbc731c | 10 | #ifndef SBVentilatorDecl |
kabukistarship | 0:7319afbc731c | 11 | #define SBVentilatorDecl |
kabukistarship | 0:7319afbc731c | 12 | #include "SBVentilatorChannel.h" |
kabukistarship | 0:7319afbc731c | 13 | namespace SickBay { |
kabukistarship | 0:7319afbc731c | 14 | |
kabukistarship | 0:7319afbc731c | 15 | /* A SickBay Ventilator. */ |
kabukistarship | 0:7319afbc731c | 16 | class SBVentilator { |
kabukistarship | 0:7319afbc731c | 17 | public: |
kabukistarship | 0:7319afbc731c | 18 | |
kabukistarship | 0:7319afbc731c | 19 | enum { |
kabukistarship | 0:7319afbc731c | 20 | StateOff = 0, //< Both Machine calibrating and off states. |
kabukistarship | 0:7319afbc731c | 21 | StateCalibrate = 0, //< The Calibrate state where the Tick is 0. |
kabukistarship | 0:7319afbc731c | 22 | StateRising = 1, //< The Running state first Tick. |
kabukistarship | 0:7319afbc731c | 23 | StateSinking = -1, //< The Running state first Tick. |
kabukistarship | 0:7319afbc731c | 24 | StatusCodeCount = 1, //< The number of status codes. |
kabukistarship | 0:7319afbc731c | 25 | ChannelCount = SBVentilatorChannelCount, //< Number of ventilator channels. |
kabukistarship | 0:7319afbc731c | 26 | }; |
kabukistarship | 0:7319afbc731c | 27 | |
kabukistarship | 0:7319afbc731c | 28 | volatile int Status; //< The status of the Device. |
kabukistarship | 0:7319afbc731c | 29 | // The tick and negative calibrating positive running states. |
kabukistarship | 0:7319afbc731c | 30 | volatile int Ticks; |
kabukistarship | 0:7319afbc731c | 31 | int TicksMonitor, //< The max ticks between the Device monitor updates. |
kabukistarship | 0:7319afbc731c | 32 | TicksSecond, //< The number of Ticks per Second. |
kabukistarship | 0:7319afbc731c | 33 | TicksInhaleMin, //< The min inhale ticks. |
kabukistarship | 0:7319afbc731c | 34 | TicksInhaleMax, //< The max breath period of 20 seconds. |
kabukistarship | 0:7319afbc731c | 35 | TicksExhaleMin, //< The min ticks in an exhale. |
kabukistarship | 0:7319afbc731c | 36 | TicksExhaleMax, //< The max ticks in an exhale. |
kabukistarship | 0:7319afbc731c | 37 | TicksPEEP, //< The max number of PEEP Ticks before inhaling. |
kabukistarship | 0:7319afbc731c | 38 | TicksCalibration; //< The number of ticks in the calibration state. |
kabukistarship | 0:7319afbc731c | 39 | int32_t Temperature, //< The Temperature in the tank. |
kabukistarship | 0:7319afbc731c | 40 | TemperatureReference; //< The Temperature in the tank. |
kabukistarship | 0:7319afbc731c | 41 | uint32_t Pressure, //< The Pressure in the tank. |
kabukistarship | 0:7319afbc731c | 42 | PressureReference, //< The Pressure when the device is tared. |
kabukistarship | 0:7319afbc731c | 43 | PressureMin, //< The min Pressure. |
kabukistarship | 0:7319afbc731c | 44 | PressureMax, //< The max Pressure. |
kabukistarship | 0:7319afbc731c | 45 | HysteresisChamber, //< The pressure chamber hystersis +/- delta. |
kabukistarship | 0:7319afbc731c | 46 | HysteresisPatient; //< The patient Hystersis + delta. |
kabukistarship | 0:7319afbc731c | 47 | SBVentilatorChannel Channels[ChannelCount]; |
kabukistarship | 0:7319afbc731c | 48 | |
kabukistarship | 0:7319afbc731c | 49 | /* Sets some of the varaibles to default requiring a call to Init. */ |
kabukistarship | 0:7319afbc731c | 50 | SBVentilator (); |
kabukistarship | 0:7319afbc731c | 51 | |
kabukistarship | 0:7319afbc731c | 52 | /* Initializes the ventilator with the given values. */ |
kabukistarship | 0:7319afbc731c | 53 | void Init (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 0:7319afbc731c | 54 | float PressureHysteresis, float HysteresisPatient); |
kabukistarship | 0:7319afbc731c | 55 | |
kabukistarship | 0:7319afbc731c | 56 | /* Enters the Calibration State. */ |
kabukistarship | 0:7319afbc731c | 57 | void StateCalibrateEnter (); |
kabukistarship | 0:7319afbc731c | 58 | |
kabukistarship | 0:7319afbc731c | 59 | /* Enters the Calibration State. */ |
kabukistarship | 0:7319afbc731c | 60 | void StateCalibrateExit (); |
kabukistarship | 0:7319afbc731c | 61 | |
kabukistarship | 0:7319afbc731c | 62 | /* Returns true if the Chamber is over-pressure. */ |
kabukistarship | 0:7319afbc731c | 63 | bool IsOverPressure (); |
kabukistarship | 0:7319afbc731c | 64 | |
kabukistarship | 0:7319afbc731c | 65 | /* Returns true if the Chamber is under-pressure. */ |
kabukistarship | 0:7319afbc731c | 66 | bool IsUnderPressure (); |
kabukistarship | 0:7319afbc731c | 67 | |
kabukistarship | 0:7319afbc731c | 68 | /* Turns on the blower fan. */ |
kabukistarship | 0:7319afbc731c | 69 | void BlowerTurnOn (); |
kabukistarship | 0:7319afbc731c | 70 | |
kabukistarship | 0:7319afbc731c | 71 | /* Turns off the blower fan. */ |
kabukistarship | 0:7319afbc731c | 72 | void BlowerTurnOff (); |
kabukistarship | 0:7319afbc731c | 73 | |
kabukistarship | 0:7319afbc731c | 74 | /* Turns the Blower off and sets the Ticks to StateSinking. */ |
kabukistarship | 0:7319afbc731c | 75 | void StateSinkingEnter (); |
kabukistarship | 0:7319afbc731c | 76 | |
kabukistarship | 0:7319afbc731c | 77 | /* Turns the Blower On and sets the Ticks to StateRising. */ |
kabukistarship | 0:7319afbc731c | 78 | void StateRisingEnter (); |
kabukistarship | 0:7319afbc731c | 79 | |
kabukistarship | 0:7319afbc731c | 80 | /* Sets the TicksPEEP given 1/64 second > NewTicksPEEP < 1 second. */ |
kabukistarship | 0:7319afbc731c | 81 | void TicksPEEPSet (int NewTicksPEEP); |
kabukistarship | 0:7319afbc731c | 82 | |
kabukistarship | 0:7319afbc731c | 83 | /* Enters the Off State. */ |
kabukistarship | 0:7319afbc731c | 84 | void StateCalibrateOff (); |
kabukistarship | 0:7319afbc731c | 85 | |
kabukistarship | 0:7319afbc731c | 86 | /* Monitors this Device and it's channels. */ |
kabukistarship | 0:7319afbc731c | 87 | void Monitor (); |
kabukistarship | 0:7319afbc731c | 88 | |
kabukistarship | 0:7319afbc731c | 89 | /* Turns off the Device and all of it's chanels. */ |
kabukistarship | 0:7319afbc731c | 90 | void TurnOff (); |
kabukistarship | 0:7319afbc731c | 91 | |
kabukistarship | 0:7319afbc731c | 92 | /* Turns on the Device and all of it's chanels to the Inhale state. */ |
kabukistarship | 0:7319afbc731c | 93 | void TurnOnAll (); |
kabukistarship | 0:7319afbc731c | 94 | |
kabukistarship | 0:7319afbc731c | 95 | /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ |
kabukistarship | 0:7319afbc731c | 96 | void Tare(); |
kabukistarship | 0:7319afbc731c | 97 | |
kabukistarship | 0:7319afbc731c | 98 | /* Sets the inhale and exhale ticks for the give channel Index. */ |
kabukistarship | 0:7319afbc731c | 99 | int TicksInhaleExhaleSet (int Index, int TicksInhale, int TicksExhale); |
kabukistarship | 0:7319afbc731c | 100 | |
kabukistarship | 1:278bfa29bd0d | 101 | /* Calls on of the Channel1ValveSet through Channel4ValveSet functions. */ |
kabukistarship | 0:7319afbc731c | 102 | void ChannelValveSet (SBVentilatorChannel* Channel, int Value); |
kabukistarship | 0:7319afbc731c | 103 | |
kabukistarship | 0:7319afbc731c | 104 | /* Sets the Channel 1 solenoid valve to the given Value. */ |
kabukistarship | 0:7319afbc731c | 105 | void Channel1ValveSet (int Value); |
kabukistarship | 1:278bfa29bd0d | 106 | //#if SBVentilatorChannelCount >= 2 |
kabukistarship | 0:7319afbc731c | 107 | /* Sets the Channel 2 solenoid valve to the given Value. */ |
kabukistarship | 0:7319afbc731c | 108 | void Channel2ValveSet (int Value); |
kabukistarship | 1:278bfa29bd0d | 109 | //#endif |
kabukistarship | 1:278bfa29bd0d | 110 | //#if SBVentilatorChannelCount >= 3 |
kabukistarship | 0:7319afbc731c | 111 | /* Sets the Channel 3 solenoid valve to the given Value. */ |
kabukistarship | 0:7319afbc731c | 112 | void Channel3ValveSet (int Value); |
kabukistarship | 1:278bfa29bd0d | 113 | //#endif |
kabukistarship | 1:278bfa29bd0d | 114 | //#if SBVentilatorChannelCount >= 4 |
kabukistarship | 0:7319afbc731c | 115 | /* Sets the Channel 4 solenoid valve to the given Value. */ |
kabukistarship | 0:7319afbc731c | 116 | void Channel4ValveSet (int Value); |
kabukistarship | 1:278bfa29bd0d | 117 | //#endif |
kabukistarship | 0:7319afbc731c | 118 | |
kabukistarship | 0:7319afbc731c | 119 | /* Updates the main device and it's channels. */ |
kabukistarship | 0:7319afbc731c | 120 | void Update (); |
kabukistarship | 0:7319afbc731c | 121 | |
kabukistarship | 1:278bfa29bd0d | 122 | /* Main program loop. */ |
kabukistarship | 1:278bfa29bd0d | 123 | void Run (); |
kabukistarship | 1:278bfa29bd0d | 124 | |
kabukistarship | 0:7319afbc731c | 125 | }; |
kabukistarship | 0:7319afbc731c | 126 | |
kabukistarship | 0:7319afbc731c | 127 | } //< namespace SickBay |
kabukistarship | 0:7319afbc731c | 128 | #endif |
kabukistarship | 0:7319afbc731c | 129 | #undef SBVentilatorChannelCount |
kabukistarship | 0:7319afbc731c | 130 | #undef SBVentilatorStateRising |
kabukistarship | 0:7319afbc731c | 131 | #undef SBVentilatorStateSinking |