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: GHVentilator.h
- Revision:
- 3:d15b6579b5ae
- Parent:
- 2:1578ecfa9377
- Child:
- 4:de69851cf725
diff -r 1578ecfa9377 -r d15b6579b5ae GHVentilator.h --- a/GHVentilator.h Tue Apr 07 13:10:45 2020 +0000 +++ b/GHVentilator.h Wed Apr 08 07:16:51 2020 +0000 @@ -1,6 +1,6 @@ /** Gravity Hookah Ventilator @version 0.x -@link https://github.com/KabukiStarship/SickBay.git -@file /GHVentilator.h +@link https://github.com/KabukiStarship/SickBay.git +@file /GHVentilator.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, @@ -13,97 +13,94 @@ using namespace mbedBug; #include "GHVentilatorChannel.h" namespace SickBay { -/* -void DoGetData(Arguments* input, Reply* output); - -RPCFunction getData(&DoGetData, "getData"); - -void DoGetData(Arguments* input, Reply* output) { - // Arguments are already parsed into argv array of char* - printf("Object name = %s\n",input->obj_name); - printf("Method name = %s\n",input->method_name); - for (int i=0; i < input->argc; i++) - printf("argv[%1d] = %s \n",i,input->argv[i]); - - // Alternatively the arguments can be recovered as the types expected - // by repeated calls to getArg() - int arg0 = input->getArg<int>(); // Expecting argv[0] to be int - printf("Expecting argv[0] to be int = %d\n",arg0); - float arg1 = input->getArg<float>(); // Expecting argv[1] to be float - printf("Expecting argv[1] to be float = %f\n",arg1); - const char *arg2 = input->getArg<const char*>(); // Expecting argv[2] to be a string - printf("Expecting argv[2] to be a string = %s\n",arg2); - - // The output parameter string is generated by calls to putData, which separates them with spaces. - output->putData(arg0); - output->putData(arg1); - output->putData(arg2); -}*/ + +#define GHVentilatorPressureHysteresisPercent 0.25f //< +/- 25% histesis. /* A Gravity Hookah Ventilator. */ template<int ChannelCount> class GHVentilator { - public: - - enum { - ChannelCountMax = 4, - StateCalibratingPressureSensor = 0, - StateRunning = 1, - }; - - int State, //< The ventilator state. - Ticks, //< The tick. - TicksMax, //< The max tick count before it gets reset. - TicksSecond, //< The number of Ticks per Second. - TicksInhaleMin, //< The min inhale ticks. - TicksInhaleMax, //< The max breath period of 20 seconds. - TicksExhaleMin, //< The min ticks in an exhale. - TicksExhaleMax; //< The max ticks in an exhale. - float PressureMin, //< The min Pressure. - PressureMax, //< The max Pressure. - Pressure, //< The Pressure in the tank. - ServoMin, //< The min servo value. - ServoMax; //< The max servo value. - /* The amount the Pressure needs to change to count as having changed. */ - float PressureChangeDelta; - //< The GHV channels. - GHVentilatorChannel Channels[ChannelCountMax]; - BMP280 Atmosphere; //< Pressure sensor for the air tank. - DigitalOut Blower; //< A blower powered by a Solid State Relay. - - GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, - PinName BlowerPin, PinName StatusPin, - GHVentilatorChannel A); - - GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, - PinName BlowerPin, PinName StatusPin, - GHVentilatorChannel A, - GHVentilatorChannel B); - - GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, - PinName BlowerPin, PinName StatusPin, - GHVentilatorChannel A, - GHVentilatorChannel B, - GHVentilatorChannel C); - - GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, - PinName BlowerPin, PinName StatusPin, - GHVentilatorChannel A, - GHVentilatorChannel B, - GHVentilatorChannel C, - GHVentilatorChannel D); - - void ChannelSet (int ChannelIndex, float DutyCycle = 0.0f, - float Period = 0.0f); - /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ - void TarePressure(); - - /* Starts the system. */ - int Run (); - - /* Updates the main device and it's channels. */ - void Update (); + public: + + enum { + ChannelCountMax = 4, + StateCalibratingPressureSensor = 0, + StateRunning = 1, + }; + + // The tick and negative calibrating positive running states. + int Ticks, + TicksMax, //< The max tick count before it gets reset. + TicksSecond, //< The number of Ticks per Second. + TicksInhaleMin, //< The min inhale ticks. + TicksInhaleMax, //< The max breath period of 20 seconds. + TicksExhaleMin, //< The min ticks in an exhale. + TicksExhaleMax, //< The max ticks in an exhale. + TicksCalibration;//< The number of ticks in the calibration state. + float PressureMin, //< The min Pressure. + PressureMax, //< The max Pressure. + Pressure, //< The Pressure in the tank. + ServoMin, //< The min servo value. + ServoMax; //< The max servo value. + /* The amount the Pressure needs to change to count as having changed. */ + float PressureChangeDelta; + //< The GHV channels. + GHVentilatorChannel Channels[ChannelCountMax]; + BMP280 Atmosphere; //< Pressure sensor for the air tank. + DigitalOut Blower; //< A blower powered by a Solid State Relay. + + GHVentilator (int TicksPerSecond, int TicksCalibration, + I2C& I2CBus, char SlaveAddress, + PinName BlowerPin, PinName StatusPin, + GHVentilatorChannel A); + + GHVentilator (int TicksPerSecond, int TicksCalibration, + I2C& I2CBus, char SlaveAddress, + PinName BlowerPin, PinName StatusPin, + GHVentilatorChannel A, + GHVentilatorChannel B); + + GHVentilator (int TicksPerSecond, int TicksCalibration, + I2C& I2CBus, char SlaveAddress, + PinName BlowerPin, PinName StatusPin, + GHVentilatorChannel A, + GHVentilatorChannel B, + GHVentilatorChannel C); + + GHVentilator (int TicksPerSecond, I2C& I2CBus, char SlaveAddress, + PinName BlowerPin, PinName StatusPin, + GHVentilatorChannel A, + GHVentilatorChannel B, + GHVentilatorChannel C, + GHVentilatorChannel D); + + /* Gets the GHVentilatorChannel with the given Index. \ + @return Nil if the Index is out of bounds. */ + GHVentilatorChannel* Channel(int Index); + + void ChannelSet (int ChannelIndex, float DutyCycle = 0.0f, + float Period = 0.0f); + /* Reads the Atmospher.Pressure() and Atmospher.Temperature () */ + void TarePressure(); + + int TicksInhaleExhaleSet (int TicksInhale, int TicksExhale); + + /* Starts the system. */ + int Run (); + + /* Updates the main device and it's channels. */ + void Update (); }; +void HanleTicksSecondSet(Arguments* input, Reply* output); +void HanleInhaleTicksSet(Arguments* input, Reply* output); + +RPCFunction TicksSecondSet(&DoGetData, "TicksSecondSet"), + InhaleTicksSet(&DoGetData, "InhaleTicksSet"), + ExhaleTicksSet(&DoGetData, "ExhaleTicksSet"); + +void RemoteTicksSecondSetHandle(Arguments* input, Reply* output); + +void HandleTicksInhaleExhaleSet(Arguments* input, Reply* output); + } //< namespace SickBay #endif