mirror of
https://github.com/RustyRaptor/deckrotate.git
synced 2026-12-03 15:55:20 -07:00
Make settle time and button timeout adjustable
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>
This commit is contained in:
1 parent
81d2a986b6
commit
edb73fe1b6
24 files changed
+475
-47
No files matched your search
@@ -11,13 +11,15 @@ instead (see [docs/hardware.md](docs/hardware.md)).
|
||||
## Features
|
||||
|
||||
- **Auto mode**: the screen follows the Deck as soon as it settles in a new
|
||||
position (0.5 s).
|
||||
position (0.5 s by default, adjustable from 0.1 to 3 s).
|
||||
- **Manual mode**: turning the Deck shows a round button in the bottom-right
|
||||
corner, as you're now holding it, for 5 seconds. Tap it to rotate.
|
||||
corner, as you're now holding it, for 5 seconds (adjustable from 2 to 30 s).
|
||||
Tap it to rotate.
|
||||
- **Lock**: stops both modes reacting to the sensor. Explicit rotations from the
|
||||
applet, CLI or shortcuts still work.
|
||||
- **Tray applet**: pick any of the four orientations, rotate left/right, lock,
|
||||
and switch modes. Middle-click the tray icon to toggle the lock.
|
||||
switch modes and adjust both timings. Middle-click the tray icon to toggle
|
||||
the lock.
|
||||
- **Global shortcuts** for lock, rotate left/right/flip, each orientation,
|
||||
mode toggle, and "accept" for the manual-mode button.
|
||||
- Lying the Deck flat, or shaking it, never triggers a rotation.
|
||||
@@ -60,6 +62,8 @@ deckrotate lock | unlock | toggle-lock
|
||||
deckrotate mode auto|manual|toggle
|
||||
deckrotate rotate cw|ccw|flip
|
||||
deckrotate rotate landscape|portrait-cw|landscape-flipped|portrait-ccw
|
||||
deckrotate settle 700ms # 100ms to 3s
|
||||
deckrotate prompt-timeout 8s # 2s to 30s
|
||||
deckrotate accept # take the manual-mode button's rotation
|
||||
deckrotate dismiss
|
||||
```
|
||||
@@ -109,9 +113,12 @@ Service and interface `io.github.RustyRaptor.DeckRotate`, object
|
||||
| `ScreenOrientation` | s | what the panel is rotated for |
|
||||
| `SuggestedOrientation` | s | manual-mode offer, empty when none |
|
||||
| `ImuAvailable` | b | |
|
||||
| `SettleMs` | i | settle time in milliseconds |
|
||||
| `PromptTimeoutMs` | i | manual-mode button lifetime in ms |
|
||||
|
||||
Methods: `SetMode(s)`, `ToggleMode()`, `SetLocked(b)`, `ToggleLock()`,
|
||||
`RotateTo(s)`, `RotateBy(i quarterTurnsClockwise)`, `Accept()`, `Dismiss()`.
|
||||
`RotateTo(s)`, `RotateBy(i quarterTurnsClockwise)`, `SetSettleMs(i)`,
|
||||
`SetPromptTimeoutMs(i)`, `Accept()`, `Dismiss()`.
|
||||
Properties emit `PropertiesChanged`.
|
||||
|
||||
## Development
|
||||
|
||||
@@ -25,6 +25,9 @@ func TestParseCommand(t *testing.T) {
|
||||
{"rotate portrait-cw", "RotateTo", []any{"portrait-cw"}},
|
||||
{"rotate portrait-ccw", "RotateTo", []any{"portrait-ccw"}},
|
||||
{"rotate landscape-flipped", "RotateTo", []any{"landscape-flipped"}},
|
||||
{"settle 700ms", "SetSettleMs", []any{int32(700)}},
|
||||
{"settle 1.5s", "SetSettleMs", []any{int32(1500)}},
|
||||
{"prompt-timeout 8s", "SetPromptTimeoutMs", []any{int32(8000)}},
|
||||
{"accept", "Accept", nil},
|
||||
{"dismiss", "Dismiss", nil},
|
||||
}
|
||||
@@ -37,7 +40,8 @@ func TestParseCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseCommandErrors(t *testing.T) {
|
||||
for _, args := range []string{"", "spin", "mode", "mode sometimes", "rotate", "rotate diagonal", "lock now"} {
|
||||
for _, args := range []string{"", "spin", "mode", "mode sometimes", "rotate", "rotate diagonal", "lock now",
|
||||
"settle", "settle fast", "settle 1s 2s", "prompt-timeout", "settle 10000h"} {
|
||||
if _, _, err := parseCommand(strings.Fields(args)); err == nil {
|
||||
t.Errorf("parseCommand(%q) should fail", args)
|
||||
}
|
||||
@@ -46,7 +50,8 @@ func TestParseCommandErrors(t *testing.T) {
|
||||
|
||||
func TestFormatStatus(t *testing.T) {
|
||||
got := formatStatus(statusFixture)
|
||||
want := "mode: manual\nlocked: yes\ndevice: portrait-cw\nscreen: landscape\nsuggested: portrait-cw\nimu: ok\n"
|
||||
want := "mode: manual\nlocked: yes\ndevice: portrait-cw\nscreen: landscape\nsuggested: portrait-cw\nimu: ok\n" +
|
||||
"settle: 700ms\nbutton: 8s\n"
|
||||
if got != want {
|
||||
t.Errorf("formatStatus =\n%s\nwant\n%s", got, want)
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ import "github.com/RustyRaptor/deckrotate/internal/service"
|
||||
var statusFixture = service.Status{
|
||||
Mode: "manual", Locked: true, Device: "portrait-cw",
|
||||
Screen: "landscape", Suggested: "portrait-cw", IMU: true,
|
||||
SettleMs: 700, PromptTimeoutMs: 8000,
|
||||
}
|
||||
+20
-2
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -30,6 +31,8 @@ const usage = `usage: deckrotate <command>
|
||||
mode auto|manual|toggle
|
||||
rotate cw|ccw|flip turn the screen from where it is now
|
||||
rotate landscape|portrait-cw|landscape-flipped|portrait-ccw
|
||||
settle <duration> how long the Deck must hold still before it counts (100ms-3s)
|
||||
prompt-timeout <dur> how long the manual-mode button stays up (2s-30s)
|
||||
accept take the rotation the manual-mode button offers
|
||||
dismiss hide the manual-mode button
|
||||
`
|
||||
@@ -102,6 +105,21 @@ func parseCommand(args []string) (string, []any, error) {
|
||||
return "", nil, err
|
||||
}
|
||||
return "SetMode", []any{m}, nil
|
||||
case "settle", "prompt-timeout":
|
||||
v, err := arg()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
d, err := time.ParseDuration(v)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
ms := d.Milliseconds()
|
||||
if ms <= 0 || ms > math.MaxInt32 {
|
||||
return "", nil, fmt.Errorf("%s: %v is out of range", args[0], d)
|
||||
}
|
||||
method := map[string]string{"settle": "SetSettleMs", "prompt-timeout": "SetPromptTimeoutMs"}[args[0]]
|
||||
return method, []any{int32(ms)}, nil
|
||||
case "rotate":
|
||||
r, err := arg()
|
||||
if err != nil {
|
||||
@@ -136,6 +154,8 @@ func formatStatus(s service.Status) string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "mode: %s\nlocked: %s\ndevice: %s\nscreen: %s\nsuggested: %s\nimu: %s\n",
|
||||
s.Mode, yn[s.Locked], s.Device, s.Screen, sug, imu[s.IMU])
|
||||
ms := func(v int32) time.Duration { return time.Duration(v) * time.Millisecond }
|
||||
fmt.Fprintf(&b, "settle: %v\nbutton: %v\n", ms(s.SettleMs), ms(s.PromptTimeoutMs))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
@@ -175,8 +195,6 @@ func runDaemon(args []string) error {
|
||||
o := daemon.Options{SysRoot: "/sys"}
|
||||
fs.StringVar(&o.UIDir, "ui-dir", defaultUIDir(), "directory containing overlay.qml")
|
||||
fs.StringVar(&o.QMLBin, "qml", "/usr/lib/qt6/bin/qml", "QML runtime used for the overlay")
|
||||
fs.DurationVar(&o.Settle, "settle", 500*time.Millisecond, "how long an orientation must hold before it counts")
|
||||
fs.DurationVar(&o.PromptTimeout, "prompt-timeout", 5*time.Second, "how long the manual-mode button stays up")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -54,3 +54,15 @@ func TestDefaultPathUsesXDG(t *testing.T) {
|
||||
t.Errorf("DefaultPath = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimingsRoundTrip(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "settings.json")
|
||||
want := core.Settings{Mode: core.Auto, SettleMS: 750, PromptTimeoutMS: 9000}
|
||||
if err := NewFileStore(path).Save(want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := NewFileStore(path).Load()
|
||||
if err != nil || got != want {
|
||||
t.Errorf("Load = %+v, %v; want %+v", got, err, want)
|
||||
}
|
||||
}
|
||||
+62
-11
@@ -42,10 +42,31 @@ func (m *Mode) UnmarshalText(b []byte) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Settings are the user choices that survive restarts.
|
||||
const (
|
||||
DefaultSettle = 500 * time.Millisecond
|
||||
MinSettle = 100 * time.Millisecond
|
||||
MaxSettle = 3 * time.Second
|
||||
DefaultPromptTimeout = 5 * time.Second
|
||||
MinPromptTimeout = 2 * time.Second
|
||||
MaxPromptTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
var ErrOutOfRange = errors.New("value out of range")
|
||||
|
||||
// Settings are the user choices that survive restarts. Zero timings mean
|
||||
// "use the default".
|
||||
type Settings struct {
|
||||
Mode Mode `json:"mode"`
|
||||
Locked bool `json:"locked"`
|
||||
Mode Mode `json:"mode"`
|
||||
Locked bool `json:"locked"`
|
||||
SettleMS int `json:"settle_ms,omitempty"`
|
||||
PromptTimeoutMS int `json:"prompt_timeout_ms,omitempty"`
|
||||
}
|
||||
|
||||
func timing(ms int, def, lo, hi time.Duration) time.Duration {
|
||||
if ms == 0 {
|
||||
return def
|
||||
}
|
||||
return min(max(time.Duration(ms)*time.Millisecond, lo), hi)
|
||||
}
|
||||
|
||||
type State struct {
|
||||
@@ -55,6 +76,9 @@ type State struct {
|
||||
Screen orient.Orientation // what the panel is rotated for
|
||||
Suggested orient.Orientation // manual-mode prompt target, Unknown when none
|
||||
IMU bool // accelerometer is delivering data
|
||||
|
||||
Settle time.Duration // how long a new orientation must hold
|
||||
PromptTimeout time.Duration // how long the manual-mode button stays up
|
||||
}
|
||||
|
||||
type Screen interface {
|
||||
@@ -77,12 +101,11 @@ type Store interface {
|
||||
type Timer interface{ Stop() bool }
|
||||
|
||||
type Deps struct {
|
||||
Screen Screen
|
||||
Prompt Prompt
|
||||
Store Store
|
||||
AfterFunc func(time.Duration, func()) Timer
|
||||
PromptTimeout time.Duration
|
||||
OnChange func(State)
|
||||
Screen Screen
|
||||
Prompt Prompt
|
||||
Store Store
|
||||
AfterFunc func(time.Duration, func()) Timer
|
||||
OnChange func(State)
|
||||
}
|
||||
|
||||
var ErrNothingToAccept = errors.New("no rotation is being offered")
|
||||
@@ -112,6 +135,8 @@ func (c *Controller) Init(ctx context.Context) error {
|
||||
}
|
||||
return c.update(func() error {
|
||||
c.st.Mode, c.st.Locked = s.Mode, s.Locked
|
||||
c.st.Settle = timing(s.SettleMS, DefaultSettle, MinSettle, MaxSettle)
|
||||
c.st.PromptTimeout = timing(s.PromptTimeoutMS, DefaultPromptTimeout, MinPromptTimeout, MaxPromptTimeout)
|
||||
return c.refreshScreen(ctx)
|
||||
})
|
||||
}
|
||||
@@ -150,7 +175,12 @@ func (c *Controller) apply(ctx context.Context, o orient.Orientation) error {
|
||||
}
|
||||
|
||||
func (c *Controller) save() error {
|
||||
return c.d.Store.Save(Settings{Mode: c.st.Mode, Locked: c.st.Locked})
|
||||
return c.d.Store.Save(Settings{
|
||||
Mode: c.st.Mode,
|
||||
Locked: c.st.Locked,
|
||||
SettleMS: int(c.st.Settle / time.Millisecond),
|
||||
PromptTimeoutMS: int(c.st.PromptTimeout / time.Millisecond),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) withdraw() {
|
||||
@@ -177,7 +207,7 @@ func (c *Controller) offer(o orient.Orientation) {
|
||||
gen := c.gen
|
||||
c.st.Suggested = o
|
||||
c.d.Prompt.Show(o, c.st.Screen)
|
||||
c.timer = c.d.AfterFunc(c.d.PromptTimeout, func() {
|
||||
c.timer = c.d.AfterFunc(c.st.PromptTimeout, func() {
|
||||
c.update(func() error {
|
||||
if c.gen == gen {
|
||||
c.withdraw()
|
||||
@@ -249,6 +279,27 @@ func (c *Controller) ToggleLock(ctx context.Context) error {
|
||||
return c.SetLocked(ctx, !c.State().Locked)
|
||||
}
|
||||
|
||||
func (c *Controller) SetSettle(d time.Duration) error {
|
||||
if d < MinSettle || d > MaxSettle {
|
||||
return fmt.Errorf("settle time %v: %w (%v to %v)", d, ErrOutOfRange, MinSettle, MaxSettle)
|
||||
}
|
||||
return c.update(func() error {
|
||||
c.st.Settle = d
|
||||
return c.save()
|
||||
})
|
||||
}
|
||||
|
||||
// SetPromptTimeout applies from the next manual-mode prompt.
|
||||
func (c *Controller) SetPromptTimeout(d time.Duration) error {
|
||||
if d < MinPromptTimeout || d > MaxPromptTimeout {
|
||||
return fmt.Errorf("button timeout %v: %w (%v to %v)", d, ErrOutOfRange, MinPromptTimeout, MaxPromptTimeout)
|
||||
}
|
||||
return c.update(func() error {
|
||||
c.st.PromptTimeout = d
|
||||
return c.save()
|
||||
})
|
||||
}
|
||||
|
||||
// RotateTo is an explicit user request; it works regardless of mode and lock.
|
||||
func (c *Controller) RotateTo(ctx context.Context, o orient.Orientation) error {
|
||||
return c.update(func() error {
|
||||
|
||||
@@ -95,12 +95,11 @@ func newRig(t *testing.T, s Settings) *rig {
|
||||
clock: &fakeClock{},
|
||||
}
|
||||
r.c = New(Deps{
|
||||
Screen: r.screen,
|
||||
Prompt: r.prompt,
|
||||
Store: r.store,
|
||||
AfterFunc: r.clock.AfterFunc,
|
||||
PromptTimeout: 5 * time.Second,
|
||||
OnChange: func(s State) { r.states = append(r.states, s) },
|
||||
Screen: r.screen,
|
||||
Prompt: r.prompt,
|
||||
Store: r.store,
|
||||
AfterFunc: r.clock.AfterFunc,
|
||||
OnChange: func(s State) { r.states = append(r.states, s) },
|
||||
})
|
||||
if err := r.c.Init(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -113,7 +112,8 @@ var ctx = context.Background()
|
||||
func TestInitLoadsSettingsAndScreen(t *testing.T) {
|
||||
r := newRig(t, Settings{Mode: Manual, Locked: true})
|
||||
got := r.c.State()
|
||||
want := State{Mode: Manual, Locked: true, Device: orient.Unknown, Screen: orient.Landscape, Suggested: orient.Unknown}
|
||||
want := State{Mode: Manual, Locked: true, Device: orient.Unknown, Screen: orient.Landscape, Suggested: orient.Unknown,
|
||||
Settle: DefaultSettle, PromptTimeout: DefaultPromptTimeout}
|
||||
if got != want {
|
||||
t.Errorf("State = %+v, want %+v", got, want)
|
||||
}
|
||||
@@ -341,3 +341,73 @@ func TestModeStrings(t *testing.T) {
|
||||
t.Error("ParseMode(sometimes) should fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimingDefaults(t *testing.T) {
|
||||
if DefaultSettle != 500*time.Millisecond || DefaultPromptTimeout != 5*time.Second {
|
||||
t.Errorf("defaults = %v, %v", DefaultSettle, DefaultPromptTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitUsesSavedTimings(t *testing.T) {
|
||||
r := newRig(t, Settings{SettleMS: 800, PromptTimeoutMS: 12000})
|
||||
st := r.c.State()
|
||||
if st.Settle != 800*time.Millisecond || st.PromptTimeout != 12*time.Second {
|
||||
t.Errorf("state timings = %v, %v", st.Settle, st.PromptTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitClampsSavedTimings(t *testing.T) {
|
||||
r := newRig(t, Settings{SettleMS: 5, PromptTimeoutMS: 999999})
|
||||
st := r.c.State()
|
||||
if st.Settle != MinSettle || st.PromptTimeout != MaxPromptTimeout {
|
||||
t.Errorf("state timings = %v, %v; want clamped to %v, %v", st.Settle, st.PromptTimeout, MinSettle, MaxPromptTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetSettle(t *testing.T) {
|
||||
r := newRig(t, Settings{Mode: Manual, Locked: true})
|
||||
if err := r.c.SetSettle(1200 * time.Millisecond); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.c.State().Settle != 1200*time.Millisecond {
|
||||
t.Errorf("Settle = %v", r.c.State().Settle)
|
||||
}
|
||||
want := Settings{Mode: Manual, Locked: true, SettleMS: 1200, PromptTimeoutMS: 5000}
|
||||
if r.store.s != want {
|
||||
t.Errorf("saved %+v, want %+v", r.store.s, want)
|
||||
}
|
||||
for _, bad := range []time.Duration{MinSettle - time.Millisecond, MaxSettle + time.Millisecond} {
|
||||
if err := r.c.SetSettle(bad); !errors.Is(err, ErrOutOfRange) {
|
||||
t.Errorf("SetSettle(%v) err = %v, want ErrOutOfRange", bad, err)
|
||||
}
|
||||
}
|
||||
if r.c.State().Settle != 1200*time.Millisecond {
|
||||
t.Errorf("rejected value changed Settle to %v", r.c.State().Settle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetPromptTimeoutAppliesToNextPrompt(t *testing.T) {
|
||||
r := newRig(t, Settings{Mode: Manual})
|
||||
if err := r.c.SetPromptTimeout(8 * time.Second); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.c.DeviceTurned(ctx, orient.PortraitCW)
|
||||
if got := r.clock.timers[len(r.clock.timers)-1].d; got != 8*time.Second {
|
||||
t.Errorf("prompt timer = %v, want 8s", got)
|
||||
}
|
||||
if r.store.s.PromptTimeoutMS != 8000 {
|
||||
t.Errorf("saved %+v", r.store.s)
|
||||
}
|
||||
if err := r.c.SetPromptTimeout(time.Second); !errors.Is(err, ErrOutOfRange) {
|
||||
t.Errorf("SetPromptTimeout(1s) err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModeAndLockKeepTimings(t *testing.T) {
|
||||
r := newRig(t, Settings{SettleMS: 900, PromptTimeoutMS: 7000})
|
||||
r.c.SetLocked(ctx, true)
|
||||
r.c.SetMode(ctx, Manual)
|
||||
if r.store.s.SettleMS != 900 || r.store.s.PromptTimeoutMS != 7000 {
|
||||
t.Errorf("saving mode/lock lost timings: %+v", r.store.s)
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,9 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
UIDir string // holds overlay.qml
|
||||
QMLBin string
|
||||
Settle time.Duration
|
||||
PromptTimeout time.Duration
|
||||
SysRoot string
|
||||
UIDir string // holds overlay.qml
|
||||
QMLBin string
|
||||
SysRoot string
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, o Options) error {
|
||||
@@ -36,6 +34,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
defer conn.Close()
|
||||
|
||||
var svc atomic.Pointer[service.Service]
|
||||
var settle atomic.Int64
|
||||
var ctrl *core.Controller
|
||||
prompt := overlay.NewProcessPrompt(
|
||||
func(ctx context.Context, p overlay.Placement) *exec.Cmd {
|
||||
@@ -53,11 +52,11 @@ func Run(ctx context.Context, o Options) error {
|
||||
},
|
||||
)
|
||||
ctrl = core.New(core.Deps{
|
||||
Screen: display.NewKScreen(display.ExecRunner),
|
||||
Prompt: prompt,
|
||||
Store: config.NewFileStore(config.DefaultPath()),
|
||||
PromptTimeout: o.PromptTimeout,
|
||||
Screen: display.NewKScreen(display.ExecRunner),
|
||||
Prompt: prompt,
|
||||
Store: config.NewFileStore(config.DefaultPath()),
|
||||
OnChange: func(st core.State) {
|
||||
settle.Store(int64(st.Settle))
|
||||
if s := svc.Load(); s != nil {
|
||||
s.Publish(st)
|
||||
}
|
||||
@@ -75,7 +74,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
st := ctrl.State()
|
||||
log.Printf("deckrotate running: mode=%v locked=%v screen=%v", st.Mode, st.Locked, st.Screen)
|
||||
|
||||
go readIMU(ctx, o.SysRoot, NewTracker(ctrl, o.Settle))
|
||||
go readIMU(ctx, o.SysRoot, NewTracker(ctrl, func() time.Duration { return time.Duration(settle.Load()) }))
|
||||
<-ctx.Done()
|
||||
prompt.Hide()
|
||||
return nil
|
||||
|
||||
@@ -19,13 +19,16 @@ type Sink interface {
|
||||
// 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
|
||||
det *orient.Detector
|
||||
alive bool
|
||||
sink Sink
|
||||
settle func() time.Duration
|
||||
det *orient.Detector
|
||||
alive bool
|
||||
}
|
||||
|
||||
func NewTracker(sink Sink, settle time.Duration) *Tracker {
|
||||
return &Tracker{sink: sink, det: orient.NewDetector(settle)}
|
||||
// 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) {
|
||||
@@ -33,6 +36,7 @@ func (t *Tracker) Sample(at time.Time, s imu.Sample) {
|
||||
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)
|
||||
|
||||
@@ -28,7 +28,7 @@ var (
|
||||
|
||||
func TestTrackerFeedsSettledTurns(t *testing.T) {
|
||||
sink := &fakeSink{}
|
||||
tr := NewTracker(sink, 300*time.Millisecond)
|
||||
tr := NewTracker(sink, fixed(300*time.Millisecond))
|
||||
t0 := time.Unix(0, 0)
|
||||
feed := func(s imu.Sample, from, to time.Duration) {
|
||||
for d := from; d <= to; d += 4 * time.Millisecond {
|
||||
@@ -50,7 +50,7 @@ func TestTrackerFeedsSettledTurns(t *testing.T) {
|
||||
|
||||
func TestTrackerReportsLostIMU(t *testing.T) {
|
||||
sink := &fakeSink{}
|
||||
tr := NewTracker(sink, 300*time.Millisecond)
|
||||
tr := NewTracker(sink, fixed(300*time.Millisecond))
|
||||
tr.Sample(time.Unix(0, 0), landscape)
|
||||
tr.Lost()
|
||||
tr.Lost()
|
||||
@@ -60,3 +60,23 @@ func TestTrackerReportsLostIMU(t *testing.T) {
|
||||
t.Errorf("imu = %v, want %v", sink.imu, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackerFollowsSettleChanges(t *testing.T) {
|
||||
sink := &fakeSink{}
|
||||
settle := 2 * time.Second
|
||||
tr := NewTracker(sink, func() time.Duration { return settle })
|
||||
t0 := time.Unix(0, 0)
|
||||
for d := time.Duration(0); d <= 500*time.Millisecond; d += 4 * time.Millisecond {
|
||||
tr.Sample(t0.Add(d), landscape)
|
||||
}
|
||||
if len(sink.turns) != 0 {
|
||||
t.Fatalf("reported before the 2 s settle: %v", sink.turns)
|
||||
}
|
||||
settle = 100 * time.Millisecond
|
||||
tr.Sample(t0.Add(600*time.Millisecond), landscape)
|
||||
if len(sink.turns) != 1 || sink.turns[0] != orient.Landscape {
|
||||
t.Errorf("turns = %v after shortening settle", sink.turns)
|
||||
}
|
||||
}
|
||||
|
||||
func fixed(d time.Duration) func() time.Duration { return func() time.Duration { return d } }
|
||||
@@ -102,6 +102,9 @@ func NewDetector(settle time.Duration) *Detector {
|
||||
return &Detector{settle: settle, current: Unknown, candidate: Unknown}
|
||||
}
|
||||
|
||||
func (d *Detector) SetSettle(settle time.Duration) { d.settle = settle }
|
||||
func (d *Detector) Settle() time.Duration { return d.settle }
|
||||
|
||||
// Current is the last reported orientation, or Unknown before the first.
|
||||
func (d *Detector) Current() Orientation { return d.current }
|
||||
|
||||
|
||||
@@ -186,3 +186,20 @@ func TestDetectorFlatKeepsOrientationAndResetsCandidate(t *testing.T) {
|
||||
t.Fatalf("got %v,%v; want portrait-cw,true", o, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectorSettleCanChange(t *testing.T) {
|
||||
d := NewDetector(400 * time.Millisecond)
|
||||
t0 := time.Unix(1000, 0)
|
||||
d.Update(t0, vec(0))
|
||||
d.Update(t0.Add(400*time.Millisecond), vec(0))
|
||||
|
||||
d.SetSettle(100 * time.Millisecond)
|
||||
at := t0.Add(time.Second)
|
||||
d.Update(at, vec(90))
|
||||
if o, ok := d.Update(at.Add(100*time.Millisecond), vec(90)); !ok || o != PortraitCW {
|
||||
t.Fatalf("shorter settle not honoured: %v,%v", o, ok)
|
||||
}
|
||||
if d.Settle() != 100*time.Millisecond {
|
||||
t.Errorf("Settle() = %v", d.Settle())
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ func (c *Client) Status() (Status, error) {
|
||||
"Mode": &s.Mode, "Locked": &s.Locked,
|
||||
"DeviceOrientation": &s.Device, "ScreenOrientation": &s.Screen,
|
||||
"SuggestedOrientation": &s.Suggested, "ImuAvailable": &s.IMU,
|
||||
"SettleMs": &s.SettleMs, "PromptTimeoutMs": &s.PromptTimeoutMs,
|
||||
} {
|
||||
v, ok := all[name]
|
||||
if !ok {
|
||||
|
||||
@@ -4,6 +4,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -33,6 +34,8 @@ type Controller interface {
|
||||
ToggleLock(context.Context) error
|
||||
RotateTo(context.Context, orient.Orientation) error
|
||||
RotateBy(context.Context, int) error
|
||||
SetSettle(time.Duration) error
|
||||
SetPromptTimeout(time.Duration) error
|
||||
Accept(context.Context) error
|
||||
Dismiss()
|
||||
}
|
||||
@@ -45,6 +48,9 @@ type Status struct {
|
||||
Screen string
|
||||
Suggested string // empty when nothing is being offered
|
||||
IMU bool
|
||||
|
||||
SettleMs int32
|
||||
PromptTimeoutMs int32
|
||||
}
|
||||
|
||||
func statusOf(s core.State) Status {
|
||||
@@ -56,6 +62,8 @@ func statusOf(s core.State) Status {
|
||||
Mode: s.Mode.String(), Locked: s.Locked,
|
||||
Device: s.Device.String(), Screen: s.Screen.String(),
|
||||
Suggested: sug, IMU: s.IMU,
|
||||
SettleMs: int32(s.Settle / time.Millisecond),
|
||||
PromptTimeoutMs: int32(s.PromptTimeout / time.Millisecond),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +75,8 @@ func (s Status) props() map[string]any {
|
||||
"ScreenOrientation": s.Screen,
|
||||
"SuggestedOrientation": s.Suggested,
|
||||
"ImuAvailable": s.IMU,
|
||||
"SettleMs": s.SettleMs,
|
||||
"PromptTimeoutMs": s.PromptTimeoutMs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +144,29 @@ func (o object) RotateBy(turns int32) *dbus.Error {
|
||||
return fail(o.c.RotateBy(c, int(turns)))
|
||||
}
|
||||
|
||||
func positiveMs(ms int32) (time.Duration, error) {
|
||||
if ms <= 0 {
|
||||
return 0, fmt.Errorf("%d ms: must be positive", ms)
|
||||
}
|
||||
return time.Duration(ms) * time.Millisecond, nil
|
||||
}
|
||||
|
||||
func (o object) SetSettleMs(ms int32) *dbus.Error {
|
||||
d, err := positiveMs(ms)
|
||||
if err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
return fail(o.c.SetSettle(d))
|
||||
}
|
||||
|
||||
func (o object) SetPromptTimeoutMs(ms int32) *dbus.Error {
|
||||
d, err := positiveMs(ms)
|
||||
if err != nil {
|
||||
return fail(err)
|
||||
}
|
||||
return fail(o.c.SetPromptTimeout(d))
|
||||
}
|
||||
|
||||
func (o object) Accept() *dbus.Error {
|
||||
c, cancel := ctx()
|
||||
defer cancel()
|
||||
@@ -152,6 +185,8 @@ var methods = []introspect.Method{
|
||||
{Name: "ToggleLock"},
|
||||
{Name: "RotateTo", Args: []introspect.Arg{{Name: "orientation", Type: "s", Direction: "in"}}},
|
||||
{Name: "RotateBy", Args: []introspect.Arg{{Name: "quarterTurnsClockwise", Type: "i", Direction: "in"}}},
|
||||
{Name: "SetSettleMs", Args: []introspect.Arg{{Name: "ms", Type: "i", Direction: "in"}}},
|
||||
{Name: "SetPromptTimeoutMs", Args: []introspect.Arg{{Name: "ms", Type: "i", Direction: "in"}}},
|
||||
{Name: "Accept"},
|
||||
{Name: "Dismiss"},
|
||||
}
|
||||
|
||||
@@ -91,6 +91,10 @@ func (f *fakeController) RotateTo(_ context.Context, o orient.Orientation) error
|
||||
func (f *fakeController) RotateBy(_ context.Context, n int) error {
|
||||
return f.rec("by " + map[int]string{1: "1", -1: "-1"}[n])
|
||||
}
|
||||
func (f *fakeController) SetSettle(d time.Duration) error { return f.rec("settle " + d.String()) }
|
||||
func (f *fakeController) SetPromptTimeout(d time.Duration) error {
|
||||
return f.rec("prompt " + d.String())
|
||||
}
|
||||
func (f *fakeController) Accept(context.Context) error { return f.rec("accept") }
|
||||
func (f *fakeController) Dismiss() { f.rec("dismiss") }
|
||||
|
||||
@@ -100,6 +104,7 @@ func setup(t *testing.T) (*fakeController, *Service, *Client) {
|
||||
fc := &fakeController{st: core.State{
|
||||
Mode: core.Manual, Locked: true, Device: orient.PortraitCW,
|
||||
Screen: orient.Landscape, Suggested: orient.Unknown, IMU: true,
|
||||
Settle: 700 * time.Millisecond, PromptTimeout: 8 * time.Second,
|
||||
}}
|
||||
svc, err := Export(connect(t, addr), fc)
|
||||
if err != nil {
|
||||
@@ -122,6 +127,8 @@ func TestMethodsReachController(t *testing.T) {
|
||||
{"RotateTo", []any{"portrait-ccw"}},
|
||||
{"RotateBy", []any{int32(1)}},
|
||||
{"RotateBy", []any{int32(-1)}},
|
||||
{"SetSettleMs", []any{int32(1200)}},
|
||||
{"SetPromptTimeoutMs", []any{int32(9000)}},
|
||||
{"Accept", nil},
|
||||
{"Dismiss", nil},
|
||||
}
|
||||
@@ -131,7 +138,7 @@ func TestMethodsReachController(t *testing.T) {
|
||||
}
|
||||
}
|
||||
want := []string{"mode auto", "toggle-mode", "lock", "unlock", "toggle-lock",
|
||||
"to portrait-ccw", "by 1", "by -1", "accept", "dismiss"}
|
||||
"to portrait-ccw", "by 1", "by -1", "settle 1.2s", "prompt 9s", "accept", "dismiss"}
|
||||
if got := fc.recorded(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("calls = %v\nwant %v", got, want)
|
||||
}
|
||||
@@ -145,6 +152,9 @@ func TestBadArgumentsAreDBusErrors(t *testing.T) {
|
||||
if err := cl.Call("RotateTo", "diagonal"); err == nil {
|
||||
t.Error("RotateTo(diagonal) should fail")
|
||||
}
|
||||
if err := cl.Call("SetSettleMs", int32(-5)); err == nil {
|
||||
t.Error("SetSettleMs(-5) should fail")
|
||||
}
|
||||
if got := fc.recorded(); len(got) != 0 {
|
||||
t.Errorf("controller called with bad args: %v", got)
|
||||
}
|
||||
@@ -161,7 +171,8 @@ func TestInitialPropertiesAndStatus(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := Status{Mode: "manual", Locked: true, Device: "portrait-cw", Screen: "landscape", Suggested: "", IMU: true}
|
||||
want := Status{Mode: "manual", Locked: true, Device: "portrait-cw", Screen: "landscape", Suggested: "", IMU: true,
|
||||
SettleMs: 700, PromptTimeoutMs: 8000}
|
||||
if got != want {
|
||||
t.Errorf("Status = %+v, want %+v", got, want)
|
||||
}
|
||||
@@ -219,7 +230,7 @@ func TestIntrospectionListsMethods(t *testing.T) {
|
||||
if err := cl.conn.Object(BusName, ObjectPath).Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xml); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, m := range []string{"ToggleLock", "RotateBy", "Accept", "ScreenOrientation"} {
|
||||
for _, m := range []string{"ToggleLock", "RotateBy", "Accept", "ScreenOrientation", "SetSettleMs", "PromptTimeoutMs"} {
|
||||
if !strings.Contains(xml, `"`+m+`"`) {
|
||||
t.Errorf("introspection is missing %s", m)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (noPrompt) Hide() {}
|
||||
type memStore struct{ s core.Settings }
|
||||
|
||||
func (m *memStore) Load() (core.Settings, error) { return m.s, nil }
|
||||
func (m *memStore) Save(s core.Settings) error { m.s = s; return nil }
|
||||
func (m *memStore) Save(s core.Settings) error { m.s = s; return nil }
|
||||
|
||||
func main() {
|
||||
conn, err := dbus.ConnectSessionBus()
|
||||
|
||||
@@ -51,6 +51,15 @@ Item {
|
||||
tryCompare(backend, "mode", "auto")
|
||||
}
|
||||
|
||||
function test_4b_timings() {
|
||||
tryCompare(backend, "settleMs", 500)
|
||||
compare(backend.promptTimeoutMs, 5000)
|
||||
backend.setSettleMs(800)
|
||||
tryCompare(backend, "settleMs", 800)
|
||||
backend.setPromptTimeoutMs(9000)
|
||||
tryCompare(backend, "promptTimeoutMs", 9000)
|
||||
}
|
||||
|
||||
function test_5_types_are_plain() {
|
||||
compare(typeof backend.mode, "string")
|
||||
compare(typeof backend.locked, "boolean")
|
||||
|
||||
@@ -15,6 +15,8 @@ QtObject {
|
||||
readonly property string device: text(props.properties.DeviceOrientation, "unknown")
|
||||
readonly property string screen: text(props.properties.ScreenOrientation, "unknown")
|
||||
readonly property string suggested: text(props.properties.SuggestedOrientation, "")
|
||||
readonly property int settleMs: number(props.properties.SettleMs, 500)
|
||||
readonly property int promptTimeoutMs: number(props.properties.PromptTimeoutMs, 5000)
|
||||
|
||||
property DBus.DBusServiceWatcher watcher: DBus.DBusServiceWatcher {
|
||||
busType: DBus.BusType.Session
|
||||
@@ -35,6 +37,10 @@ QtObject {
|
||||
return available && v !== undefined && v !== null ? String(v) : fallback
|
||||
}
|
||||
|
||||
function number(v, fallback) {
|
||||
return available && v !== undefined && v !== null ? Number(v) : fallback
|
||||
}
|
||||
|
||||
// No signature: the module rejects explicit ones but infers types correctly.
|
||||
function call(member, args) {
|
||||
const reply = DBus.SessionBus.asyncCall({
|
||||
@@ -54,5 +60,7 @@ QtObject {
|
||||
function setLocked(l) { call("SetLocked", [l]) }
|
||||
function rotateTo(o) { call("RotateTo", [o]) }
|
||||
function rotateBy(n) { call("RotateBy", [new DBus.int32(n)]) }
|
||||
function setSettleMs(ms) { call("SetSettleMs", [new DBus.int32(ms)]) }
|
||||
function setPromptTimeoutMs(ms) { call("SetPromptTimeoutMs", [new DBus.int32(ms)]) }
|
||||
function accept() { call("Accept", []) }
|
||||
}
|
||||
@@ -165,6 +165,40 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: Kirigami.Units.smallSpacing
|
||||
columns: 2
|
||||
|
||||
PlasmaComponents3.Label {
|
||||
Layout.fillWidth: true
|
||||
text: tr("Rotate after holding still for")
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
SecondsSpinBox {
|
||||
objectName: "settleSpin"
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 6
|
||||
enabled: view.backend.imu
|
||||
range: Logic.settleRange
|
||||
backendValue: view.backend.settleMs
|
||||
onChosen: (ms) => view.backend.setSettleMs(ms)
|
||||
}
|
||||
|
||||
PlasmaComponents3.Label {
|
||||
Layout.fillWidth: true
|
||||
text: tr("Keep the rotate button for")
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
SecondsSpinBox {
|
||||
objectName: "promptSpin"
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 6
|
||||
enabled: view.backend.imu && view.backend.mode === "manual"
|
||||
range: Logic.promptRange
|
||||
backendValue: view.backend.promptTimeoutMs
|
||||
onChosen: (ms) => view.backend.setPromptTimeoutMs(ms)
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaComponents3.Label {
|
||||
objectName: "deviceLabel"
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import QtQuick
|
||||
import org.kde.plasma.components as PlasmaComponents3
|
||||
import "logic.js" as Logic
|
||||
|
||||
// Milliseconds shown as seconds. Follows backendValue; edits are reported
|
||||
// through chosen() and the box snaps back until the daemon confirms.
|
||||
PlasmaComponents3.SpinBox {
|
||||
id: spin
|
||||
|
||||
property int backendValue
|
||||
property var range
|
||||
signal chosen(int ms)
|
||||
|
||||
from: range.from
|
||||
to: range.to
|
||||
stepSize: range.step
|
||||
editable: true
|
||||
value: backendValue
|
||||
|
||||
textFromValue: (v, locale) => Logic.seconds(v)
|
||||
valueFromText: (text, locale) => {
|
||||
const ms = Logic.parseSeconds(text)
|
||||
return isNaN(ms) ? spin.value : ms
|
||||
}
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: /[0-9]+([.,][0-9]+)?\s*s?/
|
||||
}
|
||||
|
||||
onValueModified: {
|
||||
const ms = value
|
||||
value = Qt.binding(() => spin.backendValue)
|
||||
spin.chosen(ms)
|
||||
}
|
||||
}
|
||||
@@ -38,3 +38,17 @@ function summary(b) {
|
||||
state = b.mode === "manual" ? "Manual" : "Auto-rotate"
|
||||
return state + " · " + label(b.screen)
|
||||
}
|
||||
|
||||
// Mirrors the daemon's limits (internal/core); the daemon has the final say.
|
||||
const settleRange = { from: 100, to: 3000, step: 100 }
|
||||
const promptRange = { from: 2000, to: 30000, step: 1000 }
|
||||
|
||||
function seconds(ms) {
|
||||
const s = ms / 1000
|
||||
return (Number.isInteger(s) ? String(s) : s.toFixed(1)) + " s"
|
||||
}
|
||||
|
||||
function parseSeconds(text) {
|
||||
const m = String(text).trim().replace(",", ".").match(/^([0-9]+(?:\.[0-9]+)?)\s*s?$/)
|
||||
return m ? Math.round(parseFloat(m[1]) * 1000) : NaN
|
||||
}
|
||||
@@ -9,6 +9,8 @@ QtObject {
|
||||
property string device: "landscape"
|
||||
property string screen: "landscape"
|
||||
property string suggested: ""
|
||||
property int settleMs: 500
|
||||
property int promptTimeoutMs: 5000
|
||||
|
||||
property var calls: []
|
||||
|
||||
@@ -20,5 +22,7 @@ QtObject {
|
||||
function setLocked(l) { record("setLocked " + l) }
|
||||
function rotateTo(o) { record("rotateTo " + o) }
|
||||
function rotateBy(n) { record("rotateBy " + n) }
|
||||
function setSettleMs(ms) { record("setSettleMs " + ms) }
|
||||
function setPromptTimeoutMs(ms) { record("setPromptTimeoutMs " + ms) }
|
||||
function accept() { record("accept") }
|
||||
}
|
||||
@@ -115,5 +115,50 @@ Item {
|
||||
const t = make({ device: "portrait-cw" })
|
||||
verify(child(t.view, "deviceLabel").text.indexOf("Portrait (right grip down)") >= 0)
|
||||
}
|
||||
|
||||
function test_settle_spin_shows_backend_value() {
|
||||
const t = make({ settleMs: 1500 })
|
||||
const spin = child(t.view, "settleSpin")
|
||||
compare(spin.value, 1500)
|
||||
compare(spin.displayText, "1.5 s")
|
||||
compare(spin.from, 100)
|
||||
compare(spin.to, 3000)
|
||||
t.backend.settleMs = 700
|
||||
compare(spin.value, 700)
|
||||
}
|
||||
|
||||
function test_settle_spin_sets_backend() {
|
||||
const t = make({ settleMs: 500 })
|
||||
const spin = child(t.view, "settleSpin")
|
||||
spin.forceActiveFocus()
|
||||
keyClick(Qt.Key_Up)
|
||||
compare(t.backend.calls, ["setSettleMs 600"])
|
||||
// The daemon is the source of truth: the spin snaps back until it replies.
|
||||
compare(spin.value, 500)
|
||||
t.backend.settleMs = 600
|
||||
compare(spin.value, 600)
|
||||
}
|
||||
|
||||
function test_prompt_spin_sets_backend() {
|
||||
const t = make({ mode: "manual", promptTimeoutMs: 5000 })
|
||||
const spin = child(t.view, "promptSpin")
|
||||
compare(spin.displayText, "5 s")
|
||||
spin.forceActiveFocus()
|
||||
keyClick(Qt.Key_Down)
|
||||
compare(t.backend.calls, ["setPromptTimeoutMs 4000"])
|
||||
}
|
||||
|
||||
function test_prompt_spin_only_in_manual_mode() {
|
||||
const t = make({ mode: "auto" })
|
||||
verify(!child(t.view, "promptSpin").enabled)
|
||||
t.backend.mode = "manual"
|
||||
verify(child(t.view, "promptSpin").enabled)
|
||||
}
|
||||
|
||||
function test_timing_disabled_without_sensor() {
|
||||
const t = make({ imu: false, mode: "manual" })
|
||||
verify(!child(t.view, "settleSpin").enabled)
|
||||
verify(!child(t.view, "promptSpin").enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,4 +48,30 @@ TestCase {
|
||||
function test_summary(data) {
|
||||
compare(Logic.summary(data.b), data.want)
|
||||
}
|
||||
|
||||
function test_seconds_data() {
|
||||
return [
|
||||
{ tag: "half", ms: 500, want: "0.5 s" },
|
||||
{ tag: "tenth", ms: 100, want: "0.1 s" },
|
||||
{ tag: "one-half", ms: 1500, want: "1.5 s" },
|
||||
{ tag: "whole", ms: 5000, want: "5 s" },
|
||||
{ tag: "big", ms: 30000, want: "30 s" }
|
||||
]
|
||||
}
|
||||
|
||||
function test_seconds(data) {
|
||||
compare(Logic.seconds(data.ms), data.want)
|
||||
}
|
||||
|
||||
function test_parse_seconds() {
|
||||
compare(Logic.parseSeconds("0.5 s"), 500)
|
||||
compare(Logic.parseSeconds("12"), 12000)
|
||||
compare(Logic.parseSeconds("1,5 s"), 1500)
|
||||
verify(isNaN(Logic.parseSeconds("soon")))
|
||||
}
|
||||
|
||||
function test_limits() {
|
||||
compare(Logic.settleRange, { from: 100, to: 3000, step: 100 })
|
||||
compare(Logic.promptRange, { from: 2000, to: 30000, step: 1000 })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user