react-native-flic2 2.0.0-alpha.39 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +796 -13
- package/android/build.gradle +1 -1
- package/android/src/main/AndroidManifest.xml +23 -0
- package/android/src/main/java/nl/xguard/flic2/ActivityUtil.kt +29 -0
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2ButtonListener.kt +25 -13
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Converter.kt +2 -3
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Module.kt +126 -85
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Package.kt +2 -1
- package/android/src/main/java/nl/xguard/flic2/Flic2Service.kt +274 -0
- package/ios/Flic2.h +0 -1
- package/ios/Flic2.mm +223 -195
- package/lib/module/NativeFlic2.js +26 -0
- package/lib/module/NativeFlic2.js.map +1 -1
- package/lib/module/index.js +248 -76
- package/lib/module/index.js.map +1 -1
- package/lib/module/lib/typedEventEmitter.js +39 -0
- package/lib/module/lib/typedEventEmitter.js.map +1 -0
- package/lib/typescript/src/NativeFlic2.d.ts +44 -60
- package/lib/typescript/src/NativeFlic2.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +163 -80
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/lib/typedEventEmitter.d.ts +15 -0
- package/lib/typescript/src/lib/typedEventEmitter.d.ts.map +1 -0
- package/package.json +25 -25
- package/src/NativeFlic2.ts +62 -47
- package/src/index.ts +360 -0
- package/src/lib/typedEventEmitter.ts +63 -0
- package/android/src/main/java/com/flic2/Flic2Service.kt +0 -112
- package/src/index.tsx +0 -159
package/ios/Flic2.mm
CHANGED
|
@@ -8,16 +8,6 @@
|
|
|
8
8
|
return self;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
12
|
-
|
|
13
|
-
NSLog(@"multiply: %f * %f", a, b);
|
|
14
|
-
NSNumber *result = @(a * b);
|
|
15
|
-
|
|
16
|
-
[self emitOnMultiply:@{@"a": @(a), @"b": @(b), @"result": result}];
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
11
|
// MARK: - FLICManager Methods
|
|
22
12
|
|
|
23
13
|
- (void)initialize:(BOOL)background
|
|
@@ -28,8 +18,7 @@
|
|
|
28
18
|
FLICManager *manager = [FLICManager configureWithDelegate:self buttonDelegate:self background:background];
|
|
29
19
|
|
|
30
20
|
if (manager) {
|
|
31
|
-
|
|
32
|
-
resolve(@{@"success": @YES, @"message": @"Manager initialized successfully"});
|
|
21
|
+
resolve(nil);
|
|
33
22
|
} else {
|
|
34
23
|
reject(@"INIT_ERROR", @"Failed to initialize FLICManager", nil);
|
|
35
24
|
}
|
|
@@ -38,7 +27,7 @@
|
|
|
38
27
|
- (void)getButtons:(RCTPromiseResolveBlock)resolve
|
|
39
28
|
reject:(RCTPromiseRejectBlock)reject
|
|
40
29
|
{
|
|
41
|
-
if (!
|
|
30
|
+
if (![FLICManager sharedManager]) {
|
|
42
31
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
43
32
|
return;
|
|
44
33
|
}
|
|
@@ -61,7 +50,7 @@
|
|
|
61
50
|
- (void)scanForButtons:(RCTPromiseResolveBlock)resolve
|
|
62
51
|
reject:(RCTPromiseRejectBlock)reject
|
|
63
52
|
{
|
|
64
|
-
if (!
|
|
53
|
+
if (![FLICManager sharedManager]) {
|
|
65
54
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
66
55
|
return;
|
|
67
56
|
}
|
|
@@ -75,25 +64,25 @@
|
|
|
75
64
|
|
|
76
65
|
__weak Flic2 *weakSelf = self;
|
|
77
66
|
|
|
78
|
-
|
|
79
|
-
|
|
67
|
+
// Emit started event
|
|
68
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
80
69
|
[weakSelf emitOnScanStatusChange:@{
|
|
81
|
-
@"event": @
|
|
82
|
-
@"eventName":
|
|
70
|
+
@"event": @"started",
|
|
71
|
+
@"eventName": @"started"
|
|
83
72
|
}];
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
[[FLICManager sharedManager] scanForButtonsWithStateChangeHandler:^(FLICButtonScannerStatusEvent event) {
|
|
76
|
+
|
|
77
|
+
// Intermediate scan status events are intentionally not emitted
|
|
78
|
+
|
|
84
79
|
} completion:^(FLICButton * _Nullable button, NSError * _Nullable error) {
|
|
85
80
|
NSLog(@"Scan completion called - button: %@, error: %@", button ? @"YES" : @"NO", error);
|
|
86
81
|
|
|
82
|
+
NSInteger resultCode = [weakSelf mapScanErrorToResultCode:error];
|
|
83
|
+
|
|
87
84
|
if (error) {
|
|
88
|
-
NSLog(@"Scan error: %@ (code: %ld)", error.localizedDescription, (long)error.code);
|
|
89
|
-
// Check for specific error codes
|
|
90
|
-
if (error.code == FLICButtonScannerErrorCodeUserCanceled) {
|
|
91
|
-
NSLog(@"Scan was cancelled by user");
|
|
92
|
-
} else if (error.code == FLICButtonScannerErrorCodeNoPublicButtonDiscovered) {
|
|
93
|
-
NSLog(@"No Flic button found in range");
|
|
94
|
-
} else {
|
|
95
|
-
NSLog(@"Scan error: %@", error.localizedDescription);
|
|
96
|
-
}
|
|
85
|
+
NSLog(@"Scan error: %@ (code: %ld, mapped: %ld)", error.localizedDescription, (long)error.code, (long)resultCode);
|
|
97
86
|
} else if (button) {
|
|
98
87
|
NSLog(@"Button found: %@", button.uuid);
|
|
99
88
|
|
|
@@ -102,51 +91,56 @@
|
|
|
102
91
|
[button connect];
|
|
103
92
|
|
|
104
93
|
// Emit button event for discovered button
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
95
|
+
[weakSelf emitOnButtonEvent:@{
|
|
96
|
+
@"uuid": button.uuid,
|
|
97
|
+
@"event": @"discovered",
|
|
98
|
+
@"button": [weakSelf buttonToDictionary:button]
|
|
99
|
+
}];
|
|
100
|
+
});
|
|
101
|
+
|
|
110
102
|
} else {
|
|
111
103
|
NSLog(@"No button found and no error");
|
|
112
104
|
}
|
|
105
|
+
|
|
106
|
+
// Emit scan completion with result code
|
|
107
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
108
|
+
[weakSelf emitOnScanStatusChange:@{
|
|
109
|
+
@"event": @"completion",
|
|
110
|
+
@"eventName": @"completion",
|
|
111
|
+
@"result": @(resultCode)
|
|
112
|
+
}];
|
|
113
|
+
});
|
|
113
114
|
}];
|
|
114
115
|
|
|
115
116
|
// Return immediately - scan results will come through events
|
|
116
|
-
resolve(
|
|
117
|
+
resolve(nil);
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
- (void)stopScan:(RCTPromiseResolveBlock)resolve
|
|
120
121
|
reject:(RCTPromiseRejectBlock)reject
|
|
121
122
|
{
|
|
122
|
-
if (!
|
|
123
|
+
if (![FLICManager sharedManager]) {
|
|
123
124
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
NSLog(@"Stopping scan");
|
|
128
129
|
[[FLICManager sharedManager] stopScan];
|
|
129
|
-
|
|
130
|
+
|
|
131
|
+
resolve(nil);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
- (void)forgetButton:(NSString *)uuid
|
|
133
135
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
134
136
|
reject:(RCTPromiseRejectBlock)reject
|
|
135
137
|
{
|
|
136
|
-
if (!
|
|
138
|
+
if (![FLICManager sharedManager]) {
|
|
137
139
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
138
140
|
return;
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
|
|
142
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
143
|
-
FLICButton *button = nil;
|
|
144
|
-
for (FLICButton *btn in buttons) {
|
|
145
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
146
|
-
button = btn;
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
143
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
150
144
|
|
|
151
145
|
if (!button) {
|
|
152
146
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -160,7 +154,7 @@
|
|
|
160
154
|
if (error) {
|
|
161
155
|
reject(@"FORGET_ERROR", error.localizedDescription, error);
|
|
162
156
|
} else {
|
|
163
|
-
resolve(
|
|
157
|
+
resolve(nil);
|
|
164
158
|
}
|
|
165
159
|
}];
|
|
166
160
|
}
|
|
@@ -171,15 +165,7 @@
|
|
|
171
165
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
172
166
|
reject:(RCTPromiseRejectBlock)reject
|
|
173
167
|
{
|
|
174
|
-
|
|
175
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
176
|
-
FLICButton *button = nil;
|
|
177
|
-
for (FLICButton *btn in buttons) {
|
|
178
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
179
|
-
button = btn;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
168
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
183
169
|
|
|
184
170
|
if (!button) {
|
|
185
171
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -187,22 +173,14 @@
|
|
|
187
173
|
}
|
|
188
174
|
|
|
189
175
|
[button connect];
|
|
190
|
-
resolve(
|
|
176
|
+
resolve([self buttonToDictionary:button]);
|
|
191
177
|
}
|
|
192
178
|
|
|
193
179
|
- (void)disconnectButton:(NSString *)uuid
|
|
194
180
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
195
181
|
reject:(RCTPromiseRejectBlock)reject
|
|
196
182
|
{
|
|
197
|
-
|
|
198
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
199
|
-
FLICButton *button = nil;
|
|
200
|
-
for (FLICButton *btn in buttons) {
|
|
201
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
202
|
-
button = btn;
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
183
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
206
184
|
|
|
207
185
|
if (!button) {
|
|
208
186
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -210,22 +188,14 @@
|
|
|
210
188
|
}
|
|
211
189
|
|
|
212
190
|
[button disconnect];
|
|
213
|
-
resolve(
|
|
191
|
+
resolve([self buttonToDictionary:button]);
|
|
214
192
|
}
|
|
215
193
|
|
|
216
194
|
- (void)setTriggerMode:(NSString *)uuid mode:(NSInteger)mode
|
|
217
195
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
218
196
|
reject:(RCTPromiseRejectBlock)reject
|
|
219
197
|
{
|
|
220
|
-
|
|
221
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
222
|
-
FLICButton *button = nil;
|
|
223
|
-
for (FLICButton *btn in buttons) {
|
|
224
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
225
|
-
button = btn;
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
198
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
229
199
|
|
|
230
200
|
if (!button) {
|
|
231
201
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -233,22 +203,14 @@
|
|
|
233
203
|
}
|
|
234
204
|
|
|
235
205
|
button.triggerMode = (FLICButtonTriggerMode)mode;
|
|
236
|
-
resolve(
|
|
206
|
+
resolve([self buttonToDictionary:button]);
|
|
237
207
|
}
|
|
238
208
|
|
|
239
209
|
- (void)setLatencyMode:(NSString *)uuid mode:(NSInteger)mode
|
|
240
210
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
241
211
|
reject:(RCTPromiseRejectBlock)reject
|
|
242
212
|
{
|
|
243
|
-
|
|
244
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
245
|
-
FLICButton *button = nil;
|
|
246
|
-
for (FLICButton *btn in buttons) {
|
|
247
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
248
|
-
button = btn;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
213
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
252
214
|
|
|
253
215
|
if (!button) {
|
|
254
216
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -256,22 +218,14 @@
|
|
|
256
218
|
}
|
|
257
219
|
|
|
258
220
|
button.latencyMode = (FLICLatencyMode)mode;
|
|
259
|
-
resolve(
|
|
221
|
+
resolve([self buttonToDictionary:button]);
|
|
260
222
|
}
|
|
261
223
|
|
|
262
224
|
- (void)setNickname:(NSString *)uuid nickname:(NSString *)nickname
|
|
263
225
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
264
226
|
reject:(RCTPromiseRejectBlock)reject
|
|
265
227
|
{
|
|
266
|
-
|
|
267
|
-
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
268
|
-
FLICButton *button = nil;
|
|
269
|
-
for (FLICButton *btn in buttons) {
|
|
270
|
-
if ([btn.uuid isEqualToString:uuid]) {
|
|
271
|
-
button = btn;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
228
|
+
FLICButton *button = [self findButtonByUUID:uuid];
|
|
275
229
|
|
|
276
230
|
if (!button) {
|
|
277
231
|
reject(@"BUTTON_NOT_FOUND", @"Button not found", nil);
|
|
@@ -279,7 +233,7 @@
|
|
|
279
233
|
}
|
|
280
234
|
|
|
281
235
|
button.nickname = nickname;
|
|
282
|
-
resolve(
|
|
236
|
+
resolve([self buttonToDictionary:button]);
|
|
283
237
|
}
|
|
284
238
|
|
|
285
239
|
// MARK: - Helper Methods
|
|
@@ -287,7 +241,7 @@
|
|
|
287
241
|
- (void)connectAllKnownButtons:(RCTPromiseResolveBlock)resolve
|
|
288
242
|
reject:(RCTPromiseRejectBlock)reject
|
|
289
243
|
{
|
|
290
|
-
if (!
|
|
244
|
+
if (![FLICManager sharedManager]) {
|
|
291
245
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
292
246
|
return;
|
|
293
247
|
}
|
|
@@ -300,13 +254,13 @@
|
|
|
300
254
|
[button connect];
|
|
301
255
|
}
|
|
302
256
|
|
|
303
|
-
resolve(
|
|
257
|
+
resolve(nil);
|
|
304
258
|
}
|
|
305
259
|
|
|
306
260
|
- (void)disconnectAllKnownButtons:(RCTPromiseResolveBlock)resolve
|
|
307
261
|
reject:(RCTPromiseRejectBlock)reject
|
|
308
262
|
{
|
|
309
|
-
if (!
|
|
263
|
+
if (![FLICManager sharedManager]) {
|
|
310
264
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
311
265
|
return;
|
|
312
266
|
}
|
|
@@ -318,13 +272,13 @@
|
|
|
318
272
|
[button disconnect];
|
|
319
273
|
}
|
|
320
274
|
|
|
321
|
-
resolve(
|
|
275
|
+
resolve(nil);
|
|
322
276
|
}
|
|
323
277
|
|
|
324
278
|
- (void)forgetAllButtons:(RCTPromiseResolveBlock)resolve
|
|
325
279
|
reject:(RCTPromiseRejectBlock)reject
|
|
326
280
|
{
|
|
327
|
-
if (!
|
|
281
|
+
if (![FLICManager sharedManager]) {
|
|
328
282
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
329
283
|
return;
|
|
330
284
|
}
|
|
@@ -338,13 +292,13 @@
|
|
|
338
292
|
}];
|
|
339
293
|
}
|
|
340
294
|
|
|
341
|
-
resolve(
|
|
295
|
+
resolve(nil);
|
|
342
296
|
}
|
|
343
297
|
|
|
344
298
|
- (void)isScanning:(RCTPromiseResolveBlock)resolve
|
|
345
299
|
reject:(RCTPromiseRejectBlock)reject
|
|
346
300
|
{
|
|
347
|
-
if (!
|
|
301
|
+
if (![FLICManager sharedManager]) {
|
|
348
302
|
reject(@"NOT_INITIALIZED", @"Manager not initialized", nil);
|
|
349
303
|
return;
|
|
350
304
|
}
|
|
@@ -358,36 +312,44 @@
|
|
|
358
312
|
- (void)managerDidRestoreState:(FLICManager *)manager {
|
|
359
313
|
self.managerRestored = YES;
|
|
360
314
|
NSLog(@"Manager state restored - ready for operations");
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
315
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
316
|
+
[self emitOnManagerStateChange:@{
|
|
317
|
+
@"event": @"restored",
|
|
318
|
+
@"message": @"Manager state restored"
|
|
319
|
+
}];
|
|
320
|
+
});
|
|
365
321
|
}
|
|
366
322
|
|
|
367
323
|
- (void)manager:(FLICManager *)manager didUpdateState:(FLICManagerState)state {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
324
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
325
|
+
[self emitOnManagerStateChange:@{
|
|
326
|
+
@"state": @(state),
|
|
327
|
+
@"stateName": [self managerStateToString:state],
|
|
328
|
+
@"event": @"stateChanged"
|
|
329
|
+
}];
|
|
330
|
+
});
|
|
373
331
|
}
|
|
374
332
|
|
|
375
333
|
// MARK: - FLICButtonDelegate
|
|
376
334
|
|
|
377
335
|
- (void)buttonDidConnect:(FLICButton *)button {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
336
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
337
|
+
[self emitOnButtonEvent:@{
|
|
338
|
+
@"uuid": button.uuid,
|
|
339
|
+
@"event": @"connected",
|
|
340
|
+
@"button": [self buttonToDictionary:button]
|
|
341
|
+
}];
|
|
342
|
+
});
|
|
383
343
|
}
|
|
384
344
|
|
|
385
345
|
- (void)buttonIsReady:(FLICButton *)button {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
346
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
347
|
+
[self emitOnButtonEvent:@{
|
|
348
|
+
@"uuid": button.uuid,
|
|
349
|
+
@"event": @"ready",
|
|
350
|
+
@"button": [self buttonToDictionary:button]
|
|
351
|
+
}];
|
|
352
|
+
});
|
|
391
353
|
}
|
|
392
354
|
|
|
393
355
|
- (void)button:(FLICButton *)button didDisconnectWithError:(NSError * _Nullable)error {
|
|
@@ -404,99 +366,129 @@
|
|
|
404
366
|
};
|
|
405
367
|
}
|
|
406
368
|
|
|
407
|
-
|
|
369
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
370
|
+
[self emitOnButtonEvent:eventData];
|
|
371
|
+
});
|
|
408
372
|
}
|
|
409
373
|
|
|
410
374
|
- (void)button:(FLICButton *)button didFailToConnectWithError:(NSError * _Nullable)error {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
@"
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
375
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
376
|
+
[self emitOnButtonEvent:@{
|
|
377
|
+
@"uuid": button.uuid,
|
|
378
|
+
@"event": @"connectionFailed",
|
|
379
|
+
@"error": @{
|
|
380
|
+
@"code": @(error.code),
|
|
381
|
+
@"message": error.localizedDescription
|
|
382
|
+
},
|
|
383
|
+
@"button": [self buttonToDictionary:button]
|
|
384
|
+
}];
|
|
385
|
+
});
|
|
420
386
|
}
|
|
421
387
|
|
|
422
388
|
- (void)button:(FLICButton *)button didReceiveButtonDown:(BOOL)queued age:(NSInteger)age {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
389
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
390
|
+
[self emitOnButtonEvent:@{
|
|
391
|
+
@"uuid": button.uuid,
|
|
392
|
+
@"event": @"buttonDown",
|
|
393
|
+
@"queued": @(queued),
|
|
394
|
+
@"age": @(age),
|
|
395
|
+
@"button": [self buttonToDictionary:button]
|
|
396
|
+
}];
|
|
397
|
+
});
|
|
430
398
|
}
|
|
431
399
|
|
|
432
400
|
- (void)button:(FLICButton *)button didReceiveButtonUp:(BOOL)queued age:(NSInteger)age {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
401
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
402
|
+
[self emitOnButtonEvent:@{
|
|
403
|
+
@"uuid": button.uuid,
|
|
404
|
+
@"event": @"buttonUp",
|
|
405
|
+
@"queued": @(queued),
|
|
406
|
+
@"age": @(age),
|
|
407
|
+
@"button": [self buttonToDictionary:button]
|
|
408
|
+
}];
|
|
409
|
+
});
|
|
440
410
|
}
|
|
441
411
|
|
|
442
412
|
- (void)button:(FLICButton *)button didReceiveButtonClick:(BOOL)queued age:(NSInteger)age {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
413
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
414
|
+
[self emitOnButtonEvent:@{
|
|
415
|
+
@"uuid": button.uuid,
|
|
416
|
+
@"event": @"click",
|
|
417
|
+
@"queued": @(queued),
|
|
418
|
+
@"age": @(age),
|
|
419
|
+
@"button": [self buttonToDictionary:button]
|
|
420
|
+
}];
|
|
421
|
+
});
|
|
450
422
|
}
|
|
451
423
|
|
|
452
424
|
- (void)button:(FLICButton *)button didReceiveButtonDoubleClick:(BOOL)queued age:(NSInteger)age {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
425
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
426
|
+
[self emitOnButtonEvent:@{
|
|
427
|
+
@"uuid": button.uuid,
|
|
428
|
+
@"event": @"doubleClick",
|
|
429
|
+
@"queued": @(queued),
|
|
430
|
+
@"age": @(age),
|
|
431
|
+
@"button": [self buttonToDictionary:button]
|
|
432
|
+
}];
|
|
433
|
+
});
|
|
460
434
|
}
|
|
461
435
|
|
|
462
436
|
- (void)button:(FLICButton *)button didReceiveButtonHold:(BOOL)queued age:(NSInteger)age {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
437
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
438
|
+
[self emitOnButtonEvent:@{
|
|
439
|
+
@"uuid": button.uuid,
|
|
440
|
+
@"event": @"hold",
|
|
441
|
+
@"queued": @(queued),
|
|
442
|
+
@"age": @(age),
|
|
443
|
+
@"button": [self buttonToDictionary:button]
|
|
444
|
+
}];
|
|
445
|
+
});
|
|
470
446
|
}
|
|
471
447
|
|
|
472
448
|
- (void)button:(FLICButton *)button didUnpairWithError:(NSError * _Nullable)error {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
449
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
450
|
+
[self emitOnButtonEvent:@{
|
|
451
|
+
@"uuid": button.uuid,
|
|
452
|
+
@"event": @"unpaired",
|
|
453
|
+
@"button": [self buttonToDictionary:button]
|
|
454
|
+
}];
|
|
455
|
+
});
|
|
478
456
|
}
|
|
479
457
|
|
|
480
458
|
- (void)button:(FLICButton *)button didUpdateBatteryVoltage:(float)voltage {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
459
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
460
|
+
[self emitOnButtonEvent:@{
|
|
461
|
+
@"uuid": button.uuid,
|
|
462
|
+
@"event": @"batteryUpdate",
|
|
463
|
+
@"voltage": @(voltage),
|
|
464
|
+
@"button": [self buttonToDictionary:button]
|
|
465
|
+
}];
|
|
466
|
+
});
|
|
487
467
|
}
|
|
488
468
|
|
|
489
469
|
- (void)button:(FLICButton *)button didUpdateNickname:(NSString *)nickname {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
470
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
471
|
+
[self emitOnButtonEvent:@{
|
|
472
|
+
@"uuid": button.uuid,
|
|
473
|
+
@"event": @"nicknameUpdate",
|
|
474
|
+
@"nickname": nickname,
|
|
475
|
+
@"button": [self buttonToDictionary:button]
|
|
476
|
+
}];
|
|
477
|
+
});
|
|
496
478
|
}
|
|
497
479
|
|
|
498
480
|
// MARK: - Helper Methods
|
|
499
481
|
|
|
482
|
+
- (FLICButton *)findButtonByUUID:(NSString *)uuid {
|
|
483
|
+
NSArray<FLICButton *> *buttons = [[FLICManager sharedManager] buttons];
|
|
484
|
+
for (FLICButton *button in buttons) {
|
|
485
|
+
if ([button.uuid isEqualToString:uuid]) {
|
|
486
|
+
return button;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return nil;
|
|
490
|
+
}
|
|
491
|
+
|
|
500
492
|
- (NSDictionary *)buttonToDictionary:(FLICButton *)button {
|
|
501
493
|
return @{
|
|
502
494
|
@"uuid": button.uuid,
|
|
@@ -579,18 +571,54 @@
|
|
|
579
571
|
}
|
|
580
572
|
}
|
|
581
573
|
|
|
582
|
-
- (
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
case
|
|
589
|
-
return
|
|
590
|
-
case
|
|
591
|
-
return
|
|
574
|
+
- (NSInteger)mapScanErrorToResultCode:(NSError *)error {
|
|
575
|
+
if (!error) {
|
|
576
|
+
return 0; // SUCCESS
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
switch (error.code) {
|
|
580
|
+
case FLICButtonScannerErrorCodeBluetoothNotActivated:
|
|
581
|
+
return 2; // BLUETOOTH_NOT_ACTIVATED
|
|
582
|
+
case FLICButtonScannerErrorCodeUnknown:
|
|
583
|
+
return 3; // UNKNOWN
|
|
584
|
+
case FLICButtonScannerErrorCodeNoPublicButtonDiscovered:
|
|
585
|
+
return 4; // NO_PUBLIC_BUTTON_DISCOVERED
|
|
586
|
+
case FLICButtonScannerErrorCodeAlreadyConnectedToAnotherDevice:
|
|
587
|
+
return 5; // ALREADY_CONNECTED_TO_ANOTHER_DEVICE
|
|
588
|
+
case FLICButtonScannerErrorCodeConnectionTimeout:
|
|
589
|
+
return 6; // CONNECTION_TIMEOUT
|
|
590
|
+
case FLICButtonScannerErrorCodeInvalidVerifier:
|
|
591
|
+
return 7; // INVALID_VERIFIER
|
|
592
|
+
case FLICButtonScannerErrorCodeBLEPairingFailedPreviousPairingAlreadyExisting:
|
|
593
|
+
return 8; // BLE_PAIRING_FAILED_PREVIOUS_PAIRING_ALREADY_EXISTING
|
|
594
|
+
case FLICButtonScannerErrorCodeBLEPairingFailedUserCanceled:
|
|
595
|
+
return 9; // BLE_PAIRING_FAILED_USER_CANCELED
|
|
596
|
+
case FLICButtonScannerErrorCodeBLEPairingFailedUnknownReason:
|
|
597
|
+
return 10; // BLE_PAIRING_FAILED_UNKNOWN_REASON
|
|
598
|
+
case FLICButtonScannerErrorCodeAppCredentialsDontMatch:
|
|
599
|
+
return 11; // APP_CREDENTIALS_DONT_MATCH
|
|
600
|
+
case FLICButtonScannerErrorCodeUserCanceled:
|
|
601
|
+
return 12; // USER_CANCELED
|
|
602
|
+
case FLICButtonScannerErrorCodeInvalidBluetoothAddress:
|
|
603
|
+
return 13; // INVALID_BLUETOOTH_ADDRESS
|
|
604
|
+
case FLICButtonScannerErrorCodeGenuineCheckFailed:
|
|
605
|
+
return 14; // GENUINE_CHECK_FAILED
|
|
606
|
+
case FLICButtonScannerErrorCodeTooManyApps:
|
|
607
|
+
return 15; // TOO_MANY_APPS
|
|
608
|
+
case FLICButtonScannerErrorCodeCouldNotSetBluetoothNotify:
|
|
609
|
+
return 16; // COULD_NOT_SET_BLUETOOTH_NOTIFY
|
|
610
|
+
case FLICButtonScannerErrorCodeCouldNotDiscoverBluetoothServices:
|
|
611
|
+
return 17; // COULD_NOT_DISCOVER_BLUETOOTH_SERVICES
|
|
612
|
+
case FLICButtonScannerErrorCodeButtonDisconnectedDuringVerification:
|
|
613
|
+
return 18; // BUTTON_DISCONNECTED_DURING_VERIFICATION
|
|
614
|
+
case FLICButtonScannerErrorCodeFailedToEstablish:
|
|
615
|
+
return 19; // FAILED_TO_ESTABLISH
|
|
616
|
+
case FLICButtonScannerErrorCodeConnectionLimitReached:
|
|
617
|
+
return 20; // CONNECTION_LIMIT_REACHED
|
|
618
|
+
case FLICButtonScannerErrorCodeNotInPublicMode:
|
|
619
|
+
return 21; // NOT_IN_PUBLIC_MODE
|
|
592
620
|
default:
|
|
593
|
-
return
|
|
621
|
+
return 3; // UNKNOWN
|
|
594
622
|
}
|
|
595
623
|
}
|
|
596
624
|
|