update method
- @override
- DriveData value
override
Updates data with new data.
Implementation
@override
void update(DriveData value) {
// Since the newValues are often zero, [Metrics.merge] won't work.
if (!checkVersion(value)) return;
services.files.logData(value);
final oldThrottle = data.throttle;
if (value.setLeft) data.left = value.left;
if (value.setRight) data.right = value.right;
if (value.setThrottle) data.throttle = value.throttle;
if (value.hasBatteryCurrent()) data.batteryCurrent = value.batteryCurrent;
if (value.hasBatteryVoltage()) data.batteryVoltage = value.batteryVoltage;
if (value.hasBatteryTemperature()) data.batteryTemperature = value.batteryTemperature;
if(value.hasFrontLeft()) data.frontLeft = value.frontLeft;
if(value.hasMiddleLeft()) data.middleLeft = value.middleLeft;
if(value.hasBackLeft()) data.backLeft = value.backLeft;
if(value.hasFrontRight()) data.frontRight = value.frontRight;
if(value.hasMiddleRight()) data.middleRight = value.middleRight;
if(value.hasBackRight()) data.backRight = value.backRight;
if (value.color != ProtoColor.PROTO_COLOR_UNDEFINED) data.color = value.color;
if (value.batteryTemperature != 0) data.batteryTemperature = value.batteryTemperature;
if (
(data.throttle > 0.05 && oldThrottle < 0.05) ||
(data.throttle < 0.05 && oldThrottle > 0.05)
) {
models.rover.controllers.firstWhereOrNull(
(controller) => controller.mode == OperatingMode.drive || controller.mode == OperatingMode.modernDrive,
)?.gamepad.pulse();
}
notifyListeners();
}