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.
Diff: GHVentilatorChannel.h
- Revision:
- 2:1578ecfa9377
- Child:
- 3:d15b6579b5ae
diff -r 3a36f28f8d65 -r 1578ecfa9377 GHVentilatorChannel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GHVentilatorChannel.h Tue Apr 07 13:10:45 2020 +0000 @@ -0,0 +1,95 @@ +/** Gravity Hookah Ventilator @version 0.x +@link https://github.com/KabukiStarship/SickBay.git +@file /GHVentilatorChannel.h +@author Cale McCollough <https://cale-mccollough.github.io> +@license Copyright 2020 (C) Kabuki Starship <kabukistarship.com>. +This Source Code Form is subject to the terms of the Mozilla Public License, +v. 2.0. If a copy of the MPL was not distributed with this file, you can obtain +one at <https://mozilla.org/MPL/2.0/>. */ + +#pragma once +#ifndef GHVentilatorChannelDecl +#define GHVentilatorChannelDecl +#include <mbedBug.h> +using namespace mbedBug; +#include "GHVentilatorConfig.h" +#include "BMP280.h" + +#ifndef GHVentilatorChannelsCount +#define GHVentilatorChannelsCount 1 +#endif + +volatile int CurrentChannel = -1; +volatile bool TooMuchAir = false; + +namespace SickBay { + +/* A Gravity Hookah Ventilator channel for one patient. */ +class GHVentilatorChannel { + public: + + int Ticks, //< Ticks since the beginning of the inhale. + TicksInhale, //< The ticks in the inhale duty half-period. + TicksExhale; //< The period of the breathing. + volatile int TicksFlowLast, //< The previous saved count. + TicksFlow; //< Flow sensor pulse count. + float ReferencePressure, //< The pressure in the mask at one atmosphere. + ReferenceTemperature; //< The refernce temperature. + BMP280 Atmosphere; //< The air Atmosphere going to the patient. + InterruptIn Sensor; //< The flow sensor pin. + DigitalOut Valve, //< The Solenoid valve. + Status; //< The Status LED and optional alarm. + PwmOut Servo; //< The Servo for reducing the pressrue. + AnalogIn PulseOximeter; //< The PulseOximeterentiometer pin. + + /* Constructs a smart waterer. */ + GHVentilatorChannel (PinName SensorPin, + PinName PulseOximeterPin, + PinName SolenoidPin, + PinName StatusPin, + PinName ServoPin, + I2C& I2CBus, char I2CAddress); + + /* Returns a pointer to this. */ + GHVentilatorChannel* This(); + + /* Sets the Breath period in seconds. */ + void BreathPeriodSet(float Period); + + /* Sets the Breath duty cycle between a 1-to-1 and 1-to-3 ratio. */ + void DutyCycleSet(float Period); + + /* BreatheStarts to the begining of the watering cycle. */ + void BreatheStart (int Index); + + /* Increments theflow rate sensor pulse counter. */ + void PulseFlowSensor (); + + /* Prints the state of object to the debug stream. */ + void Print (int Index); + + /* Polls the PulseOximeter and updates the target flow. */ + void Update (int Index); + + /* Updates the float rate. */ + bool CheckIfDoneBreathing (int Index); + + /* Opens the solenoid valve. */ + void Inhale (); + + /* Closes the solenoid valve. */ + void Exhale (); + + /* Samples the Atmospheric pressure and temperature. */ + void Tare (); + + /* Updates the channel with the DeviceTick. */ + void Update(); + + private: + + /* Calculates the pulse target value from the PulseOximeter value. */ + inline int CalcPulseTarget (); +}; +} //< namespace SickBay +#endif //< GHVentilatorChannelDecl