diff --git a/lib/communication/commands_proto.dart b/lib/communication/commands_proto.dart index a6c64c4c7..b626477cd 100644 --- a/lib/communication/commands_proto.dart +++ b/lib/communication/commands_proto.dart @@ -132,6 +132,7 @@ class CommandsProto { int getFrequency = 3; int getInductance = 4; int getVersion = 5; + int getFwVersion = 6; int retrieveBuffer = 8; int getHighFrequency = 9; int clearBuffer = 10; diff --git a/lib/communication/packet_handler.dart b/lib/communication/packet_handler.dart index 361a41f8b..d6d4735a1 100644 --- a/lib/communication/packet_handler.dart +++ b/lib/communication/packet_handler.dart @@ -15,7 +15,7 @@ class PacketHandler { late SocketClient _socketClient; static String version = ''; late CommandsProto _mCommandsProto; - int _timeout = 500, versionStringLength = 8; + int _timeout = 500, versionStringLength = 8, fwVersionLength = 3; PacketHandler(int timeout, CommunicationHandler communicationHandler) { _connected = false; @@ -134,6 +134,22 @@ class PacketHandler { return -1; } + Future getFirmwareVersion() async { + try { + sendByte(_mCommandsProto.common); + sendByte(_mCommandsProto.getFwVersion); + int numBytesRead = await _commonRead(fwVersionLength); + if (numBytesRead == 1) { + return 2; + } else { + return _buffer[0]; + } + } catch (e) { + logger.e(e); + } + return 0; + } + Future read(Uint8List dest, int bytesToRead) async { int numBytesRead = await _commonRead(bytesToRead); for (int i = 0; i < bytesToRead; i++) { diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index ea6f43fb1..c34957a5a 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -480,5 +480,7 @@ "altitudeUnitLabel" : "m", "time" : "Time", "notAvailable" : "N/A", - "estimated" : "Estimated" + "estimated" : "Estimated", + "legacyFirmwareAlertTitle": "Legacy Firmware Detected", + "legacyFirmwareAlertMessage": "We have detected that your PSLab device is running legacy firmware. Please note that support for this firmware has ended. For the best experience and continued support, please update your device to the latest firmware version." } diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 4f3e36aaa..d77b21454 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -2789,6 +2789,18 @@ abstract class AppLocalizations { /// In en, this message translates to: /// **'Estimated'** String get estimated; + + /// No description provided for @legacyFirmwareAlertTitle. + /// + /// In en, this message translates to: + /// **'Legacy Firmware Detected'** + String get legacyFirmwareAlertTitle; + + /// No description provided for @legacyFirmwareAlertMessage. + /// + /// In en, this message translates to: + /// **'We have detected that your PSLab device is running legacy firmware. Please note that support for this firmware has ended. For the best experience and continued support, please update your device to the latest firmware version.'** + String get legacyFirmwareAlertMessage; } class _AppLocalizationsDelegate diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 6e3206fec..ca6474dea 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1444,4 +1444,11 @@ class AppLocalizationsEn extends AppLocalizations { @override String get estimated => 'Estimated'; + + @override + String get legacyFirmwareAlertTitle => 'Legacy Firmware Detected'; + + @override + String get legacyFirmwareAlertMessage => + 'We have detected that your PSLab device is running legacy firmware. Please note that support for this firmware has ended. For the best experience and continued support, please update your device to the latest firmware version.'; } diff --git a/lib/providers/board_state_provider.dart b/lib/providers/board_state_provider.dart index 74730ea11..418fecb56 100644 --- a/lib/providers/board_state_provider.dart +++ b/lib/providers/board_state_provider.dart @@ -20,10 +20,13 @@ class BoardStateProvider extends ChangeNotifier { String pslabVersionIDV6 = 'PSLab V6'; String pslabVersionIDV5 = 'PSLab V5'; int pslabVersion = 0; + int pslabFirmwareVersion = 0; late String exportFormat; bool autoStart = true; bool _isProcessing = false; + final ValueNotifier legacyFirmwareNotifier = ValueNotifier(null); + BoardStateProvider() { scienceLabCommon = getIt.get(); exportFormat = appLocalizations.txtFormat; @@ -32,9 +35,12 @@ class BoardStateProvider extends ChangeNotifier { Future initialize() async { if (_isProcessing) return; _isProcessing = true; - await scienceLabCommon.initialize(); - pslabIsConnected = await scienceLabCommon.openDevice(); - setPSLabVersionIDs(); + if (!scienceLabCommon.isConnected()) { + await scienceLabCommon.initialize(); + pslabIsConnected = await scienceLabCommon.openDevice(); + await setPSLabVersionIDs(); + await fetchFirmwareVersion(); + } _isProcessing = false; if (autoStart) { if (Platform.isAndroid) { @@ -43,9 +49,11 @@ class BoardStateProvider extends ChangeNotifier { if (usbEvent.event == UsbEvent.ACTION_USB_ATTACHED) { if (_isProcessing) return; _isProcessing = true; - if (await attemptToConnectPSLab()) { + if (!scienceLabCommon.isConnected() && + await attemptToConnectPSLab()) { pslabIsConnected = await scienceLabCommon.openDevice(); - setPSLabVersionIDs(); + await setPSLabVersionIDs(); + await fetchFirmwareVersion(); _isProcessing = false; } } else if (usbEvent.event == UsbEvent.ACTION_USB_DETACHED && @@ -74,7 +82,8 @@ class BoardStateProvider extends ChangeNotifier { Future initializeWiFi() async { if (!pslabIsConnected) { pslabIsConnected = await scienceLabCommon.openWiFiDevice(); - setPSLabVersionIDs(); + await setPSLabVersionIDs(); + await fetchFirmwareVersion(); } } @@ -88,6 +97,17 @@ class BoardStateProvider extends ChangeNotifier { notifyListeners(); } + Future fetchFirmwareVersion() async { + if (getIt.get().isConnected()) { + pslabFirmwareVersion = + await getIt.get().mPacketHandler.getFirmwareVersion(); + } + if (pslabFirmwareVersion < 3 && pslabFirmwareVersion != 0) { + legacyFirmwareNotifier.value = "LegacyFirmwareDetected"; + } + notifyListeners(); + } + Future attemptToConnectPSLab() async { if (scienceLabCommon.isConnected()) { logger.d("Device Connected Successfully"); diff --git a/lib/view/instruments_screen.dart b/lib/view/instruments_screen.dart index 7b7f9fb59..278073e67 100644 --- a/lib/view/instruments_screen.dart +++ b/lib/view/instruments_screen.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:pslab/constants.dart'; import 'package:pslab/l10n/app_localizations.dart'; +import 'package:pslab/providers/board_state_provider.dart'; import 'package:pslab/providers/locator.dart'; import 'package:pslab/view/widgets/applications_list_item.dart'; import 'package:pslab/view/widgets/main_scaffold_widget.dart'; @@ -210,6 +211,31 @@ class _InstrumentsScreenState extends State { @override void initState() { super.initState(); + getIt.get().legacyFirmwareNotifier.addListener(() { + if (getIt.get().legacyFirmwareNotifier.value == + "LegacyFirmwareDetected") { + WidgetsBinding.instance.addPostFrameCallback((_) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + icon: const Icon(Icons.warning), + title: Text(appLocalizations.legacyFirmwareAlertTitle), + content: Text(appLocalizations.legacyFirmwareAlertMessage), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text(appLocalizations.ok), + ), + ], + ); + }, + ); + }); + } + }); instrumentHeadings = [ appLocalizations.oscilloscope.toUpperCase(), appLocalizations.multimeter.toUpperCase(),