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@3:d15b6579b5ae, 2020-04-08 (annotated)
- 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?
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 <mbedBug.h> |
kabukistarship | 2:1578ecfa9377 | 13 | using namespace mbedBug; |
kabukistarship | 2:1578ecfa9377 | 14 | #include "GHVentilatorChannel.h" |
kabukistarship | 2:1578ecfa9377 | 15 | namespace SickBay { |
kabukistarship | 3:d15b6579b5ae | 16 | |
kabukistarship | 3:d15b6579b5ae | 17 | #define GHVentilatorPressureHysteresisPercent 0.25f //< +/- 25% histesis. |
kabukistarship | 2:1578ecfa9377 | 18 | |
kabukistarship | 2:1578ecfa9377 | 19 | /* A Gravity Hookah Ventilator. */ |
kabukistarship | 2:1578ecfa9377 | 20 | template<int ChannelCount> |
kabukistarship | 2:1578ecfa9377 | 21 | class GHVentilator { |
kabukistarship | 3:d15b6579b5ae | 22 | public: |
kabukistarship | 3:d15b6579b5ae | 23 | |
kabukistarship | 3:d15b6579b5ae | 24 | enum { |
kabukistarship | 3:d15b6579b5ae | 25 | ChannelCountMax = 4, |
kabukistarship | 3:d15b6579b5ae | 26 | StateCalibratingPressureSensor = 0, |
kabukistarship | 3:d15b6579b5ae | 27 | StateRunning = 1, |
kabukistarship | 3:d15b6579b5ae | 28 | }; |
kabukistarship | 3:d15b6579b5ae | 29 | |
kabukistarship | 3:d15b6579b5ae | 30 | // The tick and negative calibrating positive running states. |
kabukistarship | 3:d15b6579b5ae | 31 | int Ticks, |
kabukistarship | 3:d15b6579b5ae | 32 | TicksMax, //< The max tick count before it gets reset. |
kabukistarship | 3:d15b6579b5ae | 33 | TicksSecond, //< The number of Ticks per Second. |
kabukistarship | 3:d15b6579b5ae | 34 | TicksInhaleMin, //< The min inhale ticks. |
kabukistarship | 3:d15b6579b5ae | 35 | TicksInhaleMax, //< The max breath period of 20 seconds. |
kabukistarship | 3:d15b6579b5ae | 36 | TicksExhaleMin, //< The min ticks in an exhale. |
kabukistarship | 3:d15b6579b5ae | 37 | TicksExhaleMax, //< The max ticks in an exhale. |
kabukistarship | 3:d15b6579b5ae | 38 | TicksCalibration;//< The number of ticks in the calibration state. |
kabukistarship | 3:d15b6579b5ae | 39 | float PressureMin, //< The min Pressure. |
kabukistarship | 3:d15b6579b5ae | 40 | PressureMax, //< The max Pressure. |
kabukistarship | 3:d15b6579b5ae | 41 | Pressure, //< The Pressure in the tank. |
kabukistarship | 3:d15b6579b5ae | 42 | ServoMin, //< The min servo value. |
kabukistarship | 3:d15b6579b5ae | 43 | ServoMax; //< The max servo value. |
kabukistarship | 3:d15b6579b5ae | 44 | /* The amount the Pressure needs to change to count as having changed. */ |
kabukistarship | 3:d15b6579b5ae | 45 | float PressureChangeDelta; |
kabukistarship | 3:d15b6579b5ae | 46 | //< The GHV channels. |
kabukistarship | 3:d15b6579b5ae | 47 | GHVentilatorChannel Channels[ChannelCountMax]; |
kabukistarship | 3:d15b6579b5ae | 48 | BMP280 Atmosphere; //< Pressure sensor for the air tank. |
kabukistarship | 3:d15b6579b5ae | 49 | DigitalOut Blower; //< A blower powered by a Solid State Relay. |
kabukistarship | 3:d15b6579b5ae | 50 | |
kabukistarship | 3:d15b6579b5ae | 51 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 3:d15b6579b5ae | 52 | I2C& I2CBus, char SlaveAddress, |
kabukistarship | 3:d15b6579b5ae | 53 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 3:d15b6579b5ae | 54 | GHVentilatorChannel A); |
kabukistarship | 3:d15b6579b5ae | 55 | |
kabukistarship | 3:d15b6579b5ae | 56 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 3:d15b6579b5ae | 57 | I2C& I2CBus, char SlaveAddress, |
kabukistarship | 3:d15b6579b5ae | 58 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 3:d15b6579b5ae | 59 | GHVentilatorChannel A, |
kabukistarship | 3:d15b6579b5ae | 60 | GHVentilatorChannel B); |
kabukistarship | 3:d15b6579b5ae | 61 | |
kabukistarship | 3:d15b6579b5ae | 62 | GHVentilator (int TicksPerSecond, int TicksCalibration, |
kabukistarship | 3:d15b6579b5ae | 63 | I2C& I2CBus, char SlaveAddress, |
kabukistarship | 3:d15b6579b5ae | 64 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 3:d15b6579b5ae | 65 | GHVentilatorChannel A, |
kabukistarship | 3:d15b6579b5ae | 66 | GHVentilatorChannel B, |
kabukistarship | 3:d15b6579b5ae | 67 | GHVentilatorChannel C); |
kabukistarship | 3:d15b6579b5ae | 68 | |
kabukistarship | 3:d15b6579b5ae | 69 | GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, |
kabukistarship | 3:d15b6579b5ae | 70 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 3:d15b6579b5ae | 71 | GHVentilatorChannel A, |
kabukistarship | 3:d15b6579b5ae | 72 | GHVentilatorChannel B, |
kabukistarship | 3:d15b6579b5ae | 73 | GHVentilatorChannel C, |
kabukistarship | 3:d15b6579b5ae | 74 | GHVentilatorChannel D); |
kabukistarship | 3:d15b6579b5ae | 75 | |
kabukistarship | 3:d15b6579b5ae | 76 | /* Gets the GHVentilatorChannel with the given Index. \ |
kabukistarship | 3:d15b6579b5ae | 77 | @return Nil if the Index is out of bounds. */ |
kabukistarship | 3:d15b6579b5ae | 78 | GHVentilatorChannel* Channel(int Index); |
kabukistarship | 3:d15b6579b5ae | 79 | |
kabukistarship | 3:d15b6579b5ae | 80 | void ChannelSet (int ChannelIndex, float DutyCycle = 0.0f, |
kabukistarship | 3:d15b6579b5ae | 81 | float Period = 0.0f); |
kabukistarship | 3:d15b6579b5ae | 82 | /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ |
kabukistarship | 3:d15b6579b5ae | 83 | void TarePressure(); |
kabukistarship | 3:d15b6579b5ae | 84 | |
kabukistarship | 3:d15b6579b5ae | 85 | int TicksInhaleExhaleSet (int TicksInhale, int TicksExhale); |
kabukistarship | 3:d15b6579b5ae | 86 | |
kabukistarship | 3:d15b6579b5ae | 87 | /* Starts the system. */ |
kabukistarship | 3:d15b6579b5ae | 88 | int Run (); |
kabukistarship | 3:d15b6579b5ae | 89 | |
kabukistarship | 3:d15b6579b5ae | 90 | /* Updates the main device and it's channels. */ |
kabukistarship | 3:d15b6579b5ae | 91 | void Update (); |
kabukistarship | 2:1578ecfa9377 | 92 | }; |
kabukistarship | 2:1578ecfa9377 | 93 | |
kabukistarship | 3:d15b6579b5ae | 94 | void HanleTicksSecondSet(Arguments* input, Reply* output); |
kabukistarship | 3:d15b6579b5ae | 95 | void HanleInhaleTicksSet(Arguments* input, Reply* output); |
kabukistarship | 3:d15b6579b5ae | 96 | |
kabukistarship | 3:d15b6579b5ae | 97 | RPCFunction TicksSecondSet(&DoGetData, "TicksSecondSet"), |
kabukistarship | 3:d15b6579b5ae | 98 | InhaleTicksSet(&DoGetData, "InhaleTicksSet"), |
kabukistarship | 3:d15b6579b5ae | 99 | ExhaleTicksSet(&DoGetData, "ExhaleTicksSet"); |
kabukistarship | 3:d15b6579b5ae | 100 | |
kabukistarship | 3:d15b6579b5ae | 101 | void RemoteTicksSecondSetHandle(Arguments* input, Reply* output); |
kabukistarship | 3:d15b6579b5ae | 102 | |
kabukistarship | 3:d15b6579b5ae | 103 | void HandleTicksInhaleExhaleSet(Arguments* input, Reply* output); |
kabukistarship | 3:d15b6579b5ae | 104 | |
kabukistarship | 2:1578ecfa9377 | 105 | } //< namespace SickBay |
kabukistarship | 2:1578ecfa9377 | 106 | #endif |