/
bluetooth_low_energy.clj
832 lines (629 loc) · 41.9 KB
/
bluetooth_low_energy.clj
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
(ns chromex.app.bluetooth-low-energy
"The chrome.bluetoothLowEnergy API is used to communicate with
Bluetooth Smart (Low Energy) devices using the
Generic Attribute Profile (GATT).
* available since Chrome 37
* https://developer.chrome.com/apps/bluetoothLowEnergy"
(:refer-clojure :only [defmacro defn apply declare meta let partial])
(:require [chromex.wrapgen :refer [gen-wrap-helper]]
[chromex.callgen :refer [gen-call-helper gen-tap-all-events-call]]))
(declare api-table)
(declare gen-call)
; -- functions --------------------------------------------------------------------------------------------------------------
(defmacro connect
"Establishes a connection between the application and the device with the given address. A device may be already connected
and its GATT services available without calling connect, however, an app that wants to access GATT services of a device
should call this function to make sure that a connection to the device is maintained. If the device is not connected, all
GATT services of the device will be discovered after a successful call to connect.
|device-address| - The Bluetooth address of the remote device to which a GATT connection should be opened.
|properties| - Connection properties (optional).
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-connect."
([device-address properties] (gen-call :function ::connect &form device-address properties))
([device-address] `(connect ~device-address :omit)))
(defmacro disconnect
"Closes the app's connection to the device with the given address. Note that this will not always destroy the physical link
itself, since there may be other apps with open connections.
|device-address| - The Bluetooth address of the remote device.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-disconnect."
([device-address] (gen-call :function ::disconnect &form device-address)))
(defmacro get-service
"Get the GATT service with the given instance ID.
|service-id| - The instance ID of the requested GATT service.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getService."
([service-id] (gen-call :function ::get-service &form service-id)))
(defmacro create-service
"Create a locally hosted GATT service. This service can be registered to be available on a local GATT server. This function
is only available if the app has both the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The
peripheral permission may not be available to all apps.
|service| - The service to create.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [service-id] where:
|service-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-serviceId.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-createService."
([service] (gen-call :function ::create-service &form service)))
(defmacro get-services
"Get all the GATT services that were discovered on the remote device with the given device address.Note: If service
discovery is not yet complete on the device, this API will return a subset (possibly empty) of services. A work around is
to add a time based delay and/or call repeatedly until the expected number of services is returned.
|device-address| - The Bluetooth address of the remote device whose GATT services should be returned.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getServices."
([device-address] (gen-call :function ::get-services &form device-address)))
(defmacro get-characteristic
"Get the GATT characteristic with the given instance ID that belongs to the given GATT service, if the characteristic
exists.
|characteristic-id| - The instance ID of the requested GATT characteristic.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getCharacteristic."
([characteristic-id] (gen-call :function ::get-characteristic &form characteristic-id)))
(defmacro create-characteristic
"Create a locally hosted GATT characteristic. This characteristic must be hosted under a valid service. If the service ID is
not valid, the lastError will be set. This function is only available if the app has both the bluetooth:low_energy and the
bluetooth:peripheral permissions set to true. The peripheral permission may not be available to all apps.
|characteristic| - The characteristic to create.
|service-id| - ID of the service to create this characteristic for.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [characteristic-id] where:
|characteristic-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-characteristicId.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-createCharacteristic."
([characteristic service-id] (gen-call :function ::create-characteristic &form characteristic service-id)))
(defmacro get-characteristics
"Get a list of all discovered GATT characteristics that belong to the given service.
|service-id| - The instance ID of the GATT service whose characteristics should be returned.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getCharacteristics."
([service-id] (gen-call :function ::get-characteristics &form service-id)))
(defmacro get-included-services
"Get a list of GATT services that are included by the given service.
|service-id| - The instance ID of the GATT service whose included services should be returned.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getIncludedServices."
([service-id] (gen-call :function ::get-included-services &form service-id)))
(defmacro get-descriptor
"Get the GATT characteristic descriptor with the given instance ID.
|descriptor-id| - The instance ID of the requested GATT characteristic descriptor.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getDescriptor."
([descriptor-id] (gen-call :function ::get-descriptor &form descriptor-id)))
(defmacro create-descriptor
"Create a locally hosted GATT descriptor. This descriptor must be hosted under a valid characteristic. If the characteristic
ID is not valid, the lastError will be set. This function is only available if the app has both the bluetooth:low_energy
and the bluetooth:peripheral permissions set to true. The peripheral permission may not be available to all apps.
|descriptor| - The descriptor to create.
|characteristic-id| - ID of the characteristic to create this descriptor for.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [descriptor-id] where:
|descriptor-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-descriptorId.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-createDescriptor."
([descriptor characteristic-id] (gen-call :function ::create-descriptor &form descriptor characteristic-id)))
(defmacro get-descriptors
"Get a list of GATT characteristic descriptors that belong to the given characteristic.
|characteristic-id| - The instance ID of the GATT characteristic whose descriptors should be returned.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-getDescriptors."
([characteristic-id] (gen-call :function ::get-descriptors &form characteristic-id)))
(defmacro read-characteristic-value
"Retrieve the value of a specified characteristic from a remote peripheral.
|characteristic-id| - The instance ID of the GATT characteristic whose value should be read from the remote device.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-readCharacteristicValue."
([characteristic-id] (gen-call :function ::read-characteristic-value &form characteristic-id)))
(defmacro write-characteristic-value
"Write the value of a specified characteristic from a remote peripheral.
|characteristic-id| - The instance ID of the GATT characteristic whose value should be written to.
|value| - The value that should be sent to the remote characteristic as part of the write request.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-writeCharacteristicValue."
([characteristic-id value] (gen-call :function ::write-characteristic-value &form characteristic-id value)))
(defmacro start-characteristic-notifications
"Enable value notifications/indications from the specified characteristic. Once enabled, an application can listen to
notifications using the 'onCharacteristicValueChanged' event.
|characteristic-id| - The instance ID of the GATT characteristic that notifications should be enabled on.
|properties| - Notification session properties (optional).
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-startCharacteristicNotifications."
([characteristic-id properties] (gen-call :function ::start-characteristic-notifications &form characteristic-id properties))
([characteristic-id] `(start-characteristic-notifications ~characteristic-id :omit)))
(defmacro stop-characteristic-notifications
"Disable value notifications/indications from the specified characteristic. After a successful call, the application will
stop receiving notifications/indications from this characteristic.
|characteristic-id| - The instance ID of the GATT characteristic on which this app's notification session should be
stopped.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-stopCharacteristicNotifications."
([characteristic-id] (gen-call :function ::stop-characteristic-notifications &form characteristic-id)))
(defmacro notify-characteristic-value-changed
"Notify a remote device of a new value for a characteristic. If the shouldIndicate flag in the notification object is true,
an indication will be sent instead of a notification. Note, the characteristic needs to correctly set the 'notify' or
'indicate' property during creation for this call to succeed. This function is only available if the app has both the
bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be available
to all apps.
|characteristic-id| - The characteristic to send the notication for.
|notification| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-notifyCharacteristicValueChanged-notification.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-notifyCharacteristicValueChanged."
([characteristic-id notification] (gen-call :function ::notify-characteristic-value-changed &form characteristic-id notification)))
(defmacro read-descriptor-value
"Retrieve the value of a specified characteristic descriptor from a remote peripheral.
|descriptor-id| - The instance ID of the GATT characteristic descriptor whose value should be read from the remote
device.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [result] where:
|result| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-result.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-readDescriptorValue."
([descriptor-id] (gen-call :function ::read-descriptor-value &form descriptor-id)))
(defmacro write-descriptor-value
"Write the value of a specified characteristic descriptor from a remote peripheral.
|descriptor-id| - The instance ID of the GATT characteristic descriptor whose value should be written to.
|value| - The value that should be sent to the remote descriptor as part of the write request.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-writeDescriptorValue."
([descriptor-id value] (gen-call :function ::write-descriptor-value &form descriptor-id value)))
(defmacro register-service
"Register the given service with the local GATT server. If the service ID is invalid, the lastError will be set. This
function is only available if the app has both the bluetooth:low_energy and the bluetooth:peripheral permissions set to
true. The peripheral permission may not be available to all apps.
|service-id| - Unique ID of a created service.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-registerService."
([service-id] (gen-call :function ::register-service &form service-id)))
(defmacro unregister-service
"Unregister the given service with the local GATT server. If the service ID is invalid, the lastError will be set. This
function is only available if the app has both the bluetooth:low_energy and the bluetooth:peripheral permissions set to
true. The peripheral permission may not be available to all apps.
|service-id| - Unique ID of a current registered service.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-unregisterService."
([service-id] (gen-call :function ::unregister-service &form service-id)))
(defmacro remove-service
"Remove the specified service, unregistering it if it was registered. If the service ID is invalid, the lastError will be
set. This function is only available if the app has both the bluetooth:low_energy and the bluetooth:peripheral permissions
set to true. The peripheral permission may not be available to all apps.
|service-id| - Unique ID of a current registered service.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-removeService."
([service-id] (gen-call :function ::remove-service &form service-id)))
(defmacro register-advertisement
"Create an advertisement and register it for advertising. To call this function, the app must have the bluetooth:low_energy
and bluetooth:peripheral permissions set to true. Additionally this API is only available to auto launched apps in Kiosk
Mode or by setting the '--enable-ble-advertising-in-apps' command-line switch. See
https://developer.chrome.com/apps/manifest/bluetooth Note: On some hardware, central and peripheral modes at the same time
is supported but on hardware that doesn't support this, making this call will switch the device to peripheral mode. In the
case of hardware which does not support both central and peripheral mode, attempting to use the device in both modes will
lead to undefined behavior or prevent other central-role applications from behaving correctly (including the discovery of
Bluetooth Low Energy devices).
|advertisement| - The advertisement to advertise.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [advertisement-id] where:
|advertisement-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-callback-advertisementId.
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-registerAdvertisement."
([advertisement] (gen-call :function ::register-advertisement &form advertisement)))
(defmacro unregister-advertisement
"Unregisters an advertisement and stops its advertising. If the advertisement fails to unregister the only way to stop
advertising might be to restart the device.
|advertisement-id| - Id of the advertisement to unregister.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-unregisterAdvertisement."
([advertisement-id] (gen-call :function ::unregister-advertisement &form advertisement-id)))
(defmacro reset-advertising
"Resets advertising on the current device. It will unregister and stop all existing advertisements.
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-resetAdvertising."
([] (gen-call :function ::reset-advertising &form)))
(defmacro set-advertising-interval
"Set's the interval betweeen two consecutive advertisements. Note: This is a best effort. The actual interval may vary
non-trivially from the requested intervals. On some hardware, there is a minimum interval of 100ms. The minimum and maximum
values cannot exceed the the range allowed by the Bluetooth 4.2 specification.
|min-interval| - Minimum interval between advertisments (in milliseconds). This cannot be lower than 20ms (as per the
spec).
|max-interval| - Maximum interval between advertisments (in milliseconds). This cannot be more than 10240ms (as per the
spec).
This function returns a core.async channel of type `promise-chan` which eventually receives a result value.
Signature of the result value put on the channel is [].
In case of an error the channel closes without receiving any value and relevant error object can be obtained via
chromex.error/get-last-error.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-setAdvertisingInterval."
([min-interval max-interval] (gen-call :function ::set-advertising-interval &form min-interval max-interval)))
(defmacro send-request-response
"Sends a response for a characteristic or descriptor read/write request. This function is only available if the app has both
the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be
available to all apps.
|response| - The response to the request.
https://developer.chrome.com/apps/bluetoothLowEnergy#method-sendRequestResponse."
([response] (gen-call :function ::send-request-response &form response)))
; -- events -----------------------------------------------------------------------------------------------------------------
;
; docs: https://github.com/binaryage/chromex/#tapping-events
(defmacro tap-on-service-added-events
"Fired whan a new GATT service has been discovered on a remote device.
Events will be put on the |channel| with signature [::on-service-added [service]] where:
|service| - The GATT service that was added.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onServiceAdded."
([channel & args] (apply gen-call :event ::on-service-added &form channel args)))
(defmacro tap-on-service-changed-events
"Fired when the state of a remote GATT service changes. This involves any characteristics and/or descriptors that get added
or removed from the service, as well as 'ServiceChanged' notifications from the remote device.
Events will be put on the |channel| with signature [::on-service-changed [service]] where:
|service| - The GATT service whose state has changed.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onServiceChanged."
([channel & args] (apply gen-call :event ::on-service-changed &form channel args)))
(defmacro tap-on-service-removed-events
"Fired when a GATT service that was previously discovered on a remote device has been removed.
Events will be put on the |channel| with signature [::on-service-removed [service]] where:
|service| - The GATT service that was removed.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onServiceRemoved."
([channel & args] (apply gen-call :event ::on-service-removed &form channel args)))
(defmacro tap-on-characteristic-value-changed-events
"Fired when the value of a remote GATT characteristic changes, either as a result of a read request, or a value change
notification/indication This event will only be sent if the app has enabled notifications by calling
'startCharacteristicNotifications'.
Events will be put on the |channel| with signature [::on-characteristic-value-changed [characteristic]] where:
|characteristic| - The GATT characteristic whose value has changed.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onCharacteristicValueChanged."
([channel & args] (apply gen-call :event ::on-characteristic-value-changed &form channel args)))
(defmacro tap-on-descriptor-value-changed-events
"Fired when the value of a remote GATT characteristic descriptor changes, usually as a result of a read request. This event
exists mostly for convenience and will always be sent after a successful call to 'readDescriptorValue'.
Events will be put on the |channel| with signature [::on-descriptor-value-changed [descriptor]] where:
|descriptor| - The GATT characteristic descriptor whose value has changed.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onDescriptorValueChanged."
([channel & args] (apply gen-call :event ::on-descriptor-value-changed &form channel args)))
(defmacro tap-on-characteristic-read-request-events
"Fired when a connected central device requests to read the value of a characteristic registered on the local GATT server.
Not responding to this request for a long time may lead to a disconnection. This event is only available if the app has
both the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be
available to all apps.
Events will be put on the |channel| with signature [::on-characteristic-read-request [request characteristic-id]] where:
|request| - Request data for this request.
|characteristic-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-onCharacteristicReadRequest-characteristicId.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onCharacteristicReadRequest."
([channel & args] (apply gen-call :event ::on-characteristic-read-request &form channel args)))
(defmacro tap-on-characteristic-write-request-events
"Fired when a connected central device requests to write the value of a characteristic registered on the local GATT server.
Not responding to this request for a long time may lead to a disconnection. This event is only available if the app has
both the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be
available to all apps.
Events will be put on the |channel| with signature [::on-characteristic-write-request [request characteristic-id]] where:
|request| - Request data for this request.
|characteristic-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-onCharacteristicWriteRequest-characteristicId.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onCharacteristicWriteRequest."
([channel & args] (apply gen-call :event ::on-characteristic-write-request &form channel args)))
(defmacro tap-on-descriptor-read-request-events
"Fired when a connected central device requests to read the value of a descriptor registered on the local GATT server. Not
responding to this request for a long time may lead to a disconnection. This event is only available if the app has both
the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be
available to all apps.
Events will be put on the |channel| with signature [::on-descriptor-read-request [request descriptor-id]] where:
|request| - Request data for this request.
|descriptor-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-onDescriptorReadRequest-descriptorId.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onDescriptorReadRequest."
([channel & args] (apply gen-call :event ::on-descriptor-read-request &form channel args)))
(defmacro tap-on-descriptor-write-request-events
"Fired when a connected central device requests to write the value of a descriptor registered on the local GATT server. Not
responding to this request for a long time may lead to a disconnection. This event is only available if the app has both
the bluetooth:low_energy and the bluetooth:peripheral permissions set to true. The peripheral permission may not be
available to all apps.
Events will be put on the |channel| with signature [::on-descriptor-write-request [request descriptor-id]] where:
|request| - Request data for this request.
|descriptor-id| - https://developer.chrome.com/apps/bluetoothLowEnergy#property-onDescriptorWriteRequest-descriptorId.
Note: |args| will be passed as additional parameters into Chrome event's .addListener call.
https://developer.chrome.com/apps/bluetoothLowEnergy#event-onDescriptorWriteRequest."
([channel & args] (apply gen-call :event ::on-descriptor-write-request &form channel args)))
; -- convenience ------------------------------------------------------------------------------------------------------------
(defmacro tap-all-events
"Taps all valid non-deprecated events in chromex.app.bluetooth-low-energy namespace."
[chan]
(gen-tap-all-events-call api-table (meta &form) chan))
; ---------------------------------------------------------------------------------------------------------------------------
; -- API TABLE --------------------------------------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------------------------------------------------
(def api-table
{:namespace "chrome.bluetoothLowEnergy",
:since "37",
:functions
[{:id ::connect,
:name "connect",
:callback? true,
:params
[{:name "device-address", :type "string"}
{:name "properties", :optional? true, :type "object"}
{:name "callback", :type :callback}]}
{:id ::disconnect,
:name "disconnect",
:callback? true,
:params [{:name "device-address", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::get-service,
:name "getService",
:callback? true,
:params
[{:name "service-id", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "result", :type "bluetoothLowEnergy.Service"}]}}]}
{:id ::create-service,
:name "createService",
:since "52",
:callback? true,
:params
[{:name "service", :type "bluetoothLowEnergy.Service"}
{:name "callback", :type :callback, :callback {:params [{:name "service-id", :type "string"}]}}]}
{:id ::get-services,
:name "getServices",
:callback? true,
:params
[{:name "device-address", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "[array-of-bluetoothLowEnergy.Services]"}]}}]}
{:id ::get-characteristic,
:name "getCharacteristic",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "bluetoothLowEnergy.Characteristic"}]}}]}
{:id ::create-characteristic,
:name "createCharacteristic",
:since "52",
:callback? true,
:params
[{:name "characteristic", :type "bluetoothLowEnergy.Characteristic"}
{:name "service-id", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "characteristic-id", :type "string"}]}}]}
{:id ::get-characteristics,
:name "getCharacteristics",
:callback? true,
:params
[{:name "service-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "[array-of-bluetoothLowEnergy.Characteristics]"}]}}]}
{:id ::get-included-services,
:name "getIncludedServices",
:callback? true,
:params
[{:name "service-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "[array-of-bluetoothLowEnergy.Services]"}]}}]}
{:id ::get-descriptor,
:name "getDescriptor",
:callback? true,
:params
[{:name "descriptor-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "bluetoothLowEnergy.Descriptor"}]}}]}
{:id ::create-descriptor,
:name "createDescriptor",
:since "52",
:callback? true,
:params
[{:name "descriptor", :type "bluetoothLowEnergy.Descriptor"}
{:name "characteristic-id", :type "string"}
{:name "callback", :type :callback, :callback {:params [{:name "descriptor-id", :type "string"}]}}]}
{:id ::get-descriptors,
:name "getDescriptors",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "[array-of-bluetoothLowEnergy.Descriptors]"}]}}]}
{:id ::read-characteristic-value,
:name "readCharacteristicValue",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "bluetoothLowEnergy.Characteristic"}]}}]}
{:id ::write-characteristic-value,
:name "writeCharacteristicValue",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "value", :type "ArrayBuffer"}
{:name "callback", :type :callback}]}
{:id ::start-characteristic-notifications,
:name "startCharacteristicNotifications",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "properties", :optional? true, :type "object"}
{:name "callback", :type :callback}]}
{:id ::stop-characteristic-notifications,
:name "stopCharacteristicNotifications",
:callback? true,
:params [{:name "characteristic-id", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::notify-characteristic-value-changed,
:name "notifyCharacteristicValueChanged",
:since "52",
:callback? true,
:params
[{:name "characteristic-id", :type "string"}
{:name "notification", :type "object"}
{:name "callback", :type :callback}]}
{:id ::read-descriptor-value,
:name "readDescriptorValue",
:callback? true,
:params
[{:name "descriptor-id", :type "string"}
{:name "callback",
:type :callback,
:callback {:params [{:name "result", :type "bluetoothLowEnergy.Descriptor"}]}}]}
{:id ::write-descriptor-value,
:name "writeDescriptorValue",
:callback? true,
:params
[{:name "descriptor-id", :type "string"}
{:name "value", :type "ArrayBuffer"}
{:name "callback", :type :callback}]}
{:id ::register-service,
:name "registerService",
:since "52",
:callback? true,
:params [{:name "service-id", :type "string"} {:name "callback", :type :callback}]}
{:id ::unregister-service,
:name "unregisterService",
:since "52",
:callback? true,
:params [{:name "service-id", :type "string"} {:name "callback", :type :callback}]}
{:id ::remove-service,
:name "removeService",
:since "52",
:callback? true,
:params [{:name "service-id", :type "string"} {:name "callback", :optional? true, :type :callback}]}
{:id ::register-advertisement,
:name "registerAdvertisement",
:since "47",
:callback? true,
:params
[{:name "advertisement", :type "object"}
{:name "callback", :type :callback, :callback {:params [{:name "advertisement-id", :type "integer"}]}}]}
{:id ::unregister-advertisement,
:name "unregisterAdvertisement",
:since "47",
:callback? true,
:params [{:name "advertisement-id", :type "integer"} {:name "callback", :type :callback}]}
{:id ::reset-advertising,
:name "resetAdvertising",
:since "61",
:callback? true,
:params [{:name "callback", :type :callback}]}
{:id ::set-advertising-interval,
:name "setAdvertisingInterval",
:since "55",
:callback? true,
:params
[{:name "min-interval", :type "integer"}
{:name "max-interval", :type "integer"}
{:name "callback", :type :callback}]}
{:id ::send-request-response,
:name "sendRequestResponse",
:since "52",
:params [{:name "response", :type "object"}]}],
:events
[{:id ::on-service-added, :name "onServiceAdded", :params [{:name "service", :type "bluetoothLowEnergy.Service"}]}
{:id ::on-service-changed,
:name "onServiceChanged",
:params [{:name "service", :type "bluetoothLowEnergy.Service"}]}
{:id ::on-service-removed,
:name "onServiceRemoved",
:params [{:name "service", :type "bluetoothLowEnergy.Service"}]}
{:id ::on-characteristic-value-changed,
:name "onCharacteristicValueChanged",
:params [{:name "characteristic", :type "bluetoothLowEnergy.Characteristic"}]}
{:id ::on-descriptor-value-changed,
:name "onDescriptorValueChanged",
:params [{:name "descriptor", :type "bluetoothLowEnergy.Descriptor"}]}
{:id ::on-characteristic-read-request,
:name "onCharacteristicReadRequest",
:since "52",
:params [{:name "request", :type "bluetoothLowEnergy.Request"} {:name "characteristic-id", :type "string"}]}
{:id ::on-characteristic-write-request,
:name "onCharacteristicWriteRequest",
:since "52",
:params [{:name "request", :type "bluetoothLowEnergy.Request"} {:name "characteristic-id", :type "string"}]}
{:id ::on-descriptor-read-request,
:name "onDescriptorReadRequest",
:since "52",
:params [{:name "request", :type "bluetoothLowEnergy.Request"} {:name "descriptor-id", :type "string"}]}
{:id ::on-descriptor-write-request,
:name "onDescriptorWriteRequest",
:since "52",
:params [{:name "request", :type "bluetoothLowEnergy.Request"} {:name "descriptor-id", :type "string"}]}]})
; -- helpers ----------------------------------------------------------------------------------------------------------------
; code generation for native API wrapper
(defmacro gen-wrap [kind item-id config & args]
(apply gen-wrap-helper api-table kind item-id config args))
; code generation for API call-site
(def gen-call (partial gen-call-helper api-table))