Reset everything from a held on-screen button or space

This commit is contained in:
flamingcow
2026-07-25 21:41:21 -07:00
parent b2441ba64a
commit 09411aebdf
3 changed files with 259 additions and 12 deletions
+29 -11
View File
@@ -251,11 +251,25 @@ func (d *direction) snapshot() sample {
}
// Counters keep climbing in the workers, so resetting just moves the origin
// the display subtracts from.
func (d *direction) resetErrors() {
// everything is measured from. Rates are deliberately left running, since they
// are instantaneous and would only blink to zero and back.
func (d *direction) reset() {
d.sampleDrops()
d.errBase = d.snapshot()
d.dropBase = d.drops
d.heldFrames = heldValue{}
d.heldSent = heldValue{}
}
// Returns the new start time, so the uptime shown alongside the totals counts
// from the reset rather than from launch.
func resetAll(dirs []*direction, stats *streamTable) time.Time {
for _, d := range dirs {
d.reset()
}
stats.sinceHeader = 0
fmt.Println(stats.rule("counters reset"))
return time.Now()
}
func (d *direction) sampleDrops() {
@@ -300,10 +314,10 @@ type view struct {
func (d *direction) counters(now sample) view {
b := d.errBase
v := view{
txFrames: now.txFrames,
txSent: now.txBytes,
rxFrames: now.rxFrames,
rxGot: now.rxBytes,
txFrames: now.txFrames - b.txFrames,
txSent: now.txBytes - b.txBytes,
rxFrames: now.rxFrames - b.rxFrames,
rxGot: now.rxBytes - b.rxBytes,
lost: now.lost - b.lost,
late: now.late - b.late,
crc: now.crcErr - b.crcErr,
@@ -644,6 +658,11 @@ func run(aName, bName, sizesArg, patArg string,
}
defer disp.close()
touch, err := watchTouch(disp.fb.w, disp.fb.h)
if err != nil {
return fmt.Errorf("touchscreen: %w", err)
}
start := time.Now()
close(startTx)
tick := time.NewTicker(reportInterval)
@@ -666,12 +685,11 @@ func run(aName, bName, sizesArg, patArg string,
wg.Wait()
return nil
case <-space:
for _, d := range dirs {
d.resetErrors()
}
stats.sinceHeader = 0
fmt.Println(stats.rule("error counts reset"))
start = resetAll(dirs, stats)
case now := <-frame.C:
if x, y, down := touch.get(); disp.holdReset(x, y, down, now) {
start = resetAll(dirs, stats)
}
for i, d := range dirs {
views[i] = d.displayView(now)
}