diff --git a/sensor/platformio.ini b/sensor/platformio.ini index bf58527..05cafd2 100644 --- a/sensor/platformio.ini +++ b/sensor/platformio.ini @@ -37,3 +37,14 @@ upload_flags = [env:d1_mini_lite] board = d1_mini_lite platform = espressif8266 + +[env:t-rsc3] ; Lilygo T-RSC3 +platform = espressif32 +board = esp32-c3-devkitm-1 +lib_deps = + ${env.lib_deps} + https://github.com/adafruit/Adafruit_NeoPixel.git#1.11.1 +build_flags = + -D RSC3 + -DARDUINO_USB_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 diff --git a/sensor/src/constants.h b/sensor/src/constants.h index 9ea0834..ddd8e60 100644 --- a/sensor/src/constants.h +++ b/sensor/src/constants.h @@ -25,3 +25,9 @@ #else #define PUMP2_STATE_HIGH 1 #endif + +#define STATUS_BOOT 0 +#define STATUS_WIFI 2 +#define STATUS_OK 1 +#define STATUS_WAITING_DATA 3 +#define STATUS_WAITING_PANEL 4 \ No newline at end of file diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.ino index 607c0b0..9a23df0 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.ino @@ -57,7 +57,18 @@ const int MINUTES_PER_DEGC = 45; #define DELAY_TIME_DEFAULT 40 int delayTime = DELAY_TIME_DEFAULT; -#ifdef ESP32 + +#ifdef RSC3 +#define tub Serial1 +#define RX_PIN 3 +#define TX_PIN 10 +#define RTS_PIN 5 // RS485 direction control, RequestToSend TX or RX, required for MAX485 board. +#define PIN_5_PIN 6 + +#include +Adafruit_NeoPixel pixels(1, 4, NEO_GRB + NEO_KHZ800); + +#elif ESP32 #define tub Serial2 #define RX_PIN 19 #define TX_PIN 23 @@ -231,13 +242,42 @@ void onTargetTemperatureCommand(HANumeric temperature, HAHVAC* sender) { // the control unit reports that assume our commands worked } +void setPixel(uint8_t color) { +#ifdef RSC3 + switch(color) { + case 0: + pixels.setPixelColor(0, pixels.Color(255,0,0)); + break; + case 1: + pixels.setPixelColor(0, pixels.Color(0,255,0)); + break; + case 2: + pixels.setPixelColor(0, pixels.Color(0,0,255)); + break; + case 3: + pixels.setPixelColor(0, pixels.Color(255,255,0)); + break; + case 4: + pixels.setPixelColor(0, pixels.Color(255,0,255)); + break; + } + pixels.show(); +#endif +} + boolean isConnected = false; void setup() { Serial.begin(115200); delay(1000); +#ifdef RSC3 + pixels.begin(); + pixels.setBrightness(255); + setPixel(STATUS_BOOT); +#else pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); +#endif // Make sure you're in station mode WiFi.mode(WIFI_STA); @@ -264,6 +304,7 @@ void setup() { Serial.print("."); } } + setPixel(STATUS_WIFI); if (WiFi.status() != WL_CONNECTED) { #ifdef AP_FALLBACK @@ -416,7 +457,7 @@ String lastRaw5 = ""; String lastRaw6 = ""; String lastRaw7 = ""; String lastJSON = ""; -int lastUptime = 0; +uint32_t lastUptime = 0; String timeString = ""; int msgLength = 0; boolean panelDetected = false; @@ -426,6 +467,7 @@ void handleBytes(size_t len, uint8_t buf[]); void loop() { bool panelSelect = digitalRead(PIN_5_PIN); // LOW when we are meant to read data if (tub.available() > 0) { + setPixel(STATUS_OK); size_t len = tub.available(); // Serial.printf("bytes avail = %u\n", len); uint8_t buf[len]; // TODO: swap to fixed buffer to help prevent fragmentation of memory @@ -438,6 +480,14 @@ void loop() { msgLength = 0; } } + else { + if(panelDetected) { + setPixel(STATUS_WAITING_DATA); + } + else { + setPixel(STATUS_WAITING_PANEL); + } + } if (panelSelect == HIGH || !panelDetected) { // Controller talking to other topside panels - we are in effect idle @@ -454,7 +504,7 @@ void loop() { telnetLoop(); - if (sendBuffer.isEmpty()) { // Only handle status is we aren't trying to send commands, webserver and websocket + if (sendBuffer.isEmpty() || !panelDetected) { // Only handle status is we aren't trying to send commands, webserver and websocket // can both block for a long time webserver.handleClient(); @@ -681,7 +731,7 @@ void handleMessage() { float timeToTempValue = (tempDiff * MINUTES_PER_DEGC); timeToTemp.setValue(timeToTempValue); } else { - timeToTemp.setValue(0); + timeToTemp.setValue((float) 0); } } } else if (result.substring(10, 12) == "2d") { // "-"