refactor(doorbell-touch): extract board configs and improve logging
This commit is contained in:
4
boards/esp32-32e-4/board-config.sh
Normal file
4
boards/esp32-32e-4/board-config.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default"
|
||||||
|
PORT="/dev/ttyUSB0"
|
||||||
|
LIBS="--libraries ./vendor/esp32-32e-4/TFT_eSPI"
|
||||||
|
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM"
|
||||||
4
boards/esp32-32e/board-config.sh
Normal file
4
boards/esp32-32e/board-config.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default"
|
||||||
|
PORT="/dev/ttyUSB0"
|
||||||
|
LIBS="--libraries ./vendor/esp32-32e/TFT_eSPI"
|
||||||
|
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM"
|
||||||
4
boards/esp32-s3-lcd-43/board-config.sh
Normal file
4
boards/esp32-s3-lcd-43/board-config.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FQBN="esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB"
|
||||||
|
PORT="/dev/ttyACM0"
|
||||||
|
LIBS="--libraries ./vendor/esp32-s3-lcd-43/LovyanGFX"
|
||||||
|
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM -DLGFX_USE_V1"
|
||||||
@@ -133,7 +133,8 @@ void DoorbellLogic::update() {
|
|||||||
default:
|
default:
|
||||||
// Inactivity timeout: turn off screen after no activity
|
// Inactivity timeout: turn off screen after no activity
|
||||||
if(_state.screen != ScreenID::OFF && now - _lastActivityMs > INACTIVITY_TIMEOUT_MS) {
|
if(_state.screen != ScreenID::OFF && now - _lastActivityMs > INACTIVITY_TIMEOUT_MS) {
|
||||||
Serial.println("[STATE] Inactivity timeout → OFF");
|
Serial.printf("[%lu] [STATE] Inactivity timeout (%lu ms) → OFF\n",
|
||||||
|
millis(), now - _lastActivityMs);
|
||||||
_state.screen = ScreenID::OFF;
|
_state.screen = ScreenID::OFF;
|
||||||
_display->setBacklight(false);
|
_display->setBacklight(false);
|
||||||
_state.backlightOn = false;
|
_state.backlightOn = false;
|
||||||
@@ -229,10 +230,12 @@ void DoorbellLogic::onAdmin(const String& cmd) {
|
|||||||
delay(500);
|
delay(500);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
} else if(cmd == "dashboard") {
|
} else if(cmd == "dashboard") {
|
||||||
|
Serial.printf("[%lu] [ADMIN] dashboard\n", millis());
|
||||||
_state.screen = ScreenID::DASHBOARD;
|
_state.screen = ScreenID::DASHBOARD;
|
||||||
_display->setBacklight(true);
|
_display->setBacklight(true);
|
||||||
_state.backlightOn = true;
|
_state.backlightOn = true;
|
||||||
} else if(cmd == "off") {
|
} else if(cmd == "off") {
|
||||||
|
Serial.printf("[%lu] [ADMIN] off\n", millis());
|
||||||
_state.screen = ScreenID::OFF;
|
_state.screen = ScreenID::OFF;
|
||||||
_display->setBacklight(false);
|
_display->setBacklight(false);
|
||||||
_state.backlightOn = false;
|
_state.backlightOn = false;
|
||||||
@@ -312,7 +315,7 @@ int DoorbellLogic::handleTouch(const TouchEvent& evt) {
|
|||||||
_lastActivityMs = millis();
|
_lastActivityMs = millis();
|
||||||
|
|
||||||
if(_state.screen == ScreenID::OFF) {
|
if(_state.screen == ScreenID::OFF) {
|
||||||
Serial.println("[TOUCH] OFF → DASHBOARD");
|
Serial.printf("[%lu] [TOUCH] OFF → DASHBOARD\n", millis());
|
||||||
setScreen(ScreenID::DASHBOARD);
|
setScreen(ScreenID::DASHBOARD);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
136
mise.toml
136
mise.toml
@@ -6,70 +6,41 @@
|
|||||||
[tools]
|
[tools]
|
||||||
hk = "latest"
|
hk = "latest"
|
||||||
pkl = "latest"
|
pkl = "latest"
|
||||||
|
# zellij = "latest" # Install manually if needed (brew install zellij)
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
# BOARD=esp32-32e-4 mise run compile # compile
|
# BOARD=esp32-32e-4 mise run compile # compile
|
||||||
# BOARD=esp32-32e-4 mise run upload # upload
|
# BOARD=esp32-32e-4 mise run upload # upload
|
||||||
# BOARD=esp32-32e-4 mise run monitor # monitor
|
# BOARD=esp32-32e-4 mise run monitor # monitor
|
||||||
# BOARD=esp32-32e-4 mise run monitor-screen # screen monitor with auto-reconnect
|
# BOARD=esp32-32e-4 mise run monitor-screen # shows tio command to run manually
|
||||||
#
|
#
|
||||||
# Valid BOARD: esp32-32e, esp32-32e-4, esp32-s3-43
|
# Valid BOARD: esp32-32e, esp32-32e-4, esp32-s3-lcd-43
|
||||||
|
# Board config lives in: boards/{BOARD}/board-config.sh
|
||||||
|
|
||||||
[tasks.compile]
|
[tasks.compile]
|
||||||
description = "Compile (uses BOARD env var)"
|
description = "Compile (uses BOARD env var)"
|
||||||
run = """
|
run = """
|
||||||
case "$BOARD" in
|
source ./boards/$BOARD/board-config.sh
|
||||||
esp32-32e)
|
|
||||||
FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default"
|
|
||||||
LIBS="--libraries ./vendor/esp32-32e/TFT_eSPI"
|
|
||||||
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM"
|
|
||||||
;;
|
|
||||||
esp32-32e-4)
|
|
||||||
FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default"
|
|
||||||
LIBS="--libraries ./vendor/esp32-32e-4/TFT_eSPI"
|
|
||||||
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM"
|
|
||||||
;;
|
|
||||||
esp32-s3-43)
|
|
||||||
FQBN="esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB"
|
|
||||||
LIBS="--libraries ./vendor/esp32-s3-lcd-43/LovyanGFX"
|
|
||||||
OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM -DLGFX_USE_V1"
|
|
||||||
;;
|
|
||||||
*) echo "Unknown BOARD: $BOARD" && exit 1 ;;
|
|
||||||
esac
|
|
||||||
arduino-cli compile --fqbn "$FQBN" --libraries ./libraries $LIBS --build-property "compiler.cpp.extra_flags=$OPTS" --warnings default ./boards/$BOARD
|
arduino-cli compile --fqbn "$FQBN" --libraries ./libraries $LIBS --build-property "compiler.cpp.extra_flags=$OPTS" --warnings default ./boards/$BOARD
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[tasks.upload]
|
[tasks.upload]
|
||||||
description = "Upload (uses BOARD env var)"
|
description = "Upload (uses BOARD env var)"
|
||||||
run = """
|
run = """
|
||||||
# Kill any screen session holding the port
|
source ./boards/$BOARD/board-config.sh
|
||||||
screen -X -S doorbell quit 2>/dev/null || true
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
case "$BOARD" in
|
LOCKFILE="/tmp/doorbell-$BOARD.lock"
|
||||||
esp32-32e) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
if [ -f "$LOCKFILE" ]; then
|
||||||
esp32-32e-4) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
echo "Error: Another instance is running (lockfile exists: $LOCKFILE)"
|
||||||
esp32-s3-43) PORT="${PORT:-/dev/ttyACM0}" ;;
|
echo "Remove with: rm $LOCKFILE"
|
||||||
*) echo "Unknown BOARD: $BOARD" && exit 1 ;;
|
exit 1
|
||||||
esac
|
fi
|
||||||
FQBN=""
|
trap 'rm -f "$LOCKFILE"' EXIT
|
||||||
case "$BOARD" in
|
touch "$LOCKFILE"
|
||||||
esp32-32e) FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default" ;;
|
|
||||||
esp32-32e-4) FQBN="esp32:esp32:esp32:FlashSize=4M,PartitionScheme=default" ;;
|
echo "Acquired lock: $LOCKFILE"
|
||||||
esp32-s3-43) FQBN="esp32:esp32:waveshare_esp32_s3_touch_lcd_43:PSRAM=enabled,FlashSize=16M,USBMode=hwcdc,PartitionScheme=app3M_fat9M_16MB" ;;
|
|
||||||
esac
|
PORT="${PORT:-$PORT}"
|
||||||
LIBS=""
|
|
||||||
case "$BOARD" in
|
|
||||||
esp32-32e) LIBS="--libraries ./vendor/esp32-32e/TFT_eSPI" ;;
|
|
||||||
esp32-32e-4) LIBS="--libraries ./vendor/esp32-32e-4/TFT_eSPI" ;;
|
|
||||||
esp32-s3-43) LIBS="--libraries ./vendor/esp32-s3-lcd-43/LovyanGFX" ;;
|
|
||||||
esac
|
|
||||||
OPTS=""
|
|
||||||
case "$BOARD" in
|
|
||||||
esp32-32e) OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM" ;;
|
|
||||||
esp32-32e-4) OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM" ;;
|
|
||||||
esp32-s3-43) OPTS="-DDEBUG_MODE -DBOARD_HAS_PSRAM -DLGFX_USE_V1" ;;
|
|
||||||
esac
|
|
||||||
arduino-cli compile --fqbn "$FQBN" --libraries ./libraries $LIBS --build-property "compiler.cpp.extra_flags=$OPTS" --warnings default ./boards/$BOARD && \
|
arduino-cli compile --fqbn "$FQBN" --libraries ./libraries $LIBS --build-property "compiler.cpp.extra_flags=$OPTS" --warnings default ./boards/$BOARD && \
|
||||||
arduino-cli upload --fqbn "$FQBN" --port "$PORT" ./boards/$BOARD
|
arduino-cli upload --fqbn "$FQBN" --port "$PORT" ./boards/$BOARD
|
||||||
"""
|
"""
|
||||||
@@ -77,42 +48,37 @@ arduino-cli upload --fqbn "$FQBN" --port "$PORT" ./boards/$BOARD
|
|||||||
[tasks.monitor]
|
[tasks.monitor]
|
||||||
description = "Monitor (uses BOARD env var)"
|
description = "Monitor (uses BOARD env var)"
|
||||||
run = """
|
run = """
|
||||||
case "$BOARD" in
|
source ./boards/$BOARD/board-config.sh
|
||||||
esp32-32e) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
PORT="${PORT:-$PORT}"
|
||||||
esp32-32e-4) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
|
||||||
esp32-s3-43) PORT="${PORT:-/dev/ttyACM0}" ;;
|
|
||||||
*) echo "Unknown BOARD: $BOARD" && exit 1 ;;
|
|
||||||
esac
|
|
||||||
TARGET="$(readlink -f "$PORT" 2>/dev/null || echo "$PORT")"
|
TARGET="$(readlink -f "$PORT" 2>/dev/null || echo "$PORT")"
|
||||||
arduino-cli monitor -p "$TARGET" --config baudrate=115200
|
arduino-cli monitor -p "$TARGET" --config baudrate=115200
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[tasks.monitor-screen]
|
[tasks.monitor-tio]
|
||||||
description = "Screen monitor with auto-reconnect (uses BOARD env var)"
|
description = "Show tio command to run in separate terminal"
|
||||||
run = """
|
run = """
|
||||||
case "$BOARD" in
|
source ./boards/$BOARD/board-config.sh
|
||||||
esp32-32e) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
|
||||||
esp32-32e-4) PORT="${PORT:-/dev/ttyUSB0}" ;;
|
LOCKFILE="/tmp/doorbell-$BOARD.lock"
|
||||||
esp32-s3-43) PORT="${PORT:-/dev/ttyACM0}" ;;
|
if [ -f "$LOCKFILE" ]; then
|
||||||
*) echo "Unknown BOARD: $BOARD" && exit 1 ;;
|
echo "Error: Another instance is running (lockfile exists: $LOCKFILE)"
|
||||||
esac
|
echo "Remove with: rm $LOCKFILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
trap 'rm -f "$LOCKFILE"' EXIT
|
||||||
|
touch "$LOCKFILE"
|
||||||
|
|
||||||
|
echo "Acquired lock: $LOCKFILE (Ctrl+C to release)"
|
||||||
|
|
||||||
|
PORT="${PORT:-$PORT}"
|
||||||
TARGET="$(readlink -f "$PORT" 2>/dev/null || echo "$PORT")"
|
TARGET="$(readlink -f "$PORT" 2>/dev/null || echo "$PORT")"
|
||||||
screen -dmS doorbell bash -c "
|
tio --map INLCRNL "$TARGET" -e
|
||||||
while true; do
|
|
||||||
echo \"Connecting to $TARGET...\"
|
|
||||||
arduino-cli monitor -p \"$TARGET\" --config baudrate=115200
|
|
||||||
echo \"Disconnected, retrying in 3s...\"
|
|
||||||
sleep 3
|
|
||||||
done
|
|
||||||
"
|
|
||||||
echo "Screen session 'doorbell' started. Attach with: screen -r doorbell"
|
|
||||||
echo "Detach: Ctrl+A D"
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[tasks.monitor-screen-kill]
|
[tasks.monitor-screen-kill]
|
||||||
description = "Kill screen-based monitor"
|
description = "Kill tio (Ctrl+C in the terminal)"
|
||||||
run = """
|
run = """
|
||||||
screen -X -S doorbell quit 2>/dev/null && echo "Killed screen session 'doorbell'" || echo "No session found"
|
echo "Press Ctrl+C in the tio terminal to exit"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[tasks.install-libs-shared]
|
[tasks.install-libs-shared]
|
||||||
@@ -197,7 +163,12 @@ echo "[OK] LovyanGFX vendored"
|
|||||||
|
|
||||||
[tasks.install-libs]
|
[tasks.install-libs]
|
||||||
description = "Install all libraries (shared + vendored)"
|
description = "Install all libraries (shared + vendored)"
|
||||||
depends = ["install-libs-shared", "install-libs-32e", "install-libs-32e-4", "install-libs-s3-43"]
|
depends = [
|
||||||
|
"install-libs-shared",
|
||||||
|
"install-libs-32e",
|
||||||
|
"install-libs-32e-4",
|
||||||
|
"install-libs-s3-43",
|
||||||
|
]
|
||||||
|
|
||||||
# Convenience
|
# Convenience
|
||||||
|
|
||||||
@@ -211,6 +182,23 @@ rm -rf boards/esp32-s3-lcd-43/build
|
|||||||
echo "[OK] Build artifacts cleaned"
|
echo "[OK] Build artifacts cleaned"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
[tasks.arduino-clean]
|
||||||
|
description = "Clean Arduino CLI cache (staging + packages)"
|
||||||
|
run = """
|
||||||
|
echo "Checking ~/.arduino15..."
|
||||||
|
du -sh ~/.arduino15/staging 2>/dev/null || echo "No staging folder"
|
||||||
|
du -sh ~/.arduino15/packages 2>/dev/null || echo "No packages folder"
|
||||||
|
read -p "Delete staging + packages folders? [y/N] " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
rm -rf ~/.arduino15/staging
|
||||||
|
rm -rf ~/.arduino15/packages
|
||||||
|
echo "[OK] Arduino staging + packages cleared"
|
||||||
|
else
|
||||||
|
echo "Aborted"
|
||||||
|
fi
|
||||||
|
"""
|
||||||
|
|
||||||
[tasks.format]
|
[tasks.format]
|
||||||
run = """
|
run = """
|
||||||
clang-format -i --style=file \
|
clang-format -i --style=file \
|
||||||
|
|||||||
Reference in New Issue
Block a user