should have push notifs as well as Battery SOC monitoring
This commit is contained in:
@@ -124,6 +124,27 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
}
|
||||
});
|
||||
|
||||
socket?.on("battery_alert", (data) {
|
||||
if (data is! Map<String, dynamic>) return;
|
||||
if (data['deviceId'] != widget.deviceId) return;
|
||||
if (!mounted) return;
|
||||
final type = data['type'] as String? ?? '';
|
||||
final soc = data['soc'] as int? ?? 0;
|
||||
final (String message, Color color) = switch (type) {
|
||||
'overvoltage' => ('Battery fault detected. Please check your charger.', Colors.red),
|
||||
'critical_low' => ('Battery critically low ($soc%). Device shutting down.', Colors.red),
|
||||
'low_voltage_warning' => ('Battery voltage dip detected ($soc%). Monitor closely.', Colors.orange),
|
||||
'low_20' => ('Battery low: $soc% remaining. Consider charging soon.', Colors.orange),
|
||||
'low_10' => ('Battery very low: $soc% remaining. Charge now.', Colors.deepOrange),
|
||||
_ => ('Battery alert received ($soc%).', Colors.orange),
|
||||
};
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: color,
|
||||
duration: const Duration(seconds: 6),
|
||||
));
|
||||
});
|
||||
|
||||
socket?.on("calib", (periphData) {
|
||||
if (periphData is Map<String, dynamic>) {
|
||||
if (periphData['periphID'] == widget.peripheralId) {
|
||||
|
||||
Reference in New Issue
Block a user