Skip to content

Commit 917639a

Browse files
committed
nav
1 parent 7162ae7 commit 917639a

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

cmd/rpi_exporter/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ func main() {
4141
log.Println("Sense HAT initialized")
4242
defer hat.Close()
4343

44-
// Clear LED matrix on startup
44+
// Clear LED matrix on startup and set nav lights
4545
if err := hat.ClearLEDs(); err != nil {
4646
log.Printf("Warning: Failed to clear LEDs: %v", err)
4747
}
48+
if err := hat.SetNavLights(); err != nil {
49+
log.Printf("Warning: Failed to set nav lights: %v", err)
50+
}
4851

4952
if hat.HasColorSensor() {
5053
log.Println("Color sensor detected (Sense HAT v2)")
@@ -62,9 +65,9 @@ func main() {
6265
if *flagAddr != "" {
6366
// Metrics endpoint
6467
http.Handle("/metrics", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
65-
// Flash LED on scrape
68+
// Flash strobes on scrape
6669
if hat != nil {
67-
go hat.FlashLED(0, 0, 0, 255, 0, 100*time.Millisecond)
70+
go hat.FlashStrobes(100 * time.Millisecond)
6871
}
6972
var buf bytes.Buffer
7073
if err := prometheus.Write(&buf, cfg); err != nil {
@@ -118,11 +121,16 @@ func main() {
118121

119122
switch r.Method {
120123
case http.MethodDelete:
121-
// Clear all LEDs
124+
// Clear all LEDs (except nav lights)
122125
if err := hat.ClearLEDs(); err != nil {
123126
http.Error(w, err.Error(), http.StatusInternalServerError)
124127
return
125128
}
129+
// Restore nav lights
130+
if err := hat.SetNavLights(); err != nil {
131+
http.Error(w, err.Error(), http.StatusInternalServerError)
132+
return
133+
}
126134
w.WriteHeader(http.StatusNoContent)
127135

128136
case http.MethodPost:
@@ -138,6 +146,11 @@ func main() {
138146
http.Error(w, "invalid JSON: "+err.Error(), http.StatusBadRequest)
139147
return
140148
}
149+
// Protect top row (strobes) and bottom row (nav lights)
150+
if req.Y == 0 || req.Y == 7 {
151+
http.Error(w, "top and bottom rows are reserved for nav/strobe lights", http.StatusForbidden)
152+
return
153+
}
141154
if err := hat.SetPixel(req.X, req.Y, req.R, req.G, req.B); err != nil {
142155
http.Error(w, err.Error(), http.StatusBadRequest)
143156
return

pkg/sensehat/sensehat.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,31 @@ func (s *SenseHat) FlashLED(x, y int, r, g, b uint8, duration time.Duration) err
712712
return s.SetPixel(x, y, 0, 0, 0)
713713
}
714714

715+
// SetNavLights turns on the navigation lights (red port, green starboard) on the bottom row.
716+
func (s *SenseHat) SetNavLights() error {
717+
if err := s.SetPixel(0, 7, 255, 0, 0); err != nil { // Red - port (left)
718+
return err
719+
}
720+
return s.SetPixel(7, 7, 0, 255, 0) // Green - starboard (right)
721+
}
722+
723+
// FlashStrobes briefly flashes the strobe lights on the top corners.
724+
func (s *SenseHat) FlashStrobes(duration time.Duration) error {
725+
// Turn on strobes
726+
if err := s.SetPixel(0, 0, 255, 255, 255); err != nil {
727+
return err
728+
}
729+
if err := s.SetPixel(7, 0, 255, 255, 255); err != nil {
730+
return err
731+
}
732+
time.Sleep(duration)
733+
// Turn off strobes
734+
if err := s.SetPixel(0, 0, 0, 0, 0); err != nil {
735+
return err
736+
}
737+
return s.SetPixel(7, 0, 0, 0, 0)
738+
}
739+
715740
// PlaneAnimation animates a plane flying across the LED matrix with nav lights.
716741
func (s *SenseHat) PlaneAnimation(frameDelay time.Duration) error {
717742
// Plane shape (relative pixels from nose position)

0 commit comments

Comments
 (0)