Skip to content

Commit 07a6a29

Browse files
authored
fix(ios): comms handler not initializing (#2626)
1 parent ff727a0 commit 07a6a29

15 files changed

+146
-12
lines changed

ios/Podfile.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
PODS:
22
- Flutter (1.0.0)
3+
- flutter_audio_capture (1.1.4):
4+
- Flutter
35
- path_provider_foundation (0.0.1):
46
- Flutter
57
- FlutterMacOS
8+
- permission_handler_apple (9.3.0):
9+
- Flutter
610

711
DEPENDENCIES:
812
- Flutter (from `Flutter`)
13+
- flutter_audio_capture (from `.symlinks/plugins/flutter_audio_capture/ios`)
914
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
15+
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
1016

1117
EXTERNAL SOURCES:
1218
Flutter:
1319
:path: Flutter
20+
flutter_audio_capture:
21+
:path: ".symlinks/plugins/flutter_audio_capture/ios"
1422
path_provider_foundation:
1523
:path: ".symlinks/plugins/path_provider_foundation/darwin"
24+
permission_handler_apple:
25+
:path: ".symlinks/plugins/permission_handler_apple/ios"
1626

1727
SPEC CHECKSUMS:
1828
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
29+
flutter_audio_capture: e1681f0d73912d756ef02313e9505e8d19246867
1930
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
31+
permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d
2032

21-
PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796
33+
PODFILE CHECKSUM: ec8b70a489dd1f81e53ef185cf7ad30fce8f8d00
2234

2335
COCOAPODS: 1.16.2

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
9705A1C41CF9048500538489 /* Embed Frameworks */,
199199
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
200200
C8B0F9A46182CD022AB63602 /* [CP] Embed Pods Frameworks */,
201+
31EA1FE1A656C4F7D7D9E007 /* [CP] Copy Pods Resources */,
201202
);
202203
buildRules = (
203204
);
@@ -269,6 +270,23 @@
269270
/* End PBXResourcesBuildPhase section */
270271

271272
/* Begin PBXShellScriptBuildPhase section */
273+
31EA1FE1A656C4F7D7D9E007 /* [CP] Copy Pods Resources */ = {
274+
isa = PBXShellScriptBuildPhase;
275+
buildActionMask = 2147483647;
276+
files = (
277+
);
278+
inputFileListPaths = (
279+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
280+
);
281+
name = "[CP] Copy Pods Resources";
282+
outputFileListPaths = (
283+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
284+
);
285+
runOnlyForDeploymentPostprocessing = 0;
286+
shellPath = /bin/sh;
287+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
288+
showEnvVarsInLog = 0;
289+
};
272290
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
273291
isa = PBXShellScriptBuildPhase;
274292
alwaysOutOfDate = 1;
@@ -690,8 +708,8 @@
690708
);
691709
PRODUCT_BUNDLE_IDENTIFIER = io.pslab;
692710
PRODUCT_NAME = "$(TARGET_NAME)";
693-
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "match AppStore io.pslab";
694711
PROVISIONING_PROFILE_SPECIFIER = "";
712+
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "match AppStore io.pslab";
695713
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
696714
SWIFT_VERSION = 5.0;
697715
VERSIONING_SYSTEM = "apple-generic";

lib/communication/communication_handler.dart renamed to lib/communication/handler/android_comms_handler.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import 'dart:async';
22

33
import 'package:flutter/foundation.dart';
4+
import 'package:pslab/communication/handler/base.dart';
45
import 'package:pslab/others/logger_service.dart';
56
import 'package:usb_serial/usb_serial.dart';
67

