Skip to content

Commit

Permalink
Merge pull request #55 from netmindz/T-RSC3
Browse files Browse the repository at this point in the history
Lilygo T-RSC3 Support
  • Loading branch information
netmindz authored Oct 7, 2023
2 parents 202ec77 + 22c5041 commit 9e9cb91
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
11 changes: 11 additions & 0 deletions sensor/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions sensor/src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 54 additions & 4 deletions sensor/src/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.h>
Adafruit_NeoPixel pixels(1, 4, NEO_GRB + NEO_KHZ800);

#elif ESP32
#define tub Serial2
#define RX_PIN 19
#define TX_PIN 23
Expand Down Expand Up @@ -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);
Expand All @@ -264,6 +304,7 @@ void setup() {
Serial.print(".");
}
}
setPixel(STATUS_WIFI);

if (WiFi.status() != WL_CONNECTED) {
#ifdef AP_FALLBACK
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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();
Expand Down Expand Up @@ -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") { // "-"
Expand Down

0 comments on commit 9e9cb91

Please sign in to comment.