Kabuki Starship / SickBayTek

Dependencies:   KabukiTek

Dependents:   GHVentilator

SBVentilatorChannel.h

Committer:
kabukistarship
Date:
2020-04-11
Revision:
1:278bfa29bd0d
Parent:
0:7319afbc731c

File content as of revision 1:278bfa29bd0d:

/** SickBay Tek @version 0.x
@link    https://github.com/KabukiStarship/SickBay.git
@file    /SBVentilatorChannel.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 SBVentilatorChannelDecl
#define SBVentilatorChannelDecl
#include <_Config.h>
#ifndef SBVentilatorChannelCount
#define SBVentilatorChannelCount 1
#endif
namespace SickBay {
    
class SBVentilator;

/* A Ventilator channel for one patient. */
class SBVentilatorChannel {
  public:
  
  enum {
    StateInhaling = 1,      //< The inhaling state is where Ticks < 0.
    StateOff = 0,           //< The off state is where Ticks = 0.
    StateExhaling = -1,     //< The exhaling state is where Ticks > 0.
  };
  
  SBVentilator* Parent;     //< The SBVentilator this is part of.
  int Ticks,                //< Ticks since the beginning of the inhale.
      TicksInhale,          //< The tick count in the inhale duty cycle.
      TicksExhale,          //< The period of the breathing.
      TicksFlow,            //< The number of flow sensor ticks.
      TicksFlowLast,        //< The previous inhale cycle TicksFlow count.
      PulseOximeter,        //< The 7-pin pulse oximeter value.
      Servo,                //< The Servo for reducing the pressrue.
      ServoClosed,          //< The min servo duty cycle of no air flow.
      ServoOpen;            //< The max servo duty cycle of an open tube.
  int32_t Temperature,      //< The Temperature of the patients breath.
      TemperatureReference; //< The refernce temperature upon Tare.
  uint32_t Pressure,        //< The pressure in the patient's mask.
      PressureReference,    //< About 1 atmosphere + the hysteresis delta.
      PressureHysteresis;   //< The hysteresis above the PressureReference. 
  
  /* Initializes the channel.
  @param PressureHysteresis 1.0 + the percent hysteresis up and down from the 
  center the 
  */
  void Init (SBVentilator* Parent, int TicksInhale, int TicksExhale, 
             float ChannelPressureHysteresis);
             
  /* Doesn't do anything and requires a call to . */
  SBVentilatorChannel ();
    
  /* Returns a pointer to this. */
  SBVentilatorChannel* This();
  
  void ChannelValveSet (SBVentilatorChannel* Channel, int Value);
  
  /* Turns this channel off. */
  void TurnOff ();
    
  /* Sets the number of ticks on the inhale and exhale. */
  void TicksInhaleExhaleSet (int NewTicksInhale, int NewTicksExhale);
    
  /* Increments theflow rate sensor pulse counter. */
  void TickFlow ();
    
  /* Prints the state of object to the debug stream. */
  void Print (int Index);
    
  /* Opens the solenoid valve. */
  void Inhale ();
    
  /* Closes the solenoid valve. */
  void Exhale ();
    
  /* Samples the Atmospheric pressure and temperature. */
  void Tare (float PressureHysteresis);
  
  /* Monitor the channel for if errors. */
  int Monitor ();
    
  /* Updates the channel with the DeviceTick. */
  void Update();
};
}   //< namespace SickBay
#endif