Integrate relays, improve logging

This commit is contained in:
2022-09-18 16:09:21 -06:00
parent 1833ecf607
commit cc123773b5
3 changed files with 80 additions and 34 deletions
+58 -25
View File
@@ -16,16 +16,14 @@
#define ENTER_BUTTON 30
#define DOWN_BUTTON 27
#define PRESSURE_SENSOR_PIN A0
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
static const unsigned char PROGMEM arrow[] =
{ B10000000,
B11000000,
B11100000,
B11000000,
B10000000};
//static const unsigned char PROGMEM arrow[] =
//{ B10000000,
// B11000000,
// B11100000,
// B11000000,
// B10000000};
//oled.drawBitmap(0, 1, arrow, 8, 5, 1);
@@ -51,14 +49,34 @@ enum screenStates {
SAY_HOLD,
SAY_TIMEOUT,
SETTINGS,
NUM_SCREENSTATES
};
static const char* stateLabels[] = {
"BOOT_UP",
"PRESSURE",
"SET_POINT",
"INIT_RUN",
"BEGIN_RUN",
"MEASURING",
"RUNNING",
"SAY_DONE",
"SAY_CANCEL",
"SAY_HOLD",
"SAY_TIMEOUT",
"SETTINGS",
};
enum buttonStates upButton = OPEN;
enum buttonStates enterButton = OPEN;
enum buttonStates downButton = OPEN;
enum screenStates screenState = BOOT_UP;
float pressureValue = 0.0;
int pressureSetPoint = 0;
//float initialPressure = 0.0;
//float runningPressure = 0.0;
float sampledPressure = 0.0;
int debounceValue(float value) {
static int prevValue = (int) value;
@@ -82,34 +100,57 @@ void setup()
pinMode(ENTER_BUTTON, INPUT); // Has external pullup
pinMode(DOWN_BUTTON, INPUT_PULLUP);
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
digitalWrite(RELAY1_PIN, HIGH);
digitalWrite(RELAY2_PIN, HIGH);
#ifdef SIMULATE
initSimulation();
#endif
resamplePressure(pressureValue, PRESSURE_SENSOR_PIN);
resamplePressure(pressureValue);
}
void loop() {
measurePressure(pressureValue, PRESSURE_SENSOR_PIN);
measurePressure(pressureValue);
pollButtons();
runUI();
logData();
#ifdef SIMULATE
tickSimulation();
#endif
}
void logData() {
static unsigned long lastLogTime = millis();
if (millis() > lastLogTime + 100) {
Serial.print("pressure: ");
Serial.print(pressureValue);
#ifdef SIMULATE
Serial.print(", simulated: ");
Serial.print(simulatedPressure);
#endif
Serial.print(", sampled: ");
Serial.print(sampledPressure);
Serial.print(", setpoint: ");
Serial.print(pressureSetPoint);
Serial.print(", state: ");
Serial.print(stateLabels[screenState]);
Serial.println("");
lastLogTime = millis();
}
}
void runUI() {
static enum screenStates screenState = BOOT_UP;
static enum screenStates nextState = BOOT_UP;
static unsigned long timer = millis();
static int pressureSetPoint = 0;
static unsigned long startTime = millis();
//static float initialPressure = 0.0;
//static float runningPressure = 0.0;
static float sampledPressure = 0.0;
static bool isInflating = false;
static bool isDeflating = false;
@@ -118,14 +159,6 @@ void runUI() {
oled.clearDisplay();
Serial.print("pressure: ");
Serial.print(pressureValue);
Serial.print(", sampled: ");
Serial.print(sampledPressure);
Serial.print(", setpoint: ");
Serial.print(pressureSetPoint);
Serial.println("");
switch (screenState) {
case BOOT_UP:
if (millis() >= timer + 2000) {
@@ -274,7 +307,7 @@ void runUI() {
if (millis() < timer + 500) {
// wait for solenoids to settle before averaging
resamplePressure(pressureValue, PRESSURE_SENSOR_PIN);
resamplePressure(pressureValue);
}
setSoleniod(SOLENOID_STOP);