feat: keep OSD always visible with pre-map fullscreen states (#3)
This commit is contained in:
+25
-8
@@ -460,10 +460,27 @@ func writeStateFile(path string, data []byte) error {
|
||||
return os.Rename(tmpPath, path)
|
||||
}
|
||||
|
||||
// SnapshotState tells the display how to treat the latest snapshot.
|
||||
type SnapshotState int
|
||||
|
||||
const (
|
||||
// SnapshotNone means no snapshot has ever been decoded: the display
|
||||
// renders explicit unknown state instead of last-known values.
|
||||
SnapshotNone SnapshotState = iota
|
||||
// SnapshotFresh means the snapshot is within the freshness window and
|
||||
// its values are current.
|
||||
SnapshotFresh
|
||||
// SnapshotStale means the last successfully decoded snapshot is older
|
||||
// than the freshness window: the display keeps showing its values
|
||||
// marked as stale, never as current.
|
||||
SnapshotStale
|
||||
)
|
||||
|
||||
// FileSource reads the supervisor-published snapshot from its state file.
|
||||
// It is the display-side end of the snapshot contract: reads that fail or
|
||||
// return stale snapshots report no snapshot, so the OSD stays transparent
|
||||
// instead of rendering telemetry from a dead UART.
|
||||
// It is the display-side end of the snapshot contract: missing or corrupt
|
||||
// records report none, and a record beyond the freshness window is reported
|
||||
// as stale last-known data rather than hidden, so the display can mark it
|
||||
// visibly instead of freezing it as current.
|
||||
type FileSource struct {
|
||||
path string
|
||||
// now is the clock used for freshness checks; tests replace it.
|
||||
@@ -475,14 +492,14 @@ func NewFileSource(path string) *FileSource {
|
||||
return &FileSource{path: path, now: time.Now}
|
||||
}
|
||||
|
||||
// Latest reports the current snapshot while it is fresh.
|
||||
func (s *FileSource) Latest() (Snapshot, bool) {
|
||||
// Latest reports the current snapshot and its state.
|
||||
func (s *FileSource) Latest() (Snapshot, SnapshotState) {
|
||||
snapshot, err := DecodeFile(s.path)
|
||||
if err != nil {
|
||||
return Snapshot{}, false
|
||||
return Snapshot{}, SnapshotNone
|
||||
}
|
||||
if age := s.now().Sub(time.UnixMilli(snapshot.PublishedMS)); age > Freshness {
|
||||
return Snapshot{}, false
|
||||
return snapshot, SnapshotStale
|
||||
}
|
||||
return snapshot, true
|
||||
return snapshot, SnapshotFresh
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user