|
|
@@ -1,11 +1,20 @@
|
|
|
|
|
|
|
|
// Tire Inflation Firmware
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Board: Adafruit Feather nRF52832
|
|
|
|
|
|
|
|
// Setup: https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup
|
|
|
|
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
#include <Adafruit_SSD1306.h>
|
|
|
|
#include <Adafruit_SSD1306.h>
|
|
|
|
#include <Adafruit_FeatherOLED.h>
|
|
|
|
#include <Adafruit_FeatherOLED.h> // make sure to add:
|
|
|
|
|
|
|
|
// #define VBATPIN 0
|
|
|
|
|
|
|
|
// #define VBAT_MULTIPLIER 0
|
|
|
|
|
|
|
|
// to Adafruit_FeatherOLED.cpp
|
|
|
|
|
|
|
|
// or Adafruit_FeatherOLED_SH110X.cpp
|
|
|
|
|
|
|
|
|
|
|
|
#include "hardware.h"
|
|
|
|
#include "hardware.h"
|
|
|
|
|
|
|
|
|
|
|
|
//#define SIMULATE 1
|
|
|
|
#define SIMULATE 1
|
|
|
|
#define DEBUG 0
|
|
|
|
#define DEBUG 0
|
|
|
|
|
|
|
|
|
|
|
|
#define TIMEOUT_TIME 7000
|
|
|
|
#define TIMEOUT_TIME 7000
|
|
|
@@ -36,7 +45,7 @@ enum buttonStates {
|
|
|
|
NUM_BUTTONSTATES
|
|
|
|
NUM_BUTTONSTATES
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum screenStates {
|
|
|
|
enum machineStates {
|
|
|
|
BOOT_UP,
|
|
|
|
BOOT_UP,
|
|
|
|
PRESSURE,
|
|
|
|
PRESSURE,
|
|
|
|
SET_POINT,
|
|
|
|
SET_POINT,
|
|
|
@@ -71,7 +80,7 @@ enum buttonStates upButton = OPEN;
|
|
|
|
enum buttonStates enterButton = OPEN;
|
|
|
|
enum buttonStates enterButton = OPEN;
|
|
|
|
enum buttonStates downButton = OPEN;
|
|
|
|
enum buttonStates downButton = OPEN;
|
|
|
|
|
|
|
|
|
|
|
|
enum screenStates screenState = BOOT_UP;
|
|
|
|
enum machineStates machineState = BOOT_UP;
|
|
|
|
double pressureValue = 0.0;
|
|
|
|
double pressureValue = 0.0;
|
|
|
|
int pressureSetPoint = 0;
|
|
|
|
int pressureSetPoint = 0;
|
|
|
|
double initialPressure = 0.0;
|
|
|
|
double initialPressure = 0.0;
|
|
|
@@ -108,9 +117,9 @@ void setup()
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATE
|
|
|
|
#ifdef SIMULATE
|
|
|
|
initSimulation();
|
|
|
|
initSimulation();
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
initHardware();
|
|
|
|
initHardware();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
resamplePressure(pressureValue);
|
|
|
|
resamplePressure(pressureValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -118,7 +127,7 @@ void setup()
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
measurePressure(pressureValue);
|
|
|
|
measurePressure(pressureValue);
|
|
|
|
pollButtons();
|
|
|
|
pollButtons();
|
|
|
|
runUI();
|
|
|
|
runStateMachine();
|
|
|
|
logData();
|
|
|
|
logData();
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATE
|
|
|
|
#ifdef SIMULATE
|
|
|
@@ -130,7 +139,9 @@ void logData() {
|
|
|
|
static unsigned long lastLogTime = millis();
|
|
|
|
static unsigned long lastLogTime = millis();
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() > lastLogTime + 100) {
|
|
|
|
if (millis() > lastLogTime + 100) {
|
|
|
|
Serial.print("pressure: ");
|
|
|
|
//Serial.print("millis: ");
|
|
|
|
|
|
|
|
//Serial.print(millis());
|
|
|
|
|
|
|
|
Serial.print(", pressure: ");
|
|
|
|
Serial.print(pressureValue);
|
|
|
|
Serial.print(pressureValue);
|
|
|
|
#ifdef SIMULATE
|
|
|
|
#ifdef SIMULATE
|
|
|
|
Serial.print(", simulated: ");
|
|
|
|
Serial.print(", simulated: ");
|
|
|
@@ -138,20 +149,20 @@ void logData() {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
Serial.print(", sampled: ");
|
|
|
|
Serial.print(", sampled: ");
|
|
|
|
Serial.print(sampledPressure);
|
|
|
|
Serial.print(sampledPressure);
|
|
|
|
Serial.print(", rate (inv): ");
|
|
|
|
//Serial.print(", rate (inv): ");
|
|
|
|
Serial.print(runningRateInv);
|
|
|
|
//Serial.print(runningRateInv);
|
|
|
|
Serial.print(", setpoint: ");
|
|
|
|
Serial.print(", setpoint: ");
|
|
|
|
Serial.print(pressureSetPoint);
|
|
|
|
Serial.print(pressureSetPoint);
|
|
|
|
Serial.print(", state: ");
|
|
|
|
Serial.print(", state: ");
|
|
|
|
Serial.print(stateLabels[screenState]);
|
|
|
|
Serial.print(stateLabels[machineState]);
|
|
|
|
Serial.println("");
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
|
|
|
|
lastLogTime = millis();
|
|
|
|
lastLogTime = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void runUI() {
|
|
|
|
void runStateMachine() {
|
|
|
|
static enum screenStates nextState = BOOT_UP;
|
|
|
|
static enum machineStates nextState = BOOT_UP;
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long timer = millis();
|
|
|
|
static unsigned long timer = millis();
|
|
|
|
|
|
|
|
|
|
|
@@ -165,10 +176,10 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
oled.clearDisplay();
|
|
|
|
oled.clearDisplay();
|
|
|
|
|
|
|
|
|
|
|
|
switch (screenState) {
|
|
|
|
switch (machineState) {
|
|
|
|
case BOOT_UP:
|
|
|
|
case BOOT_UP:
|
|
|
|
if (millis() >= timer + 2000) {
|
|
|
|
if (millis() >= timer + 2000) {
|
|
|
|
screenState = PRESSURE;
|
|
|
|
machineState = PRESSURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oled.setCursor(0,0);
|
|
|
|
oled.setCursor(0,0);
|
|
|
@@ -184,25 +195,25 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case PRESSURE:
|
|
|
|
case PRESSURE:
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
screenState = SAY_HOLD;
|
|
|
|
machineState = SAY_HOLD;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (enterButton == HELD) {
|
|
|
|
} else if (enterButton == HELD) {
|
|
|
|
; // settings?
|
|
|
|
; // settings?
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
screenState = SET_POINT;
|
|
|
|
machineState = SET_POINT;
|
|
|
|
pressureSetPoint = debouncedPressureValue+1;
|
|
|
|
pressureSetPoint = debouncedPressureValue+1;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (downButton == PRESSED) {
|
|
|
|
} else if (downButton == PRESSED) {
|
|
|
|
screenState = SET_POINT;
|
|
|
|
machineState = SET_POINT;
|
|
|
|
pressureSetPoint = debouncedPressureValue-1;
|
|
|
|
pressureSetPoint = debouncedPressureValue-1;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (upButton == HELD) {
|
|
|
|
} else if (upButton == HELD) {
|
|
|
|
screenState = SET_POINT;
|
|
|
|
machineState = SET_POINT;
|
|
|
|
pressureSetPoint = debouncedPressureValue+1;
|
|
|
|
pressureSetPoint = debouncedPressureValue+1;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (downButton == HELD) {
|
|
|
|
} else if (downButton == HELD) {
|
|
|
|
screenState = SET_POINT;
|
|
|
|
machineState = SET_POINT;
|
|
|
|
pressureSetPoint = debouncedPressureValue-1;
|
|
|
|
pressureSetPoint = debouncedPressureValue-1;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -217,12 +228,12 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case SET_POINT:
|
|
|
|
case SET_POINT:
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
screenState = SAY_HOLD;
|
|
|
|
machineState = SAY_HOLD;
|
|
|
|
nextState = SET_POINT;
|
|
|
|
nextState = SET_POINT;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (enterButton == HELD) {
|
|
|
|
} else if (enterButton == HELD) {
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
screenState = INIT_RUN;
|
|
|
|
machineState = INIT_RUN;
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
pressureSetPoint++;
|
|
|
|
pressureSetPoint++;
|
|
|
@@ -238,7 +249,7 @@ void runUI() {
|
|
|
|
pressureSetPoint--;
|
|
|
|
pressureSetPoint--;
|
|
|
|
delay(75);
|
|
|
|
delay(75);
|
|
|
|
} else if (millis() >= timer + TIMEOUT_TIME) {
|
|
|
|
} else if (millis() >= timer + TIMEOUT_TIME) {
|
|
|
|
screenState = SAY_TIMEOUT;
|
|
|
|
machineState = SAY_TIMEOUT;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -258,7 +269,7 @@ void runUI() {
|
|
|
|
initialPressure = pressureValue;
|
|
|
|
initialPressure = pressureValue;
|
|
|
|
startTime = millis();
|
|
|
|
startTime = millis();
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
screenState = BEGIN_RUN;
|
|
|
|
machineState = BEGIN_RUN;
|
|
|
|
|
|
|
|
|
|
|
|
oled.setCursor(0,0);
|
|
|
|
oled.setCursor(0,0);
|
|
|
|
oled.setTextSize(1);
|
|
|
|
oled.setTextSize(1);
|
|
|
@@ -276,7 +287,7 @@ void runUI() {
|
|
|
|
isInflating = false;
|
|
|
|
isInflating = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
screenState = SAY_DONE;
|
|
|
|
machineState = SAY_DONE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -288,7 +299,7 @@ void runUI() {
|
|
|
|
if (millis() >= timer + 5000) {
|
|
|
|
if (millis() >= timer + 5000) {
|
|
|
|
//runningPressure = pressureValue;
|
|
|
|
//runningPressure = pressureValue;
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
screenState = MEASURING;
|
|
|
|
machineState = MEASURING;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -296,44 +307,45 @@ void runUI() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MEASURING:
|
|
|
|
case MEASURING:
|
|
|
|
|
|
|
|
if (millis() < timer + 500) {
|
|
|
|
|
|
|
|
// wait for solenoids to settle before averaging
|
|
|
|
|
|
|
|
resamplePressure(pressureValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() >= timer + 3000) {
|
|
|
|
if (millis() >= timer + 3000) {
|
|
|
|
sampledPressure = pressureValue;
|
|
|
|
sampledPressure = pressureValue;
|
|
|
|
|
|
|
|
|
|
|
|
runningRateInv = (stopTime - startTime) / (sampledPressure - initialPressure);
|
|
|
|
runningRateInv = (stopTime - startTime) / (sampledPressure - initialPressure);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("stopTime: ");
|
|
|
|
//Serial.print("stopTime: ");
|
|
|
|
Serial.print(stopTime);
|
|
|
|
//Serial.print(stopTime);
|
|
|
|
Serial.print(", startTime: ");
|
|
|
|
//Serial.print(", startTime: ");
|
|
|
|
Serial.print(startTime);
|
|
|
|
//Serial.print(startTime);
|
|
|
|
Serial.print(", sampledPressure: ");
|
|
|
|
//Serial.print(", sampledPressure: ");
|
|
|
|
Serial.print(sampledPressure);
|
|
|
|
//Serial.print(sampledPressure);
|
|
|
|
Serial.print(", initialPressure: ");
|
|
|
|
//Serial.print(", initialPressure: ");
|
|
|
|
Serial.print(initialPressure);
|
|
|
|
//Serial.print(initialPressure);
|
|
|
|
Serial.print(", rate: ");
|
|
|
|
//Serial.print(", rate: ");
|
|
|
|
Serial.print(runningRateInv);
|
|
|
|
//Serial.print(runningRateInv);
|
|
|
|
Serial.println("");
|
|
|
|
//Serial.println("");
|
|
|
|
|
|
|
|
|
|
|
|
initialPressure = sampledPressure;
|
|
|
|
initialPressure = sampledPressure;
|
|
|
|
|
|
|
|
|
|
|
|
if (isInflating && (int) sampledPressure >= pressureSetPoint) {
|
|
|
|
if (isInflating && (int) sampledPressure >= pressureSetPoint) {
|
|
|
|
screenState = SAY_DONE;
|
|
|
|
machineState = SAY_DONE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
} else if (isDeflating && (int) sampledPressure <= pressureSetPoint) {
|
|
|
|
} else if (isDeflating && (int) sampledPressure <= pressureSetPoint) {
|
|
|
|
screenState = SAY_DONE;
|
|
|
|
machineState = SAY_DONE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
screenState = RUNNING;
|
|
|
|
machineState = RUNNING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
startTime = millis();
|
|
|
|
startTime = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() < timer + 500) {
|
|
|
|
|
|
|
|
// wait for solenoids to settle before averaging
|
|
|
|
|
|
|
|
resamplePressure(pressureValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
|
|
|
|
|
|
|
|
oled.setCursor(0,0);
|
|
|
|
oled.setCursor(0,0);
|
|
|
@@ -348,27 +360,27 @@ void runUI() {
|
|
|
|
case RUNNING:
|
|
|
|
case RUNNING:
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
if (enterButton == PRESSED) {
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
screenState = SAY_CANCEL;
|
|
|
|
machineState = SAY_CANCEL;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
} else if (upButton == PRESSED) {
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
screenState = SAY_CANCEL;
|
|
|
|
machineState = SAY_CANCEL;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
} else if (downButton == PRESSED) {
|
|
|
|
} else if (downButton == PRESSED) {
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
setSoleniod(SOLENOID_STOP);
|
|
|
|
screenState = SAY_CANCEL;
|
|
|
|
machineState = SAY_CANCEL;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
nextState = PRESSURE;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isInflating && millis() >= timer + 20000) {
|
|
|
|
if (isInflating && millis() >= timer + 20000) {
|
|
|
|
screenState = MEASURING;
|
|
|
|
machineState = MEASURING;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
} else if (isDeflating && millis() >= timer + 10000) {
|
|
|
|
} else if (isDeflating && millis() >= timer + 10000) {
|
|
|
|
screenState = MEASURING;
|
|
|
|
machineState = MEASURING;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
stopTime = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -403,7 +415,7 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case SAY_DONE:
|
|
|
|
case SAY_DONE:
|
|
|
|
if (millis() >= timer + 3000) {
|
|
|
|
if (millis() >= timer + 3000) {
|
|
|
|
screenState = nextState;
|
|
|
|
machineState = nextState;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -417,7 +429,7 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case SAY_CANCEL:
|
|
|
|
case SAY_CANCEL:
|
|
|
|
if (millis() >= timer + 1000) {
|
|
|
|
if (millis() >= timer + 1000) {
|
|
|
|
screenState = nextState;
|
|
|
|
machineState = nextState;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -431,7 +443,7 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case SAY_HOLD:
|
|
|
|
case SAY_HOLD:
|
|
|
|
if (millis() >= timer + 500) {
|
|
|
|
if (millis() >= timer + 500) {
|
|
|
|
screenState = nextState;
|
|
|
|
machineState = nextState;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -445,7 +457,7 @@ void runUI() {
|
|
|
|
|
|
|
|
|
|
|
|
case SAY_TIMEOUT:
|
|
|
|
case SAY_TIMEOUT:
|
|
|
|
if (millis() >= timer + 1000) {
|
|
|
|
if (millis() >= timer + 1000) {
|
|
|
|
screenState = nextState;
|
|
|
|
machineState = nextState;
|
|
|
|
timer = millis();
|
|
|
|
timer = millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|