Recalibrate button works properly

This commit is contained in:
2026-03-21 00:12:47 -05:00
parent 9d291652ac
commit 35f40fe562

View File

@@ -34,6 +34,7 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
String lastSetMessage = ""; String lastSetMessage = "";
int? batterySoc; int? batterySoc;
bool _movementPending = false; bool _movementPending = false;
bool _awaitingDeviceWake = false;
final _peripheralRenameController = TextEditingController(); final _peripheralRenameController = TextEditingController();
@@ -156,11 +157,14 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
if (data['periphID'] == widget.peripheralId) { if (data['periphID'] == widget.peripheralId) {
if (!mounted) return; if (!mounted) return;
if (data['calibrated'] == false) { if (data['calibrated'] == false) {
final wasAwaiting = _awaitingDeviceWake;
setState(() { setState(() {
calibrated = false; calibrated = false;
calibrating = false; calibrating = false;
calibrationStage = 0; calibrationStage = 0;
_awaitingDeviceWake = false;
}); });
if (wasAwaiting) calibrate();
} }
} }
} }
@@ -504,7 +508,7 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
style: GoogleFonts.aBeeZee(), style: GoogleFonts.aBeeZee(),
), ),
content: const Text( content: const Text(
"This will take under a minute", "After confirming, wake the device by moving the wand. Calibration will start automatically.",
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
actions: [ actions: [
@@ -517,15 +521,17 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
}, },
child: const Text( child: const Text(
"Cancel", "Cancel",
style: TextStyle( style: TextStyle(color: Colors.red),
color: Colors.red
),
) )
), ),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
calibrate();
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
socket?.emit("recalibrate", {
"periphID": widget.peripheralId,
"periphNum": widget.peripheralNum,
});
setState(() => _awaitingDeviceWake = true);
}, },
child: const Text("Confirm") child: const Text("Confirm")
) )
@@ -610,7 +616,33 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
], ],
), ),
), ),
Expanded(child: loaded Expanded(child: _awaitingDeviceWake
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Theme.of(context).primaryColorLight),
const SizedBox(height: 24),
Text(
"Wake the device by moving the wand",
style: GoogleFonts.aBeeZee(fontSize: 16),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
"Calibration will start automatically",
style: GoogleFonts.aBeeZee(fontSize: 13, color: Colors.grey),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
TextButton(
onPressed: () => setState(() => _awaitingDeviceWake = false),
child: const Text("Cancel", style: TextStyle(color: Colors.red)),
),
],
),
)
: loaded
? (calibrating ? (calibrating
? RefreshIndicator( ? RefreshIndicator(
onRefresh: initAll, onRefresh: initAll,
@@ -770,9 +802,9 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
FloatingActionButton( FloatingActionButton(
heroTag: "recalibrate", heroTag: "recalibrate",
tooltip: "Recalibrate Peripheral", tooltip: "Recalibrate Peripheral",
onPressed: (deviceConnected && calibrated) ? recalibrate : null, onPressed: recalibrate,
foregroundColor: (deviceConnected && calibrated) ? Theme.of(context).highlightColor : Colors.grey.shade400, foregroundColor: Theme.of(context).highlightColor,
backgroundColor: (deviceConnected && calibrated) ? Theme.of(context).primaryColorDark : Colors.grey.shade300, backgroundColor: Theme.of(context).primaryColorDark,
child: Icon(Icons.swap_vert), child: Icon(Icons.swap_vert),
), ),
], ],