7-
class CommunicationHandler {
8+
class AndroidUSBCommunicationHandler implements CommunicationHandler {
89
static const int pslabVendorIdV5 = 1240;
910
static const int pslabProductIdV5 = 223;
1011
static const int pslabVendorIdV6 = 0x10C4;
1112
static const int pslabProductIdV6 = 0xEA60;
1213
UsbDevice? mDevice;
1314
UsbPort? mPort;
15+
16+
@override
1417
bool connected = false;
18+
19+
@override
1520
bool deviceFound = false;
1621

22+
@override
1723
Future<void> initialize() async {
1824
List<UsbDevice> devices = await UsbSerial.listDevices();
1925
for (UsbDevice device in devices) {
@@ -31,6 +37,7 @@ class CommunicationHandler {
3137
}
3238
}
3339

40+
@override
3441
Future<void> open() async {
3542
if (!deviceFound) {
3643
throw Exception("Device not connected");
@@ -51,16 +58,20 @@ class CommunicationHandler {
5158
connected = true;
5259
}
5360

61+
@override
5462
bool isDeviceFound() => deviceFound;
5563

64+
@override
5665
bool isConnected() => connected;
5766

67+
@override
5868
void close() {
5969
if (!connected || mPort == null) return;
6070
mPort?.close();
6171
connected = false;
6272
}
6373

74+
@override
6475
Future<int> read(Uint8List dest, int bytesToRead, int timeoutMillis) async {
6576
int numBytesRead = 0;
6677
int bytesToBeReadTemp = bytesToRead;
@@ -92,6 +103,7 @@ class CommunicationHandler {
92103
return numBytesRead;
93104
}
94105

106+
@override
95107
void write(Uint8List src, int timeoutMillis) {
96108
mPort?.write(src);
97109
}

lib/communication/handler/base.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'dart:typed_data';
2+
3+
interface class CommunicationHandler {
4+
bool connected = false;
5+
bool deviceFound = false;
6+
7+
Future<void> initialize() {
8+
throw UnimplementedError();
9+
}
10+
11+
Future<void> open() async {
12+
throw UnimplementedError();
13+
}
14+
15+
bool isDeviceFound() {
16+
throw UnimplementedError();
17+
}
18+
19+
bool isConnected() {
20+
throw UnimplementedError();
21+
}
22+
23+
void close() {
24+
throw UnimplementedError();
25+
}
26+
27+
Future<int> read(Uint8List dest, int bytesToRead, int timeoutMillis) async {
28+
throw UnimplementedError();
29+
}
30+
31+
void write(Uint8List src, int timeoutMillis) {
32+
throw UnimplementedError();
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/foundation.dart';
4+
import 'package:pslab/communication/handler/base.dart';
5+
6+
class IosNoOpCommunicationHandler implements CommunicationHandler {
7+
@override
8+
bool connected = false;
9+
10+
@override
11+
bool deviceFound = false;
12+
13+
@override
14+
Future<void> initialize() async {}
15+
16+
@override
17+
Future<void> open() async {}
18+
19+
@override
20+
bool isDeviceFound() => deviceFound;
21+
22+
@override
23+
bool isConnected() => connected;
24+
25+
@override
26+
void close() {}
27+
28+
@override
29+
Future<int> read(Uint8List dest, int bytesToRead, int timeoutMillis) async {
30+
return -1;
31+
}
32+
33+
@override
34+
void write(Uint8List src, int timeoutMillis) {}
35+
}

lib/communication/packet_handler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dart:convert';
22

33
import 'package:flutter/foundation.dart';
44
import 'package:pslab/communication/commands_proto.dart';
5-
import 'package:pslab/communication/communication_handler.dart';
5+
import 'package:pslab/communication/handler/base.dart';
66
import 'package:pslab/others/logger_service.dart';
77

88
class PacketHandler {

lib/communication/science_lab.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:math';
22
import 'package:flutter/foundation.dart';
33
import 'package:pslab/communication/commands_proto.dart';
4-
import 'package:pslab/communication/communication_handler.dart';
4+
import 'package:pslab/communication/handler/base.dart';
55
import 'package:pslab/communication/packet_handler.dart';
66
import 'package:pslab/others/logger_service.dart';
77

lib/others/science_lab_common.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:pslab/communication/communication_handler.dart';
1+
import 'package:pslab/communication/handler/base.dart';
22
import 'package:pslab/communication/science_lab.dart';
33
import 'package:pslab/others/logger_service.dart';
44

lib/providers/board_state_provider.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/cupertino.dart';
2-
import 'package:pslab/communication/communication_handler.dart';
2+
import 'package:get_it/get_it.dart';
3+
import 'package:pslab/communication/handler/base.dart';
34
import 'package:pslab/others/logger_service.dart';
45
import 'package:usb_serial/usb_serial.dart';
56

@@ -15,7 +16,7 @@ class BoardStateProvider extends ChangeNotifier {
1516

1617
Future<void> initialize() async {
1718
scienceLabCommon = ScienceLabCommon();
18-
communicationHandler = CommunicationHandler();
19+
communicationHandler = GetIt.instance.get<CommunicationHandler>();
1920
await communicationHandler.initialize();
2021
pslabIsConnected = await scienceLabCommon.openDevice(communicationHandler);
2122
setPSLabVersionIDs();

lib/providers/locator.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
import 'dart:io';
2+
13
import 'package:get_it/get_it.dart';
4+
import 'package:pslab/communication/handler/android_comms_handler.dart';
5+
import 'package:pslab/communication/handler/base.dart';
6+
import 'package:pslab/communication/handler/ios_comms_handler.dart';
27
import 'package:pslab/providers/board_state_provider.dart';
38

49
final GetIt getIt = GetIt.instance;
510

611
void setupLocator() {
12+
getIt.registerLazySingleton<CommunicationHandler>(() {
13+
if (Platform.isAndroid) {
14+
return AndroidUSBCommunicationHandler();
15+
} else {
16+
return IosNoOpCommunicationHandler();
17+
}
18+
});
719
getIt.registerLazySingleton<BoardStateProvider>(() => BoardStateProvider());
820
}

0 commit comments

Comments
 (0)