Add setpoint and run screens

This commit is contained in:
Tanner Collin 2022-09-15 15:47:58 -06:00
parent 8e0aa533e9
commit d9c3b6acaa

View File

@ -6,6 +6,7 @@
#define DEBUG 0 #define DEBUG 0
#define TIMEOUT_TIME 7000
#define BUTTON_HOLD_TIME 500 #define BUTTON_HOLD_TIME 500
#define BUTTON_PRESS_TIME 20 #define BUTTON_PRESS_TIME 20
@ -13,6 +14,8 @@
#define ENTER_BUTTON 30 #define ENTER_BUTTON 30
#define DOWN_BUTTON 27 #define DOWN_BUTTON 27
#define PRESSURE_SENSOR_PIN A0
Adafruit_FeatherOLED oled = Adafruit_FeatherOLED(); Adafruit_FeatherOLED oled = Adafruit_FeatherOLED();
static const unsigned char PROGMEM arrow[] = static const unsigned char PROGMEM arrow[] =
@ -34,7 +37,14 @@ enum buttonStates {
}; };
enum screenStates { enum screenStates {
BOOT_UP,
PRESSURE, PRESSURE,
SET_POINT,
BEGIN_RUN,
RUNNING,
SAY_CANCEL,
SAY_HOLD,
SAY_TIMEOUT,
SETTINGS, SETTINGS,
NUM_SCREENSTATES NUM_SCREENSTATES
}; };
@ -43,6 +53,7 @@ enum buttonStates upButton = OPEN;
enum buttonStates enterButton = OPEN; enum buttonStates enterButton = OPEN;
enum buttonStates downButton = OPEN; enum buttonStates downButton = OPEN;
float pressureValue = 0.0;
int pressureSetPoint = 69; int pressureSetPoint = 69;
void setup() void setup()
@ -57,35 +68,215 @@ void setup()
} }
void loop() { void loop() {
measurePressure();
pollButtons(); pollButtons();
runUI(); runUI();
} }
void measurePressure() {
int sensorValue = analogRead(PRESSURE_SENSOR_PIN);
float adjusted = 0.098 * sensorValue - 16.56 + 3.58;
pressureValue = 0.99 * pressureValue + 0.01 * adjusted;
}
void runUI() { void runUI() {
static enum screenStates screenState = PRESSURE; static enum screenStates screenState = BOOT_UP;
static enum screenStates nextState = BOOT_UP;
static unsigned long timer = millis();
static unsigned long runTime = millis();
int num_dots = 0;
oled.clearDisplay(); oled.clearDisplay();
switch (screenState) { switch (screenState) {
case PRESSURE: case BOOT_UP:
if (enterButton == HELD) screenState = SETTINGS; if (millis() >= timer + 2000) {
screenState = PRESSURE;
}
if (upButton == PRESSED) { oled.setCursor(0,0);
oled.setTextSize(2);
oled.println("STC TECH");
oled.setTextSize(1);
oled.println("");
oled.print(" INITIALIZING");
oled.display();
break;
case PRESSURE:
if (enterButton == PRESSED) {
screenState = SAY_HOLD;
nextState = PRESSURE;
timer = millis();
} else if (enterButton == HELD) {
;
} else if (upButton == PRESSED) {
screenState = SET_POINT;
pressureSetPoint = (int) pressureValue;
timer = millis();
} else if (downButton == PRESSED) {
screenState = SET_POINT;
pressureSetPoint = (int) pressureValue;
timer = millis();
} else if (upButton == HELD) {
screenState = SET_POINT;
pressureSetPoint = (int) pressureValue;
timer = millis();
} else if (downButton == HELD) {
screenState = SET_POINT;
pressureSetPoint = (int) pressureValue;
timer = millis();
}
oled.setCursor(0,0);
oled.setTextSize(3);
oled.print((int) pressureValue);
oled.print(" PSI");
oled.display();
break;
case SET_POINT:
if (enterButton == PRESSED) {
screenState = SAY_HOLD;
nextState = SET_POINT;
timer = millis();
} else if (enterButton == HELD) {
screenState = BEGIN_RUN;
timer = millis();
} else if (upButton == PRESSED) {
timer = millis();
pressureSetPoint++; pressureSetPoint++;
} else if (downButton == PRESSED) { } else if (downButton == PRESSED) {
timer = millis();
pressureSetPoint--; pressureSetPoint--;
} else if (upButton == HELD) { } else if (upButton == HELD) {
timer = millis();
pressureSetPoint++; pressureSetPoint++;
delay(75); delay(75);
} else if (downButton == HELD) { } else if (downButton == HELD) {
timer = millis();
pressureSetPoint--; pressureSetPoint--;
delay(75); delay(75);
} else if (millis() >= timer + TIMEOUT_TIME) {
screenState = SAY_TIMEOUT;
nextState = PRESSURE;
timer = millis();
} }
oled.setCursor(0,0); oled.setCursor(0,0);
oled.setTextSize(3); oled.setTextSize(3);
oled.print(pressureSetPoint); oled.print(pressureSetPoint);
oled.println(" PSI");
oled.setTextSize(1);
oled.println("TARGET");
oled.display();
break;
case BEGIN_RUN:
if (millis() >= timer + 2000) {
screenState = RUNNING;
runTime = millis();
}
oled.setCursor(0,0);
oled.setTextSize(1);
oled.println("");
oled.setTextSize(2);
if (pressureSetPoint > (int) pressureValue) {
oled.print("INFLATING");
} else if (pressureSetPoint < (int) pressureValue) {
oled.print("DEFLATING");
} else {
oled.print("DONE");
}
oled.display();
break;
case RUNNING:
if (enterButton == PRESSED) {
screenState = SAY_CANCEL;
nextState = PRESSURE;
timer = millis();
} else if (upButton == PRESSED) {
screenState = SAY_CANCEL;
nextState = PRESSURE;
timer = millis();
} else if (downButton == PRESSED) {
screenState = SAY_CANCEL;
nextState = PRESSURE;
timer = millis();
}
oled.setCursor(0,0);
oled.setTextSize(3);
oled.print((int) pressureValue);
oled.println(" PSI");
oled.setTextSize(1);
if (pressureSetPoint > (int) pressureValue) {
oled.print("INFLATING");
} else if (pressureSetPoint < (int) pressureValue) {
oled.print("DEFLATING");
} else {
oled.print("DONE");
}
num_dots = (int) ((millis() - runTime) / 400) % 4;
for (int i = 0; i < num_dots; i++) {
oled.print(".");
}
oled.display();
break;
case SAY_CANCEL:
if (millis() >= timer + 1000) {
screenState = nextState;
timer = millis();
}
oled.setCursor(0,0);
oled.setTextSize(3);
oled.print("CANCEL");
oled.display();
break;
case SAY_HOLD:
if (millis() >= timer + 500) {
screenState = nextState;
timer = millis();
}
oled.setCursor(0,0);
oled.setTextSize(3);
oled.print("HOLD");
oled.display();
break;
case SAY_TIMEOUT:
if (millis() >= timer + 1000) {
screenState = nextState;
timer = millis();
}
oled.setCursor(0,0);
oled.setTextSize(3);
oled.print("TIMEOUT");
oled.display(); oled.display();