Added LIPO 2 Reading
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
win:
|
||||
GOOS=windows GOARCH=386 go build .
|
||||
+1
-1
@@ -633,7 +633,7 @@ func runBatteryPoller(link *managedSerial, hub *wsHub, interval time.Duration, s
|
||||
case <-stop:
|
||||
return
|
||||
case <-ticker.C:
|
||||
if hub.clientCount() == 0 {
|
||||
if !link.IsConnected() {
|
||||
continue
|
||||
}
|
||||
bat, err := link.BatteryStatusPoll(&pb.BatteryStatusRequest{AllClients: true})
|
||||
|
||||
+23
-9
@@ -769,21 +769,35 @@
|
||||
},
|
||||
applyBatterySamples(samples) {
|
||||
if (!samples?.length) return;
|
||||
const master = { ...(this.state.master || {}) };
|
||||
const clients = [...(this.state.clients || [])];
|
||||
let masterChanged = false;
|
||||
let clientsChanged = false;
|
||||
for (const s of samples) {
|
||||
if (s.client_id === 0) {
|
||||
if (!this.state.master) this.state.master = {};
|
||||
this.state.master.lipo1 = s.lipo1;
|
||||
this.state.master.lipo2 = s.lipo2;
|
||||
this.state.master.battery_age_ms = s.age_ms;
|
||||
master.lipo1 = s.lipo1;
|
||||
master.lipo2 = s.lipo2;
|
||||
master.battery_age_ms = s.age_ms;
|
||||
masterChanged = true;
|
||||
continue;
|
||||
}
|
||||
const c = (this.state.clients || []).find((x) => x.id === s.client_id);
|
||||
if (c) {
|
||||
c.lipo1 = s.lipo1;
|
||||
c.lipo2 = s.lipo2;
|
||||
c.battery_age_ms = s.age_ms;
|
||||
const idx = clients.findIndex((x) => x.id === s.client_id);
|
||||
if (idx >= 0) {
|
||||
clients[idx] = {
|
||||
...clients[idx],
|
||||
lipo1: s.lipo1,
|
||||
lipo2: s.lipo2,
|
||||
battery_age_ms: s.age_ms,
|
||||
};
|
||||
clientsChanged = true;
|
||||
}
|
||||
}
|
||||
if (!masterChanged && !clientsChanged) return;
|
||||
this.state = {
|
||||
...this.state,
|
||||
...(masterChanged ? { master } : {}),
|
||||
...(clientsChanged ? { clients } : {}),
|
||||
};
|
||||
},
|
||||
async refreshBattery() {
|
||||
if (!this.state?.uart_connected) return;
|
||||
|
||||
Reference in New Issue
Block a user