diff --git a/arduino/hev_prototype_v1/src/ValvesController.cpp b/arduino/hev_prototype_v1/src/ValvesController.cpp index 380536bd6b0bdeeaba153915bfbe730c38fe8ef7..016b0b271786e98a276c844cffe795079cf225ab 100644 --- a/arduino/hev_prototype_v1/src/ValvesController.cpp +++ b/arduino/hev_prototype_v1/src/ValvesController.cpp @@ -23,6 +23,8 @@ ValvesController::ValvesController() _purge.proportional = false; _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() @@ -45,7 +47,11 @@ void ValvesController::setPWMValve(int pin, float frac_open) #ifdef CHIP_ESP32 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); #else int duty_cycle = pow(2, pwm_resolution) * frac_open; diff --git a/arduino/hev_prototype_v1/src/ValvesController.h b/arduino/hev_prototype_v1/src/ValvesController.h index aea1851508f7d81483a9ce75cca3c446164eb9f0..3cab0a3ccf8af8c94c96a4d95a1e4f0fba0c2aad 100644 --- a/arduino/hev_prototype_v1/src/ValvesController.h +++ b/arduino/hev_prototype_v1/src/ValvesController.h @@ -15,8 +15,6 @@ enum VALVE_STATE : bool 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 { @@ -38,6 +36,7 @@ private: valve _inhale; valve _exhale; valve _purge; + uint8_t _pin_to_chan[50]; }; diff --git a/arduino/hev_prototype_v1/src/main.cpp b/arduino/hev_prototype_v1/src/main.cpp index 05e78765920747e00d7b329d14ca137a7ad75f87..99920f9b91b35836489fe1787e7d5c7d5b2a89f7 100644 --- a/arduino/hev_prototype_v1/src/main.cpp +++ b/arduino/hev_prototype_v1/src/main.cpp @@ -5,6 +5,7 @@ #endif // #include <MemoryFree.h> #include <Wire.h> +#include <SPI.h> #include <Adafruit_MCP9808.h> #include <INA.h> #include "CommsControl.h" @@ -41,8 +42,6 @@ void setup() ledcAttachPin(pin_buzzer, 3); ledcAttachPin(pin_valve_inhale , pwm_chan_inhale); 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}; #else @@ -54,7 +53,6 @@ void setup() pinMode(pin_valve_air_in, OUTPUT); pinMode(pin_valve_o2_in, OUTPUT); pinMode(pin_valve_purge, OUTPUT); - pinMode(pin_valve_atmosphere, OUTPUT); pinMode(pin_pressure_air_supply, INPUT); pinMode(pin_pressure_air_regulated, INPUT); @@ -72,7 +70,7 @@ void setup() pinMode(pin_led_yellow, OUTPUT); pinMode(pin_led_red, OUTPUT); - pinMode(pin_buzzer, OUTPUT); + //pinMode(pin_buzzer, OUTPUT); pinMode(pin_button_0, INPUT); comms.beginSerial();