Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add signal handling and system LED cleanup to the Python
Appframework so that LED1 and LED2 are properly restored when an app is stopped via SIGTERM.Problem
When an app is stopped, LED1 and LED2 (MPU-controlled via sysfs) remain lit in whatever state the app left them. LED3 and LED4 (MCU-controlled) reset automatically because the MCU resets on app stop.
The Python
Appframework had no signal handling and no cleanup logic. Whenarduino-app-clisends SIGTERM to the container, the process was killed immediately without restoring LED brightness or triggers.Changes
app.py(framework)App.run()with a_shutdown_requestedflagtry/finallyinApp.run()to guarantee_cleanup_system_resources()runs after_stop_all_bricks()_cleanup_system_resources()callsLeds.restore_system_control()leds.py(framework)set_led1_color()orset_led2_color()saves the original statebluetooth-power,phy0tx,none)arduino-app-cli(see note below)app.js(color-your-leds example PR on app-bricks-examples )socket.on('connect')handler to re-sync all LED states on every socket reconnection, so the physical LEDs match the UI after an app restart without needing a browser refreshNote on
arduino-app-cliinteractionarduino-app-clicallssetStatusLeds(LedTriggerDefault)on app stop, which writes"default"to LED2 trigger files. In the Linux kernel LED subsystem,"default"maps to thedefault-ontrigger driver — it does not restore the original triggers (bluetooth-power,phy0tx). This means system services (bluetoothd, WiFi driver) lose LED control after app stop.This PR includes a workaround:
leds.pyhardcodes the known correct system triggers for LED2 and writes them during cleanup, overriding the incorrect"default"value. This is architecturally suboptimal because:arduino-app-clion the host can always restore triggers after the container stops.arduino-app-cli(knows the paths) andleds.py(knows the correct values).arduino-app-clichanges triggers before the container stops; the restore should happen after.After that fix lands,
leds.pycan be simplified to remove_led2_system_triggersand only handle LED1 triggers + LED2 brightness reset. The current workaround is forward-compatible and will not conflict with the CLI fix.