add bed cooler project.
This commit is contained in:
BIN
scripts/__pycache__/build_ota_package.cpython-313.pyc
Normal file
BIN
scripts/__pycache__/build_ota_package.cpython-313.pyc
Normal file
Binary file not shown.
BIN
scripts/__pycache__/build_upload_device.cpython-313.pyc
Normal file
BIN
scripts/__pycache__/build_upload_device.cpython-313.pyc
Normal file
Binary file not shown.
BIN
scripts/__pycache__/upload_device.cpython-313.pyc
Normal file
BIN
scripts/__pycache__/upload_device.cpython-313.pyc
Normal file
Binary file not shown.
84
scripts/build_ota_package.py
Normal file
84
scripts/build_ota_package.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
DEFAULT_ENV = "seeed_xiao_esp32c3"
|
||||
|
||||
|
||||
def find_pio():
|
||||
pio = shutil.which("pio")
|
||||
if pio:
|
||||
return pio
|
||||
candidate = Path.home() / ".platformio" / "penv" / "Scripts" / "pio.exe"
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
candidate = Path.home() / ".platformio" / "penv" / "bin" / "pio"
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
return "pio"
|
||||
|
||||
|
||||
def run(command, cwd):
|
||||
print("+ " + " ".join(command), flush=True)
|
||||
subprocess.run(command, check=True, cwd=cwd)
|
||||
|
||||
|
||||
def project_name(root):
|
||||
app_h = root / "include" / "app.h"
|
||||
if app_h.exists():
|
||||
match = re.search(r'^\s*#define\s+PROJECT_NAME\s+"([^"]+)"', app_h.read_text(encoding="utf-8"), re.MULTILINE)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return root.name
|
||||
|
||||
|
||||
def safe_filename_part(value):
|
||||
value = value.strip().replace(" ", "-")
|
||||
return re.sub(r"[^A-Za-z0-9._+-]+", "-", value).strip("-") or "project"
|
||||
|
||||
|
||||
def package_timestamp():
|
||||
return datetime.now().astimezone().isoformat(timespec="seconds").replace(":", "-")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Build firmware and LittleFS, then create a timestamped OTA update package.")
|
||||
parser.add_argument("-e", "--environment", default=DEFAULT_ENV, help="PlatformIO environment to build.")
|
||||
parser.add_argument("-o", "--output-dir", default="dist", help="Directory for the generated OTA package.")
|
||||
parser.add_argument("--pio", default=find_pio(), help="Path to the PlatformIO executable.")
|
||||
args = parser.parse_args()
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
build_dir = root / ".pio" / "build" / args.environment
|
||||
firmware = build_dir / "firmware.bin"
|
||||
filesystem = build_dir / "littlefs.bin"
|
||||
output_dir = (root / args.output_dir).resolve()
|
||||
output = output_dir / f"{safe_filename_part(project_name(root))}_{package_timestamp()}.tslpkg"
|
||||
|
||||
try:
|
||||
run([args.pio, "run", "-e", args.environment, "-t", "buildfs"], root)
|
||||
run([args.pio, "run", "-e", args.environment], root)
|
||||
run([
|
||||
sys.executable,
|
||||
str(Path(__file__).resolve().parent / "create_update_package.py"),
|
||||
"--firmware",
|
||||
str(firmware),
|
||||
"--filesystem",
|
||||
str(filesystem),
|
||||
"--output",
|
||||
str(output),
|
||||
], root)
|
||||
except subprocess.CalledProcessError as error:
|
||||
sys.exit(error.returncode)
|
||||
|
||||
print(f"OTA update file: {output.resolve()}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
57
scripts/build_upload_device.py
Normal file
57
scripts/build_upload_device.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
DEFAULT_ENV = "seeed_xiao_esp32c3"
|
||||
|
||||
|
||||
def find_pio():
|
||||
pio = shutil.which("pio")
|
||||
if pio:
|
||||
return pio
|
||||
candidate = Path.home() / ".platformio" / "penv" / "Scripts" / "pio.exe"
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
candidate = Path.home() / ".platformio" / "penv" / "bin" / "pio"
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
return "pio"
|
||||
|
||||
|
||||
def run(command, cwd):
|
||||
print("+ " + " ".join(command), flush=True)
|
||||
subprocess.run(command, check=True, cwd=cwd)
|
||||
|
||||
|
||||
def pio_command(args, pio, environment, upload_port):
|
||||
command = [pio, "run", "-e", environment] + args
|
||||
if upload_port:
|
||||
command += ["--upload-port", upload_port]
|
||||
return command
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Build firmware and LittleFS, then upload both to a connected device.")
|
||||
parser.add_argument("-e", "--environment", default=DEFAULT_ENV, help="PlatformIO environment to build and upload.")
|
||||
parser.add_argument("-p", "--upload-port", help="Upload port, for example COM3.")
|
||||
parser.add_argument("--pio", default=find_pio(), help="Path to the PlatformIO executable.")
|
||||
args = parser.parse_args()
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
try:
|
||||
run(pio_command(["-t", "buildfs"], args.pio, args.environment, None), root)
|
||||
run(pio_command([], args.pio, args.environment, None), root)
|
||||
run(pio_command(["-t", "uploadfs"], args.pio, args.environment, args.upload_port), root)
|
||||
run(pio_command(["-t", "upload"], args.pio, args.environment, args.upload_port), root)
|
||||
except subprocess.CalledProcessError as error:
|
||||
sys.exit(error.returncode)
|
||||
|
||||
print(f"Uploaded filesystem and firmware for {args.environment} from {root}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
35
scripts/create_update_package.py
Normal file
35
scripts/create_update_package.py
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import struct
|
||||
from pathlib import Path
|
||||
|
||||
MAGIC = b"TSLUPD1\0"
|
||||
HEADER_SIZE = 32
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Create a combined ESP32 update package.")
|
||||
parser.add_argument("--firmware", default=".pio/build/seeed_xiao_esp32c3/firmware.bin")
|
||||
parser.add_argument("--filesystem", default=".pio/build/seeed_xiao_esp32c3/littlefs.bin")
|
||||
parser.add_argument("--output", default=".pio/build/seeed_xiao_esp32c3/update.tslpkg")
|
||||
args = parser.parse_args()
|
||||
|
||||
firmware_path = Path(args.firmware)
|
||||
filesystem_path = Path(args.filesystem)
|
||||
output_path = Path(args.output)
|
||||
|
||||
firmware = firmware_path.read_bytes()
|
||||
filesystem = filesystem_path.read_bytes()
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
header = MAGIC + struct.pack("<III", HEADER_SIZE, len(filesystem), len(firmware)) + bytes(12)
|
||||
output_path.write_bytes(header + filesystem + firmware)
|
||||
|
||||
print(f"Created {output_path}")
|
||||
print(f" filesystem: {filesystem_path} ({len(filesystem)} bytes)")
|
||||
print(f" firmware: {firmware_path} ({len(firmware)} bytes)")
|
||||
print(f" total: {output_path.stat().st_size} bytes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
9
scripts/platformio_targets.py
Normal file
9
scripts/platformio_targets.py
Normal file
@@ -0,0 +1,9 @@
|
||||
Import("env")
|
||||
|
||||
env.AddCustomTarget(
|
||||
"uploadall",
|
||||
["upload", "uploadfs"],
|
||||
[],
|
||||
title="Upload Firmware and Filesystem",
|
||||
description="Upload firmware and the LittleFS image from data/",
|
||||
)
|
||||
Reference in New Issue
Block a user