Add basic hardware simulation
This commit is contained in:
+13
-7
@@ -3,7 +3,9 @@
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <Adafruit_FeatherOLED.h>
|
||||
|
||||
#include "hardware.h"
|
||||
|
||||
#define SIMULATE 1
|
||||
#define DEBUG 0
|
||||
|
||||
#define TIMEOUT_TIME 7000
|
||||
@@ -58,6 +60,8 @@ int pressureSetPoint = 69;
|
||||
|
||||
void setup()
|
||||
{
|
||||
randomSeed(analogRead(A1));
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
oled.init();
|
||||
@@ -65,18 +69,20 @@ void setup()
|
||||
pinMode(UP_BUTTON, INPUT_PULLUP);
|
||||
pinMode(ENTER_BUTTON, INPUT); // Has external pullup
|
||||
pinMode(DOWN_BUTTON, INPUT_PULLUP);
|
||||
|
||||
#ifdef SIMULATE
|
||||
initSimulation();
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
measurePressure();
|
||||
measurePressure(pressureValue, PRESSURE_SENSOR_PIN);
|
||||
pollButtons();
|
||||
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;
|
||||
#ifdef SIMULATE
|
||||
tickSimulation();
|
||||
#endif
|
||||
}
|
||||
|
||||
void runUI() {
|
||||
@@ -114,7 +120,7 @@ void runUI() {
|
||||
nextState = PRESSURE;
|
||||
timer = millis();
|
||||
} else if (enterButton == HELD) {
|
||||
;
|
||||
setSoleniod(SOLENOID_DEFLATE);
|
||||
} else if (upButton == PRESSED) {
|
||||
screenState = SET_POINT;
|
||||
pressureSetPoint = (int) pressureValue;
|
||||
|
||||
Reference in New Issue
Block a user