mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
sensor stream throttle and new roster panel
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
sensorHeader = 19
|
||||
sensorReadTimeout = 150 * time.Millisecond
|
||||
sensorHeader = 19
|
||||
sensorReadTimeout = 150 * time.Millisecond
|
||||
sensorThrottleMinimum = 80 * time.Millisecond
|
||||
)
|
||||
|
||||
type SensorStreamer struct {
|
||||
@@ -29,6 +30,7 @@ func NewSensorStreamer(r io.Reader, rawOut chan<- []byte, parsed chan<- SensorSa
|
||||
|
||||
func (s *SensorStreamer) Run(ctx context.Context) {
|
||||
reader := bufio.NewReader(s.r)
|
||||
var nextSend time.Time
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -62,6 +64,12 @@ func (s *SensorStreamer) Run(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if !nextSend.IsZero() && now.Before(nextSend) {
|
||||
continue
|
||||
}
|
||||
nextSend = now.Add(sensorThrottleMinimum)
|
||||
|
||||
select {
|
||||
case s.rawOut <- frame:
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user