mirror of
https://github.com/RustyRaptor/deckrotate.git
synced 2026-12-03 15:55:20 -07:00
The detector's settle time (0.1-3 s, default 0.5 s) and the manual-mode button lifetime (2-30 s, default 5 s) now live in the persisted settings instead of daemon flags. They are validated by the controller, exposed as SettleMs/PromptTimeoutMs D-Bus properties with setters, settable via `deckrotate settle` / `deckrotate prompt-timeout`, and shown as spin boxes in the tray applet. A new settle time applies immediately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Package daemon wires the IMU, orientation detector, controller, overlay
|
|
// and D-Bus service together.
|
|
package daemon
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/RustyRaptor/deckrotate/internal/imu"
|
|
"github.com/RustyRaptor/deckrotate/internal/orient"
|
|
)
|
|
|
|
type Sink interface {
|
|
DeviceTurned(context.Context, orient.Orientation) error
|
|
SetIMUAvailable(bool)
|
|
}
|
|
|
|
// Tracker turns raw IMU samples into settled orientation changes. It is not
|
|
// safe for concurrent use; feed it from the single IMU reader goroutine.
|
|
type Tracker struct {
|
|
sink Sink
|
|
settle func() time.Duration
|
|
det *orient.Detector
|
|
alive bool
|
|
}
|
|
|
|
// NewTracker asks settle for the current settle time on every sample, so
|
|
// changes made through the applet apply immediately.
|
|
func NewTracker(sink Sink, settle func() time.Duration) *Tracker {
|
|
return &Tracker{sink: sink, settle: settle, det: orient.NewDetector(settle())}
|
|
}
|
|
|
|
func (t *Tracker) Sample(at time.Time, s imu.Sample) {
|
|
if !t.alive {
|
|
t.alive = true
|
|
t.sink.SetIMUAvailable(true)
|
|
}
|
|
t.det.SetSettle(t.settle())
|
|
if o, changed := t.det.Update(at, s.Vec()); changed {
|
|
log.Printf("deck turned to %v", o)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
if err := t.sink.DeviceTurned(ctx, o); err != nil {
|
|
log.Printf("rotate to %v: %v", o, err)
|
|
}
|
|
cancel()
|
|
}
|
|
}
|
|
|
|
// Lost records that the IMU stopped delivering (device gone, read error).
|
|
func (t *Tracker) Lost() {
|
|
if t.alive {
|
|
t.alive = false
|
|
t.sink.SetIMUAvailable(false)
|
|
}
|
|
}
|