forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.dart
More file actions
278 lines (251 loc) · 10.7 KB
/
Copy pathdevice.dart
File metadata and controls
278 lines (251 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import 'dart:io';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:version/version.dart';
import 'package:omi/backend/schema/bt_device/bt_device.dart';
import 'package:omi/gen/assets.gen.dart';
class DeviceUtils {
/// Closed, analysis-safe hardware family used by product telemetry.
static String analyticsHardwareFamily(BtDevice device) {
switch (device.type) {
case DeviceType.omi:
final identity = '${device.modelNumber} ${device.name}'.toUpperCase();
if (isOmiCv1(modelNumber: device.modelNumber, deviceName: device.name)) return 'omi_cv1';
if (identity.contains('FRIEND')) return 'friend_devkit';
if (isOmiDevKit(modelNumber: device.modelNumber, deviceName: device.name)) return 'omi_devkit';
if (identity.contains('GLASS')) return 'omi_glass';
if (identity.contains('NEO')) return 'omi_neo';
return 'omi_unknown';
case DeviceType.openglass:
return 'omi_glass';
case DeviceType.appleWatch:
return 'apple_watch';
case DeviceType.plaud:
return 'plaud';
case DeviceType.bee:
return 'bee';
case DeviceType.fieldy:
return 'fieldy';
case DeviceType.friendPendant:
return 'friend_pendant';
case DeviceType.limitless:
return 'limitless';
case DeviceType.raybanMeta:
return 'rayban_meta';
}
}
static Future<(String, bool, String)> shouldUpdateFirmware({
required String currentFirmware,
required Map latestFirmwareDetails,
}) async {
if (currentFirmware.isEmpty) {
return ('Unable to determine current firmware version', false, '');
}
if (latestFirmwareDetails.isEmpty || latestFirmwareDetails['version'] == null) {
return ('Latest Version Not Available', false, '');
}
if (latestFirmwareDetails['draft']) {
return ('Latest Version Not Available', false, '');
}
Version currentVersion = Version.parse(currentFirmware);
String latestVersionStr = latestFirmwareDetails['version'];
Version latestVersion = Version.parse(latestVersionStr);
Version minVersion = Version.parse(latestFirmwareDetails['min_version']);
if (currentVersion < minVersion) {
return ('0', false, latestVersionStr);
} else {
if (latestVersion > currentVersion) {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
if (Version.parse(packageInfo.version) <= Version.parse(latestFirmwareDetails['min_app_version']) &&
int.parse(packageInfo.buildNumber) < int.parse(latestFirmwareDetails['min_app_version_code'])) {
return (
'The latest version of firmware is not compatible with this version of App (${packageInfo.version}+${packageInfo.buildNumber}). Please update the app from ${Platform.isAndroid ? 'Play Store' : 'App Store'}',
false,
latestVersionStr,
);
} else {
return ('A new version is available! Update your Omi now.', true, latestVersionStr);
}
} else {
return ('You are already on the latest version', false, latestVersionStr);
}
}
}
/// Whether an Omi-type device is a DevKit board rather than the consumer
/// pendant. Match on `DEVKIT`/`DEV KIT` (both spellings ship, e.g.
/// "Friend Dev Kit 1"), not a loose `DEV` — the consumer's default model
/// fallback is `'Omi Device'`.
static bool isOmiDevKit({String? modelNumber, String? deviceName}) {
bool matches(String? value) {
if (value == null || value.isEmpty) return false;
final upper = value.toUpperCase();
return upper.contains('DEVKIT') || upper.contains('DEV KIT');
}
return matches(modelNumber) || matches(deviceName);
}
/// Whether a [DeviceType.omi] device is the consumer CV1 pendant rather than
/// another omi-enumerated variant (DevKit 1/2, Glass, Neo, Friend), which all
/// report the same DeviceType. Used to scope CV1-only UI like the "How to use
/// your Omi" button tutorial. Callers must have already checked the device is
/// [DeviceType.omi]. CV1 reports `'Omi CV 1'` (or the `'Omi Device'` fallback
/// when the GATT model read fails), so match by excluding the known non-CV1
/// variants instead of allow-listing an exact CV1 string.
///
/// A concrete GATT model number is authoritative — trust it and ignore the
/// name. The generic `'Omi Device'` / `'Unknown'` fallback (reported by CV1
/// and DevKit alike when the model read fails) is not concrete, so defer to
/// the advertised name in that case. With neither a concrete model nor a name
/// we can't positively identify a CV1, so return false.
static bool isOmiCv1({String? modelNumber, String? deviceName}) {
const nonCv1 = ['DEVKIT', 'DEV KIT', 'GLASS', 'NEO', 'FRIEND'];
bool isVariant(String value) {
if (value.isEmpty) return false;
final upper = value.toUpperCase();
return nonCv1.any(upper.contains);
}
final model = modelNumber?.trim() ?? '';
final name = deviceName?.trim() ?? '';
final upperModel = model.toUpperCase();
final hasConcreteModel = model.isNotEmpty && upperModel != 'OMI DEVICE' && upperModel != 'UNKNOWN';
if (hasConcreteModel) return !isVariant(model);
if (name.isNotEmpty) return !isVariant(name);
return false;
}
/// Get device image path by device type and model number (most accurate)
/// Falls back to device name if type/model not available
static String getDeviceImagePath({DeviceType? deviceType, String? modelNumber, String? deviceName}) {
// Check deviceType first
if (deviceType != null) {
switch (deviceType) {
case DeviceType.limitless:
return Assets.images.limitless.path;
case DeviceType.bee:
return Assets.images.beeDevice.path;
case DeviceType.openglass:
return Assets.images.omiGlass.path;
case DeviceType.appleWatch:
return Assets.images.appleWatch.path;
case DeviceType.plaud:
return Assets.images.plaudNotePin.path;
case DeviceType.fieldy:
return Assets.images.fieldy.path;
case DeviceType.friendPendant:
return Assets.images.friendPendant.path;
case DeviceType.raybanMeta:
return Assets.images.raybanMeta.path;
case DeviceType.omi:
// For omi type, need to check model/name to distinguish between devkit and regular omi
if (modelNumber != null && modelNumber.isNotEmpty && modelNumber.toUpperCase() != 'UNKNOWN') {
final upperModel = modelNumber.toUpperCase();
if (upperModel.contains('GLASS')) {
return Assets.images.omiGlass.path;
}
if (upperModel.contains('DEVKIT') || (upperModel.contains('FRIEND'))) {
return Assets.images.omiDevkitWithoutRope.path;
}
if (upperModel.contains('NEO')) {
return Assets.images.neoOne.path;
}
}
if (deviceName != null && deviceName.isNotEmpty) {
final upperName = deviceName.toUpperCase();
if (upperName.contains('GLASS')) {
return Assets.images.omiGlass.path;
}
if (upperName.contains('DEVKIT') || upperName.contains('DEV') || (upperName.contains('FRIEND'))) {
return Assets.images.omiDevkitWithoutRope.path;
}
if (upperName.contains('NEO')) {
return Assets.images.neoOne.path;
}
}
// Default omi image
return Assets.images.omiWithoutRope.path;
}
}
// Then check modelNumber for specific variants
if (modelNumber != null && modelNumber.isNotEmpty && modelNumber.toUpperCase() != 'UNKNOWN') {
final upperModel = modelNumber.toUpperCase();
if (upperModel.contains('PLAUD')) {
return Assets.images.plaudNotePin.path;
}
if (upperModel.contains('FRIEND PENDANT')) {
return Assets.images.friendPendant.path;
}
if (upperModel.contains('OMI DEVKIT 2') || upperModel.contains('FRIEND')) {
return Assets.images.omiDevkitWithoutRope.path;
}
if (upperModel.contains('GLASS')) {
return Assets.images.omiGlass.path;
}
if (upperModel.contains('FRAME')) {
return Assets.images.omiDevkitWithoutRope.path;
}
if (upperModel.contains('BEE')) {
return Assets.images.beeDevice.path;
}
if (upperModel.contains('WATCH')) {
return Assets.images.appleWatch.path;
}
if (upperModel.contains('FIELDY') || upperModel.contains('COMPASS')) {
return Assets.images.fieldy.path;
}
if (upperModel.contains('NEO')) {
return Assets.images.neoOne.path;
}
}
// Fallback to device name
if (deviceName != null && deviceName.isNotEmpty) {
final upperName = deviceName.toUpperCase();
if (upperName.contains('PLAUD')) {
return Assets.images.plaudNotePin.path;
}
if (upperName.contains('GLASS')) {
return Assets.images.omiGlass.path;
}
if (upperName.startsWith('FRIEND_')) {
return Assets.images.friendPendant.path;
}
if (upperName.contains('OMI DEVKIT') || upperName.contains('OMI DEV') || upperName.contains('FRIEND')) {
return Assets.images.omiDevkitWithoutRope.path;
}
if (upperName.contains('BEE')) {
return Assets.images.beeDevice.path;
}
if (upperName.contains('WATCH')) {
return Assets.images.appleWatch.path;
}
if (upperName.contains('FIELDY') || upperName.contains('COMPASS')) {
return Assets.images.fieldy.path;
}
if (upperName.contains('LIMITLESS')) {
return Assets.images.limitless.path;
}
if (upperName.contains('NEO')) {
return Assets.images.neoOne.path;
}
}
// Default
return Assets.images.omiWithoutRope.path;
}
/// Convenience method when you have a BtDevice object
static String getDeviceImageFromBtDevice(BtDevice device) {
return getDeviceImagePath(deviceType: device.type, modelNumber: device.modelNumber, deviceName: device.name);
}
/// Get device image with connection state (for special cases like Omi)
static String getDeviceImagePathWithState({
DeviceType? deviceType,
String? modelNumber,
String? deviceName,
required bool isConnected,
}) {
// Special case for Omi when disconnected
if (deviceType == DeviceType.omi && !isConnected) {
return Assets.images.omiWithoutRopeTurnedOff.path;
}
// Special case for Friend Pendant when disconnected
if (deviceType == DeviceType.friendPendant && !isConnected) {
return Assets.images.friendPendant.path;
}
return getDeviceImagePath(deviceType: deviceType, modelNumber: modelNumber, deviceName: deviceName);
}
}