Skip to content
Snippets Groups Projects
Commit 0eae8386 authored by Karol Hennessy's avatar Karol Hennessy
Browse files

fix to valve controller for exhale valve

parent 2eab5c14
Branches
No related merge requests found
...@@ -23,6 +23,8 @@ ValvesController::ValvesController() ...@@ -23,6 +23,8 @@ ValvesController::ValvesController()
_purge.proportional = false; _purge.proportional = false;
_purge.state = VALVE_STATE::CLOSED; _purge.state = VALVE_STATE::CLOSED;
_pin_to_chan[pin_valve_inhale] = pwm_chan_inhale;
_pin_to_chan[pin_valve_exhale] = pwm_chan_exhale;
} }
ValvesController::~ValvesController() ValvesController::~ValvesController()
...@@ -45,7 +47,11 @@ void ValvesController::setPWMValve(int pin, float frac_open) ...@@ -45,7 +47,11 @@ void ValvesController::setPWMValve(int pin, float frac_open)
#ifdef CHIP_ESP32 #ifdef CHIP_ESP32
int duty_cycle = calcValveDutyCycle(pwm_resolution, frac_open); int duty_cycle = calcValveDutyCycle(pwm_resolution, frac_open);
int chan = pin_to_chan[pin]; int chan = _pin_to_chan[pin];
//if (pin == pin_valve_exhale)
// chan = pwm_chan_exhale;
//else if (pin == pin_valve_inhale)
// chan = pwm_chan_inhale;
ledcWrite(chan, duty_cycle); ledcWrite(chan, duty_cycle);
#else #else
int duty_cycle = pow(2, pwm_resolution) * frac_open; int duty_cycle = pow(2, pwm_resolution) * frac_open;
......
...@@ -15,8 +15,6 @@ enum VALVE_STATE : bool ...@@ -15,8 +15,6 @@ enum VALVE_STATE : bool
OPEN = HIGH OPEN = HIGH
}; };
static int pin_to_chan[50]; // too lazy to create a proper hashmap for 2 variables; 50 pins is probably fine
static int chan_to_pin[50];
class ValvesController class ValvesController
{ {
...@@ -38,6 +36,7 @@ private: ...@@ -38,6 +36,7 @@ private:
valve _inhale; valve _inhale;
valve _exhale; valve _exhale;
valve _purge; valve _purge;
uint8_t _pin_to_chan[50];
}; };
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#endif #endif
// #include <MemoryFree.h> // #include <MemoryFree.h>
#include <Wire.h> #include <Wire.h>
#include <SPI.h>
#include <Adafruit_MCP9808.h> #include <Adafruit_MCP9808.h>
#include <INA.h> #include <INA.h>
#include "CommsControl.h" #include "CommsControl.h"
...@@ -41,8 +42,6 @@ void setup() ...@@ -41,8 +42,6 @@ void setup()
ledcAttachPin(pin_buzzer, 3); ledcAttachPin(pin_buzzer, 3);
ledcAttachPin(pin_valve_inhale , pwm_chan_inhale); ledcAttachPin(pin_valve_inhale , pwm_chan_inhale);
ledcAttachPin(pin_valve_exhale , pwm_chan_exhale); ledcAttachPin(pin_valve_exhale , pwm_chan_exhale);
pin_to_chan[pin_valve_inhale] = pwm_chan_inhale;
pin_to_chan[pin_valve_exhale] = pwm_chan_exhale;
// map<int,int> pin_to_chan; // = { pin_valve_inhale : pwm_chan_inhale , pin_valve_exhale : pwm_chan_exhale}; // map<int,int> pin_to_chan; // = { pin_valve_inhale : pwm_chan_inhale , pin_valve_exhale : pwm_chan_exhale};
#else #else
...@@ -54,7 +53,6 @@ void setup() ...@@ -54,7 +53,6 @@ void setup()
pinMode(pin_valve_air_in, OUTPUT); pinMode(pin_valve_air_in, OUTPUT);
pinMode(pin_valve_o2_in, OUTPUT); pinMode(pin_valve_o2_in, OUTPUT);
pinMode(pin_valve_purge, OUTPUT); pinMode(pin_valve_purge, OUTPUT);
pinMode(pin_valve_atmosphere, OUTPUT);
pinMode(pin_pressure_air_supply, INPUT); pinMode(pin_pressure_air_supply, INPUT);
pinMode(pin_pressure_air_regulated, INPUT); pinMode(pin_pressure_air_regulated, INPUT);
...@@ -72,7 +70,7 @@ void setup() ...@@ -72,7 +70,7 @@ void setup()
pinMode(pin_led_yellow, OUTPUT); pinMode(pin_led_yellow, OUTPUT);
pinMode(pin_led_red, OUTPUT); pinMode(pin_led_red, OUTPUT);
pinMode(pin_buzzer, OUTPUT); //pinMode(pin_buzzer, OUTPUT);
pinMode(pin_button_0, INPUT); pinMode(pin_button_0, INPUT);
comms.beginSerial(); comms.beginSerial();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment