firmware: migrate cargo controller to LilyGO T-Relay S3

This commit is contained in:
2026-06-29 22:57:02 -06:00
parent 406033bec8
commit 4cbd2165b2
10 changed files with 127 additions and 95 deletions
@@ -7,68 +7,27 @@ AppConfig appConfig;
static Preferences preferences;
static RelayConfig defaultRelayConfig(uint8_t channel, const char *name, const char *role) {
return {
"relay_" + String(channel),
name,
role,
channel,
RELAY_SHIFT_REGISTER_PIN,
true,
true
};
}
void loadDefaultConfig() {
appConfig.deviceName = "Overland Controller";
appConfig.relays[0] = {
"relay_1",
"Relay 1",
"aux",
1,
RELAY_1_PIN,
true,
true
};
appConfig.relays[1] = {
"relay_2",
"Relay 2",
"fridge",
2,
RELAY_2_PIN,
true,
true
};
appConfig.relays[2] = {
"relay_3",
"Relay 3",
"starlink",
3,
0,
true,
true
};
appConfig.relays[3] = {
"relay_4",
"Relay 4",
"aux",
4,
0,
true,
true
};
appConfig.relays[4] = {
"relay_5",
"Relay 5",
"aux",
5,
0,
true,
true
};
appConfig.relays[5] = {
"relay_6",
"Relay 6",
"aux",
6,
0,
true,
true
};
appConfig.relays[0] = defaultRelayConfig(1, "Relay 1", "aux");
appConfig.relays[1] = defaultRelayConfig(2, "Relay 2", "fridge");
appConfig.relays[2] = defaultRelayConfig(3, "Relay 3", "starlink");
appConfig.relays[3] = defaultRelayConfig(4, "Relay 4", "aux");
appConfig.relays[4] = defaultRelayConfig(5, "Relay 5", "aux");
appConfig.relays[5] = defaultRelayConfig(6, "Relay 6", "aux");
appConfig.tempSensorCount = 4;
@@ -234,7 +193,7 @@ void printConfig() {
Serial.print(appConfig.relays[i].role);
Serial.print(" / channel ");
Serial.print(appConfig.relays[i].hardwareChannel);
Serial.print(" / GPIO ");
Serial.print(" / channel ");
Serial.print(appConfig.relays[i].pin);
Serial.print(" / available ");
Serial.print(appConfig.relays[i].available ? "true" : "false");
+12 -11
View File
@@ -2,24 +2,25 @@
#define DEVICE_NAME "Overland Controller"
// Relay Outputs
#define RELAY_1_PIN 16
#define RELAY_2_PIN 17
// LilyGO T-Relay S3 6-relay board.
// Relays are driven through onboard 74HC595 shift register.
#define LILYGO_T_RELAY_S3_DATA_PIN 7
#define LILYGO_T_RELAY_S3_CLOCK_PIN 5
#define LILYGO_T_RELAY_S3_LATCH_PIN 6
#define LILYGO_T_RELAY_S3_OE_PIN 4
#define LILYGO_T_RELAY_S3_RELAY_COUNT 6
// DS18B20 Bus
#define ONEWIRE_PIN 4
// Compatibility placeholder only. Relays are not direct GPIO outputs.
#define RELAY_SHIFT_REGISTER_PIN 255
// GPIO4 is used by the LilyGO relay shift-register OE pin.
#define ONEWIRE_PIN 14
// Ignition Sense
#define IGNITION_PIN 34
// Cargo OLED service/setup display
#define OLED_I2C_SDA_PIN 21
#define OLED_I2C_SCL_PIN 22
#define OLED_SETUP_BUTTON_PIN 25
// Dashboard communication is WiFi/HTTP.
// Legacy UART dashboard support is retired from active hardware use.
#define DASHBOARD_UART_ENABLED 0
#define DASHBOARD_UART_BAUD 115200
// RS-485/MAX3485 is fallback only and not currently planned.
+42 -7
View File
@@ -5,20 +5,55 @@
RelayState relays;
static uint8_t relayShiftRegisterState = 0;
static void writeRelayShiftRegister()
{
digitalWrite(LILYGO_T_RELAY_S3_LATCH_PIN, LOW);
shiftOut(
LILYGO_T_RELAY_S3_DATA_PIN,
LILYGO_T_RELAY_S3_CLOCK_PIN,
MSBFIRST,
relayShiftRegisterState
);
digitalWrite(LILYGO_T_RELAY_S3_LATCH_PIN, HIGH);
}
void initRelays() {
for (int i = 0; i < MAX_RELAYS; i++) {
if (appConfig.relays[i].available) {
pinMode(appConfig.relays[i].pin, OUTPUT);
}
}
pinMode(LILYGO_T_RELAY_S3_DATA_PIN, OUTPUT);
pinMode(LILYGO_T_RELAY_S3_CLOCK_PIN, OUTPUT);
pinMode(LILYGO_T_RELAY_S3_LATCH_PIN, OUTPUT);
pinMode(LILYGO_T_RELAY_S3_OE_PIN, OUTPUT);
// Keep outputs disabled while clearing the shift register.
digitalWrite(LILYGO_T_RELAY_S3_OE_PIN, HIGH);
relayShiftRegisterState = 0;
writeRelayShiftRegister();
// Enable relay outputs after known-off state is written.
digitalWrite(LILYGO_T_RELAY_S3_OE_PIN, LOW);
updateRelayOutputs();
}
void updateRelayOutputs() {
uint8_t nextState = 0;
for (int i = 0; i < MAX_RELAYS; i++) {
if (appConfig.relays[i].available) {
digitalWrite(appConfig.relays[i].pin, relays.state[i]);
if (!appConfig.relays[i].available) {
continue;
}
const uint8_t channel = appConfig.relays[i].hardwareChannel;
if (channel < 1 || channel > LILYGO_T_RELAY_S3_RELAY_COUNT) {
continue;
}
if (relays.state[i]) {
nextState |= (1U << (channel - 1));
}
}
relayShiftRegisterState = nextState;
writeRelayShiftRegister();
}