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@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 /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 | 2:1578ecfa9377 | 16 | /* |
kabukistarship | 2:1578ecfa9377 | 17 | void DoGetData(Arguments* input, Reply* output); |
kabukistarship | 2:1578ecfa9377 | 18 | |
kabukistarship | 2:1578ecfa9377 | 19 | RPCFunction getData(&DoGetData, "getData"); |
kabukistarship | 2:1578ecfa9377 | 20 | |
kabukistarship | 2:1578ecfa9377 | 21 | void DoGetData(Arguments* input, Reply* output) { |
kabukistarship | 2:1578ecfa9377 | 22 | // Arguments are already parsed into argv array of char* |
kabukistarship | 2:1578ecfa9377 | 23 | printf("Object name = %s\n",input->obj_name); |
kabukistarship | 2:1578ecfa9377 | 24 | printf("Method name = %s\n",input->method_name); |
kabukistarship | 2:1578ecfa9377 | 25 | for (int i=0; i < input->argc; i++) |
kabukistarship | 2:1578ecfa9377 | 26 | printf("argv[%1d] = %s \n",i,input->argv[i]); |
kabukistarship | 2:1578ecfa9377 | 27 | |
kabukistarship | 2:1578ecfa9377 | 28 | // Alternatively the arguments can be recovered as the types expected |
kabukistarship | 2:1578ecfa9377 | 29 | // by repeated calls to getArg() |
kabukistarship | 2:1578ecfa9377 | 30 | int arg0 = input->getArg<int>(); // Expecting argv[0] to be int |
kabukistarship | 2:1578ecfa9377 | 31 | printf("Expecting argv[0] to be int = %d\n",arg0); |
kabukistarship | 2:1578ecfa9377 | 32 | float arg1 = input->getArg<float>(); // Expecting argv[1] to be float |
kabukistarship | 2:1578ecfa9377 | 33 | printf("Expecting argv[1] to be float = %f\n",arg1); |
kabukistarship | 2:1578ecfa9377 | 34 | const char *arg2 = input->getArg<const char*>(); // Expecting argv[2] to be a string |
kabukistarship | 2:1578ecfa9377 | 35 | printf("Expecting argv[2] to be a string = %s\n",arg2); |
kabukistarship | 2:1578ecfa9377 | 36 | |
kabukistarship | 2:1578ecfa9377 | 37 | // The output parameter string is generated by calls to putData, which separates them with spaces. |
kabukistarship | 2:1578ecfa9377 | 38 | output->putData(arg0); |
kabukistarship | 2:1578ecfa9377 | 39 | output->putData(arg1); |
kabukistarship | 2:1578ecfa9377 | 40 | output->putData(arg2); |
kabukistarship | 2:1578ecfa9377 | 41 | }*/ |
kabukistarship | 2:1578ecfa9377 | 42 | |
kabukistarship | 2:1578ecfa9377 | 43 | /* A Gravity Hookah Ventilator. */ |
kabukistarship | 2:1578ecfa9377 | 44 | template<int ChannelCount> |
kabukistarship | 2:1578ecfa9377 | 45 | class GHVentilator { |
kabukistarship | 2:1578ecfa9377 | 46 | public: |
kabukistarship | 2:1578ecfa9377 | 47 | |
kabukistarship | 2:1578ecfa9377 | 48 | enum { |
kabukistarship | 2:1578ecfa9377 | 49 | ChannelCountMax = 4, |
kabukistarship | 2:1578ecfa9377 | 50 | StateCalibratingPressureSensor = 0, |
kabukistarship | 2:1578ecfa9377 | 51 | StateRunning = 1, |
kabukistarship | 2:1578ecfa9377 | 52 | }; |
kabukistarship | 2:1578ecfa9377 | 53 | |
kabukistarship | 2:1578ecfa9377 | 54 | int State, //< The ventilator state. |
kabukistarship | 2:1578ecfa9377 | 55 | Ticks, //< The tick. |
kabukistarship | 2:1578ecfa9377 | 56 | TicksMax, //< The max tick count before it gets reset. |
kabukistarship | 2:1578ecfa9377 | 57 | TicksSecond, //< The number of Ticks per Second. |
kabukistarship | 2:1578ecfa9377 | 58 | TicksInhaleMin, //< The min inhale ticks. |
kabukistarship | 2:1578ecfa9377 | 59 | TicksInhaleMax, //< The max breath period of 20 seconds. |
kabukistarship | 2:1578ecfa9377 | 60 | TicksExhaleMin, //< The min ticks in an exhale. |
kabukistarship | 2:1578ecfa9377 | 61 | TicksExhaleMax; //< The max ticks in an exhale. |
kabukistarship | 2:1578ecfa9377 | 62 | float PressureMin, //< The min Pressure. |
kabukistarship | 2:1578ecfa9377 | 63 | PressureMax, //< The max Pressure. |
kabukistarship | 2:1578ecfa9377 | 64 | Pressure, //< The Pressure in the tank. |
kabukistarship | 2:1578ecfa9377 | 65 | ServoMin, //< The min servo value. |
kabukistarship | 2:1578ecfa9377 | 66 | ServoMax; //< The max servo value. |
kabukistarship | 2:1578ecfa9377 | 67 | /* The amount the Pressure needs to change to count as having changed. */ |
kabukistarship | 2:1578ecfa9377 | 68 | float PressureChangeDelta; |
kabukistarship | 2:1578ecfa9377 | 69 | //< The GHV channels. |
kabukistarship | 2:1578ecfa9377 | 70 | GHVentilatorChannel Channels[ChannelCountMax]; |
kabukistarship | 2:1578ecfa9377 | 71 | BMP280 Atmosphere; //< Pressure sensor for the air tank. |
kabukistarship | 2:1578ecfa9377 | 72 | DigitalOut Blower; //< A blower powered by a Solid State Relay. |
kabukistarship | 2:1578ecfa9377 | 73 | |
kabukistarship | 2:1578ecfa9377 | 74 | GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, |
kabukistarship | 2:1578ecfa9377 | 75 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 2:1578ecfa9377 | 76 | GHVentilatorChannel A); |
kabukistarship | 2:1578ecfa9377 | 77 | |
kabukistarship | 2:1578ecfa9377 | 78 | GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, |
kabukistarship | 2:1578ecfa9377 | 79 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 2:1578ecfa9377 | 80 | GHVentilatorChannel A, |
kabukistarship | 2:1578ecfa9377 | 81 | GHVentilatorChannel B); |
kabukistarship | 2:1578ecfa9377 | 82 | |
kabukistarship | 2:1578ecfa9377 | 83 | GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, |
kabukistarship | 2:1578ecfa9377 | 84 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 2:1578ecfa9377 | 85 | GHVentilatorChannel A, |
kabukistarship | 2:1578ecfa9377 | 86 | GHVentilatorChannel B, |
kabukistarship | 2:1578ecfa9377 | 87 | GHVentilatorChannel C); |
kabukistarship | 2:1578ecfa9377 | 88 | |
kabukistarship | 2:1578ecfa9377 | 89 | GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, |
kabukistarship | 2:1578ecfa9377 | 90 | PinName BlowerPin, PinName StatusPin, |
kabukistarship | 2:1578ecfa9377 | 91 | GHVentilatorChannel A, |
kabukistarship | 2:1578ecfa9377 | 92 | GHVentilatorChannel B, |
kabukistarship | 2:1578ecfa9377 | 93 | GHVentilatorChannel C, |
kabukistarship | 2:1578ecfa9377 | 94 | GHVentilatorChannel D); |
kabukistarship | 2:1578ecfa9377 | 95 | |
kabukistarship | 2:1578ecfa9377 | 96 | void ChannelSet (int ChannelIndex, float DutyCycle = 0.0f, |
kabukistarship | 2:1578ecfa9377 | 97 | float Period = 0.0f); |
kabukistarship | 2:1578ecfa9377 | 98 | /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ |
kabukistarship | 2:1578ecfa9377 | 99 | void TarePressure(); |
kabukistarship | 2:1578ecfa9377 | 100 | |
kabukistarship | 2:1578ecfa9377 | 101 | /* Starts the system. */ |
kabukistarship | 2:1578ecfa9377 | 102 | int Run (); |
kabukistarship | 2:1578ecfa9377 | 103 | |
kabukistarship | 2:1578ecfa9377 | 104 | /* Updates the main device and it's channels. */ |
kabukistarship | 2:1578ecfa9377 | 105 | void Update (); |
kabukistarship | 2:1578ecfa9377 | 106 | }; |
kabukistarship | 2:1578ecfa9377 | 107 | |
kabukistarship | 2:1578ecfa9377 | 108 | } //< namespace SickBay |
kabukistarship | 2:1578ecfa9377 | 109 | #endif |