Skip to content

Commit 2c6afa5

Browse files
authored
feat: disable status leds while app runs (#633)
1 parent 81769d4 commit 2c6afa5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

internal/orchestrator/helpers.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78
"slices"
89
"strings"
910

@@ -186,3 +187,29 @@ func GetCustomErrorFomDockerEvent(message string) error {
186187

187188
return nil
188189
}
190+
191+
type LedTrigger string
192+
193+
const (
194+
LedTriggerNone LedTrigger = "none"
195+
LedTriggerDefault LedTrigger = "default"
196+
)
197+
198+
var statusLeds = paths.NewPathList(
199+
"/sys/class/leds/blue:bt/trigger",
200+
"/sys/class/leds/green:wlan/trigger",
201+
"/sys/class/leds/red:panic/trigger",
202+
)
203+
204+
func setStatusLeds(trigger LedTrigger) error {
205+
for _, ledPath := range statusLeds {
206+
if !ledPath.Exist() {
207+
return fmt.Errorf("LED path %s does not exist", ledPath)
208+
}
209+
var value string
210+
if err := os.WriteFile(ledPath.String(), []byte(trigger), 0600); err != nil {
211+
return fmt.Errorf("failed to set LED %s to %s: %w", ledPath, value, err)
212+
}
213+
}
214+
return nil
215+
}

internal/orchestrator/orchestrator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func StartApp(
115115
return
116116
}
117117

118+
if err := setStatusLeds(LedTriggerNone); err != nil {
119+
slog.Debug("unable to set status leds", slog.String("error", err.Error()))
120+
}
121+
118122
sketchCallbackWriter := NewCallbackWriter(func(line string) {
119123
if !yield(StreamMessage{data: line}) {
120124
cancel()
@@ -302,6 +306,10 @@ func stopAppWithCmd(ctx context.Context, app app.ArduinoApp, cmd string) iter.Se
302306
ctx, cancel := context.WithCancel(ctx)
303307
defer cancel()
304308

309+
if err := setStatusLeds(LedTriggerDefault); err != nil {
310+
slog.Debug("unable to set status leds", slog.String("error", err.Error()))
311+
}
312+
305313
callbackWriter := NewCallbackWriter(func(line string) {
306314
if !yield(StreamMessage{data: line}) {
307315
cancel()

0 commit comments

Comments
 (0)