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.
GHVentilatorChannel.h@8:fa5cc1397510, 2020-04-09 (annotated)
- Committer:
- kabukistarship
- Date:
- Thu Apr 09 03:18:31 2020 +0000
- Revision:
- 8:fa5cc1397510
- Parent:
- 6:b2672da545f1
- Child:
- 9:256989faeb3b
Detail.GHVentilator.Firmware.Mbed.Move BMP280 polling code into main loop; States.Add PEEP state. #67 #D
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 /GHVentilatorChannel.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 | |
kabukistarship | 2:1578ecfa9377 | 10 | #pragma once |
kabukistarship | 2:1578ecfa9377 | 11 | #ifndef GHVentilatorChannelDecl |
kabukistarship | 2:1578ecfa9377 | 12 | #define GHVentilatorChannelDecl |
kabukistarship | 2:1578ecfa9377 | 13 | #include "GHVentilatorConfig.h" |
kabukistarship | 2:1578ecfa9377 | 14 | #include "BMP280.h" |
kabukistarship | 2:1578ecfa9377 | 15 | |
kabukistarship | 2:1578ecfa9377 | 16 | namespace SickBay { |
kabukistarship | 2:1578ecfa9377 | 17 | |
kabukistarship | 2:1578ecfa9377 | 18 | /* A Gravity Hookah Ventilator channel for one patient. */ |
kabukistarship | 2:1578ecfa9377 | 19 | class GHVentilatorChannel { |
kabukistarship | 4:de69851cf725 | 20 | public: |
kabukistarship | 6:b2672da545f1 | 21 | |
kabukistarship | 6:b2672da545f1 | 22 | enum { |
kabukistarship | 6:b2672da545f1 | 23 | StateInhaling = 1, //< The value for the init Ticks inhale value. |
kabukistarship | 6:b2672da545f1 | 24 | StateExhaling = -1, //< The value for the init Ticks exhale value. |
kabukistarship | 6:b2672da545f1 | 25 | }; |
kabukistarship | 2:1578ecfa9377 | 26 | |
kabukistarship | 6:b2672da545f1 | 27 | volatile int Ticks; //< Ticks since the beginning of the inhale. |
kabukistarship | 6:b2672da545f1 | 28 | int TicksExhale, //< The period of the breathing. |
kabukistarship | 4:de69851cf725 | 29 | TicksInhale, //< The tick count in the inhale duty cycle. |
kabukistarship | 8:fa5cc1397510 | 30 | TicksPEEP; //< The max ticks between an exhale and inhale. |
kabukistarship | 6:b2672da545f1 | 31 | volatile int TicksFlowLast, //< The previous inhale TicksFlow count. |
kabukistarship | 6:b2672da545f1 | 32 | TicksFlow; //< Flow sensor pulse TicksFlow count. |
kabukistarship | 4:de69851cf725 | 33 | BMP280 Atmosphere; //< The air Atmosphere going to the patient. |
kabukistarship | 6:b2672da545f1 | 34 | float Temperature, //< The Temperature of the patients breath. |
kabukistarship | 6:b2672da545f1 | 35 | TemperatureReference, //< The refernce temperature, |
kabukistarship | 6:b2672da545f1 | 36 | Pressure, //< The pressure in the patient's mask. |
kabukistarship | 6:b2672da545f1 | 37 | PressureReference; //< The pressure in the mask at one atmosphere. |
kabukistarship | 4:de69851cf725 | 38 | AnalogIn PulseOximeter; //< The 7-pin pulse oximeter pin. |
kabukistarship | 4:de69851cf725 | 39 | InterruptIn FlowSensor; //< The flow sensor pin. |
kabukistarship | 6:b2672da545f1 | 40 | DigitalOut Valve; //< The Status LED and optional alarm. |
kabukistarship | 4:de69851cf725 | 41 | PwmOut Servo; //< The Servo for reducing the pressrue. |
kabukistarship | 4:de69851cf725 | 42 | int ServoClosed, //< The min servo duty cycle of no air flow. |
kabukistarship | 6:b2672da545f1 | 43 | ServoOpen, //< The max servo duty cycle of an open tube. |
kabukistarship | 6:b2672da545f1 | 44 | Status; //< The channel Status. |
kabukistarship | 6:b2672da545f1 | 45 | |
kabukistarship | 4:de69851cf725 | 46 | /* Constructs a smart waterer. */ |
kabukistarship | 4:de69851cf725 | 47 | GHVentilatorChannel (PinName PulseOximeterPin, |
kabukistarship | 5:da629056644f | 48 | PinName FlowSensorPin, |
kabukistarship | 4:de69851cf725 | 49 | PinName SolenoidPin, |
kabukistarship | 4:de69851cf725 | 50 | PinName ServoPin, |
kabukistarship | 6:b2672da545f1 | 51 | I2C& Bus, char BusAddress); |
kabukistarship | 2:1578ecfa9377 | 52 | |
kabukistarship | 4:de69851cf725 | 53 | /* Returns a pointer to this. */ |
kabukistarship | 4:de69851cf725 | 54 | GHVentilatorChannel* This(); |
kabukistarship | 6:b2672da545f1 | 55 | |
kabukistarship | 8:fa5cc1397510 | 56 | /* Sets the TicksPEEP. */ |
kabukistarship | 8:fa5cc1397510 | 57 | void TicksPEEPSet (int NewTicksPEEP, int TicksSecond); |
kabukistarship | 8:fa5cc1397510 | 58 | |
kabukistarship | 6:b2672da545f1 | 59 | /* Turns off this channel. */ |
kabukistarship | 6:b2672da545f1 | 60 | void TurnOff (); |
kabukistarship | 6:b2672da545f1 | 61 | |
kabukistarship | 6:b2672da545f1 | 62 | /* Turns on the this chanel. */ |
kabukistarship | 6:b2672da545f1 | 63 | void TurnOn (); |
kabukistarship | 6:b2672da545f1 | 64 | |
kabukistarship | 6:b2672da545f1 | 65 | /* Polls the hardware for changes. */ |
kabukistarship | 6:b2672da545f1 | 66 | void Poll(); |
kabukistarship | 2:1578ecfa9377 | 67 | |
kabukistarship | 4:de69851cf725 | 68 | /* Sets the number of ticks on the inhale and exhale. */ |
kabukistarship | 4:de69851cf725 | 69 | void TicksInhaleExhaleSet (int NewTicksInhale, int NewTicksExhale); |
kabukistarship | 2:1578ecfa9377 | 70 | |
kabukistarship | 4:de69851cf725 | 71 | /* BreatheStarts to the begining of the watering cycle. */ |
kabukistarship | 4:de69851cf725 | 72 | void BreatheStart (int Index); |
kabukistarship | 2:1578ecfa9377 | 73 | |
kabukistarship | 4:de69851cf725 | 74 | /* Increments theflow rate sensor pulse counter. */ |
kabukistarship | 6:b2672da545f1 | 75 | void TickFlow (); |
kabukistarship | 2:1578ecfa9377 | 76 | |
kabukistarship | 4:de69851cf725 | 77 | /* Prints the state of object to the debug stream. */ |
kabukistarship | 4:de69851cf725 | 78 | void Print (int Index); |
kabukistarship | 2:1578ecfa9377 | 79 | |
kabukistarship | 4:de69851cf725 | 80 | /* Updates the float rate. */ |
kabukistarship | 4:de69851cf725 | 81 | bool CheckIfDoneBreathing (int Index); |
kabukistarship | 2:1578ecfa9377 | 82 | |
kabukistarship | 4:de69851cf725 | 83 | /* Opens the solenoid valve. */ |
kabukistarship | 4:de69851cf725 | 84 | void Inhale (); |
kabukistarship | 2:1578ecfa9377 | 85 | |
kabukistarship | 4:de69851cf725 | 86 | /* Closes the solenoid valve. */ |
kabukistarship | 4:de69851cf725 | 87 | void Exhale (); |
kabukistarship | 3:d15b6579b5ae | 88 | |
kabukistarship | 4:de69851cf725 | 89 | /* Samples the Atmospheric pressure and temperature. */ |
kabukistarship | 6:b2672da545f1 | 90 | void Tare (float PressureHysteresis); |
kabukistarship | 6:b2672da545f1 | 91 | |
kabukistarship | 6:b2672da545f1 | 92 | /* Monitor the channel for if errors. */ |
kabukistarship | 6:b2672da545f1 | 93 | int Monitor (); |
kabukistarship | 2:1578ecfa9377 | 94 | |
kabukistarship | 4:de69851cf725 | 95 | /* Updates the channel with the DeviceTick. */ |
kabukistarship | 4:de69851cf725 | 96 | void Update(); |
kabukistarship | 2:1578ecfa9377 | 97 | }; |
kabukistarship | 2:1578ecfa9377 | 98 | } //< namespace SickBay |
kabukistarship | 4:de69851cf725 | 99 | #endif |