Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/communication/commands_proto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion lib/communication/packet_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,6 +134,22 @@ class PacketHandler {
return -1;
}

Future<int> 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<int> read(Uint8List dest, int bytesToRead) async {
int numBytesRead = await _commonRead(bytesToRead);
for (int i = 0; i < bytesToRead; i++) {
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
12 changes: 12 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
32 changes: 26 additions & 6 deletions lib/providers/board_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> legacyFirmwareNotifier = ValueNotifier(null);

BoardStateProvider() {
scienceLabCommon = getIt.get<ScienceLabCommon>();
exportFormat = appLocalizations.txtFormat;
Expand All @@ -32,9 +35,12 @@ class BoardStateProvider extends ChangeNotifier {
Future<void> 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) {
Expand All @@ -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 &&
Expand Down Expand Up @@ -74,7 +82,8 @@ class BoardStateProvider extends ChangeNotifier {
Future<void> initializeWiFi() async {
if (!pslabIsConnected) {
pslabIsConnected = await scienceLabCommon.openWiFiDevice();
setPSLabVersionIDs();
await setPSLabVersionIDs();
await fetchFirmwareVersion();
}
}

Expand All @@ -88,6 +97,17 @@ class BoardStateProvider extends ChangeNotifier {
notifyListeners();
}

Future<void> fetchFirmwareVersion() async {
if (getIt.get<ScienceLab>().isConnected()) {
pslabFirmwareVersion =
await getIt.get<ScienceLab>().mPacketHandler.getFirmwareVersion();
}
if (pslabFirmwareVersion < 3 && pslabFirmwareVersion != 0) {
legacyFirmwareNotifier.value = "LegacyFirmwareDetected";
}
notifyListeners();
}

Future<bool> attemptToConnectPSLab() async {
if (scienceLabCommon.isConnected()) {
logger.d("Device Connected Successfully");
Expand Down
26 changes: 26 additions & 0 deletions lib/view/instruments_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -210,6 +211,31 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {
@override
void initState() {
super.initState();
getIt.get<BoardStateProvider>().legacyFirmwareNotifier.addListener(() {
if (getIt.get<BoardStateProvider>().legacyFirmwareNotifier.value ==
"LegacyFirmwareDetected") {
WidgetsBinding.instance.addPostFrameCallback((_) {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
icon: const Icon(Icons.warning),
title: Text(appLocalizations.legacyFirmwareAlertTitle),
content: Text(appLocalizations.legacyFirmwareAlertMessage),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(appLocalizations.ok),
),
],
);
},
);
});
}
});
instrumentHeadings = [
appLocalizations.oscilloscope.toUpperCase(),
appLocalizations.multimeter.toUpperCase(),
Expand Down
Loading