add proper firmware flashing screen

This commit is contained in:
cottongin
2026-01-27 13:16:20 -05:00
parent 7349fbb208
commit a04388fd6c
8 changed files with 357 additions and 0 deletions

47
scripts/pre_flash.py Normal file
View File

@@ -0,0 +1,47 @@
"""
Pre-upload script that sends FLASH command to device before firmware upload.
This allows the firmware to display "Flashing firmware..." on the e-ink display
before the actual flash begins. The e-ink retains this message throughout the
flash process since it doesn't require power to maintain the display.
Protocol: Sends "FLASH:version\n" where version is read from platformio.ini
"""
Import("env")
import serial
import time
from version_utils import get_version
def before_upload(source, target, env):
"""Send FLASH command with version to device before upload begins."""
port = env.GetProjectOption("upload_port", None)
if not port:
import serial.tools.list_ports
# Look for common ESP32-C3 USB serial port patterns
ports = [
p.device
for p in serial.tools.list_ports.comports()
if "usbmodem" in p.device.lower() or "ttyacm" in p.device.lower()
]
port = ports[0] if ports else None
if port:
try:
version = get_version(env)
ser = serial.Serial(port, 115200, timeout=1)
ser.write(f"FLASH:{version}\n".encode())
ser.flush()
ser.close()
time.sleep(0.8) # Wait for e-ink fast refresh (~500ms) plus margin
print(f"[pre_flash] Flash notification sent to {port} (version {version})")
except Exception as e:
print(f"[pre_flash] Notification skipped: {e}")
else:
print("[pre_flash] No serial port found, skipping notification")
env.AddPreAction("upload", before_upload)

26
scripts/version_hash.py Normal file
View File

@@ -0,0 +1,26 @@
"""
Build script that adds git hash to CROSSPOINT_VERSION for dev builds.
This script runs during the build process and modifies the CROSSPOINT_VERSION
define to include the short git commit hash, e.g., "0.15.1-dev@7349fbb"
"""
Import("env")
from version_utils import get_git_short_hash
# Only modify version for non-release builds
pio_env = env.get("PIOENV", "default")
if pio_env != "gh_release":
git_hash = get_git_short_hash()
if git_hash:
# Get current build flags and find/replace CROSSPOINT_VERSION
build_flags = env.get("BUILD_FLAGS", [])
new_flags = []
for flag in build_flags:
if "CROSSPOINT_VERSION" in flag and "-dev" in flag:
# Replace -dev with -dev@hash
flag = flag.replace("-dev", f"-dev@{git_hash}")
new_flags.append(flag)
env.Replace(BUILD_FLAGS=new_flags)
print(f"[version_hash] Added git hash to version: @{git_hash}")

47
scripts/version_utils.py Normal file
View File

@@ -0,0 +1,47 @@
"""
Shared version utilities for PlatformIO build scripts.
Provides functions to get version info including git hash for dev builds.
"""
import configparser
import subprocess
def get_git_short_hash():
"""Get the short hash of the current HEAD commit."""
try:
result = subprocess.run(
["git", "rev-parse", "--short", "HEAD"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except Exception:
return None
def get_version(env):
"""
Get version from platformio.ini, adding -dev@hash suffix for dev builds.
Args:
env: PlatformIO environment object
Returns:
Version string, e.g., "0.15.1" or "0.15.1-dev@7349fbb"
"""
config = configparser.ConfigParser()
config.read("platformio.ini")
version = config.get("crosspoint", "version", fallback="unknown")
# Add -dev@hash suffix for non-release environments (matches platformio.ini build_flags)
pio_env = env.get("PIOENV", "default")
if pio_env != "gh_release":
version += "-dev"
git_hash = get_git_short_hash()
if git_hash:
version += f"@{git_hash}"
return version