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
+39 -15
View File
@@ -70,7 +70,7 @@ const (
cellGapX = 3
rowHMin = 46
btnW = 220
btnW = 190
btnH = 72
btnRadius = 10
btnBorder = 2
@@ -124,6 +124,9 @@ type display struct {
holdFrac float64
fired bool
autoBtn rect
autoDown bool
version string
versionSpot rect
showVersion bool
@@ -186,6 +189,7 @@ func (d *display) layout(w, h int) error {
d.headerH = headerTop + ringD + 24
colHdrH := d.small.lineH + 18
d.resetBtn = rect{w - uiMargin - btnW, h - uiMargin - btnH, btnW, btnH}
d.autoBtn = rect{d.resetBtn.x - uiColGap - btnW, d.resetBtn.y, btnW, btnH}
// Rows stretch to spend the whole band between the column headers and the
// footer, cells riding along at their design proportion of the row.
@@ -229,33 +233,26 @@ func (d *display) holdReset(x, y int, down bool, now time.Time) bool {
return true
}
// Accent rather than the status colours because it is something to press, not
// something being reported.
func (d *display) drawResetButton() {
r := d.resetBtn
d.fb.roundRect(r.x, r.y, r.w, r.h, btnRadius, uiAccent)
func (d *display) fillButton(r rect, frac float64, label string, frame, ink rgb) {
d.fb.roundRect(r.x, r.y, r.w, r.h, btnRadius, frame)
d.fb.roundRect(r.x+btnBorder, r.y+btnBorder, r.w-2*btnBorder, r.h-2*btnBorder,
btnRadius-btnBorder, uiBg)
split := r.x + btnBorder
if d.holdFrac > 0 {
w := int(float64(r.w-2*btnBorder) * math.Min(d.holdFrac, 1))
if frac > 0 {
w := int(float64(r.w-2*btnBorder) * math.Min(frac, 1))
d.fb.roundRect(r.x+btnBorder, r.y+btnBorder, w, r.h-2*btnBorder,
btnRadius-btnBorder, uiAccent)
btnRadius-btnBorder, frame)
split += w
}
label, base := "RESET", uiAccent
if d.showVersion {
label, base = d.version, uiMuted
}
lx := r.x + (r.w-len(label)*d.textB.cellW)/2
ly := r.y + (r.h-d.textB.lineH)/2 - d.textB.capTop
// The label straddles the fill, so each glyph takes the colour that reads
// against whatever is behind it.
for i, c := range label {
gx := lx + i*d.textB.cellW
col := base
col := ink
if gx+d.textB.cellW/2 < split {
col = uiBg
}
@@ -263,6 +260,32 @@ func (d *display) drawResetButton() {
}
}
// Accent rather than the status colours because it is something to press, not
// something being reported.
func (d *display) drawResetButton() {
label, ink := "RESET", uiAccent
if d.showVersion {
label, ink = d.version, uiMuted
}
d.fillButton(d.resetBtn, d.holdFrac, label, uiAccent, ink)
}
// Muted until switched on; the fill is the time already spent toward the next
// automatic measure.
func (d *display) drawAutoButton(on bool, frac float64) {
c := uiMuted
if on {
c = uiAccent
}
d.fillButton(d.autoBtn, frac, "AUTO", c, c)
}
func (d *display) tapAuto(x, y int, down bool) bool {
was := d.autoDown
d.autoDown = down
return down && !was && d.autoBtn.contains(x, y)
}
// go run never stamps VCS info, so dev builds have no revision to show.
func buildVersion() string {
info, ok := debug.ReadBuildInfo()
@@ -574,7 +597,7 @@ func (d *display) drawFooter(v view, elapsed time.Duration) {
}
func (d *display) render(v view, elapsed time.Duration, phy phyDisplay,
measuring bool, hv histView, target float64) error {
measuring bool, hv histView, target float64, autoOn bool, autoFrac float64) error {
fb := d.fb
fb.fill(uiBg)
@@ -583,6 +606,7 @@ func (d *display) render(v view, elapsed time.Duration, phy phyDisplay,
d.drawColHeaders()
d.drawRows(v, phy, measuring, hv, target)
d.drawFooter(v, elapsed)
d.drawAutoButton(autoOn, autoFrac)
d.drawResetButton()
return fb.flush()
}