Add an auto-measure toggle with a cable length range, and console keys through the harness

This commit is contained in:
flamingcow
2026-08-30 19:10:00 -07:00
parent 36c2ff34fe
commit 5a74fe0c76
6 changed files with 188 additions and 41 deletions
+27 -7
View File
@@ -56,8 +56,8 @@ func resetAll(dirs []*direction, mods []*phyModule) time.Time {
// Nothing to hold or revert here: failures during a measure were never
// counted, so the view is always the counters as they stand.
func phyView(diag *cableDiag, modules []*phyModule) (phyDisplay, bool) {
info, measuring := diag.snapshot()
return phyDisplayFrom(info, measuring, modules[0].view(), modules[1].view()), measuring
info, rng, measuring := diag.snapshot()
return phyDisplayFrom(info, rng, measuring, modules[0].view(), modules[1].view()), measuring
}
var intervalCols = []colSpec{
@@ -141,7 +141,8 @@ func main() {
}
const (
reportInterval = time.Second
reportInterval = time.Second
autoMeasurePeriod = 60 * time.Second
// Deliberately not tied to the refresh: letting a slow or blocked draw set
// the sampling clock would stretch the window it reports.
sampleInterval = 16 * time.Millisecond
@@ -320,7 +321,7 @@ func run(aName, bName string) (err error) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
space, restoreTerm := watchSpace()
keys, restoreTerm := watchKeys()
defer restoreTerm()
disp, err := newDisplay()
@@ -345,6 +346,7 @@ func run(aName, bName string) (err error) {
// hide or revert afterwards.
kickMeasure := func() {
if diag.kick(&done) {
diag.resetRange()
start = resetAll(dirs, modules)
hist.reset()
}
@@ -359,6 +361,8 @@ func run(aName, bName string) (err error) {
views := make([]view, len(dirs))
rows := make([]view, len(dirs))
stats := &streamTable{cols: intervalCols, headerEvery: 20}
var autoOn bool
var autoAnchor time.Time
for {
select {
case p := <-fatalCh:
@@ -366,8 +370,13 @@ func run(aName, bName string) (err error) {
case <-sig:
return nil
// The verdict lives in the cable cell, not its own line.
case <-space:
kickMeasure()
case b := <-keys:
switch b {
case ' ', 'r':
kickMeasure()
case 'a':
autoOn, autoAnchor = !autoOn, time.Now()
}
case <-disp.fb.flips:
now := time.Now()
px, py, down := touch.get()
@@ -375,6 +384,17 @@ func run(aName, bName string) (err error) {
if disp.holdReset(x, y, down, now) {
kickMeasure()
}
if disp.tapAuto(x, y, down) {
autoOn, autoAnchor = !autoOn, now
}
autoFrac := 0.0
if autoOn {
autoFrac = float64(now.Sub(autoAnchor)) / float64(autoMeasurePeriod)
if autoFrac >= 1 {
diag.kick(&done)
autoAnchor, autoFrac = now, 0
}
}
disp.showVersion = down && disp.versionSpot.contains(x, y)
for i, d := range dirs {
views[i] = d.displayView()
@@ -383,7 +403,7 @@ func run(aName, bName string) (err error) {
phy, measuring := phyView(diag, modules)
hist.sample(now, v, phy, measuring, target)
if err := disp.render(v, now.Sub(start), phy, measuring,
hist.view(now), target); err != nil {
hist.view(now), target, autoOn, autoFrac); err != nil {
return err
}
case now := <-tick.C: