Skip to content

Commit ca90166

Browse files
stc1988mkellner
authored andcommitted
add typing embedded:io/bluetoothle/peripheral #1558
1 parent 4c3235c commit ca90166

File tree

4 files changed

+117
-19
lines changed

4 files changed

+117
-19
lines changed

examples/manifest_typings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"embedded:io/audio/*": [
3434
"$(TYPINGS)/embedded_io/audio/*"
3535
],
36+
"embedded:io/bluetoothle/*": [
37+
"$(TYPINGS)/embedded_io/ble/*"
38+
],
3639
"embedded:io/socket/*": [
3740
"$(TYPINGS)/embedded_io/socket/*"
3841
],
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
declare module "embedded:io/bluetoothle/_common" {
2+
export interface GATTSecurityOptions {
3+
bond?: boolean,
4+
authenticate?: boolean,
5+
ioCapabilities?: "none" | "display" | "numbers" | "display+numbers" | "display+confirm",
6+
immediate?: boolean
7+
}
8+
export interface GATTSecurityState {
9+
encrypted: boolean,
10+
authenticated: boolean,
11+
bonded: boolean,
12+
keySize: number
13+
}
14+
}
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
declare module "embedded:io/bluetoothle/central" {
2+
import type { Buffer } from "embedded:io/_common";
3+
import type { GATTSecurityOptions, GATTSecurityState } from "embedded:io/bluetoothle/_common";
4+
25
interface Advertisement {
36
address: string;
47
rssi?: number;
@@ -30,25 +33,11 @@ declare module "embedded:io/bluetoothle/central" {
3033
response?: boolean
3134
}
3235

33-
interface GATTSecurityOptions {
34-
bond?: boolean,
35-
authenticate?: boolean,
36-
ioCapabilities?: "none" | "display" | "numbers" | "display+numbers" | "display+confirm",
37-
immediate?: boolean
38-
}
39-
40-
interface GATTSecurityState {
41-
encrypted: boolean,
42-
authenticated: boolean,
43-
bonded: boolean,
44-
keySize: number
45-
}
46-
4736
interface GATTClientOptions {
4837
address: string,
4938
target?: any;
5039
security?: GATTSecurityOptions;
51-
onReady?: (this: GATTClient, ) => void;
40+
onReady?: (this: GATTClient,) => void;
5241
onPasskey?: (this: GATTClient, action: string, data: number | ArrayBuffer | undefined) => void;
5342
onSecured?: (this: GATTClient, state: GATTSecurityState) => void;
5443
onError?: (this: GATTClient, error: Error) => void;
@@ -86,15 +75,15 @@ declare module "embedded:io/bluetoothle/central" {
8675

8776
read(what: GATTClientCharacteristic | GATTClientDescriptor, callback: (error: Error | null, value: ArrayBuffer) => void): void;
8877
read(what: GATTClientCharacteristic | GATTClientDescriptor, options: object, callback: (error: Error | null, value: ArrayBuffer) => void): void;
89-
read() : undefined | GATTClientNotifiedValue;
78+
read(): undefined | GATTClientNotifiedValue;
9079

9180
write(what: GATTClientCharacteristic | GATTClientDescriptor, value: BufferLike, callback?: (error: Error | null) => void): void;
9281
write(what: GATTClientCharacteristic | GATTClientDescriptor, value: BufferLike, options: GATTClientWriteOptions, callback?: (error: Error | null) => void): void;
9382

94-
subscribe(characteristic: GATTClientCharacteristic, callback?: (error?: Error) => void) : void;
95-
unsubscribe(characteristic: GATTClientCharacteristic, callback?: (error?: Error) => void) : void;
83+
subscribe(characteristic: GATTClientCharacteristic, callback?: (error?: Error) => void): void;
84+
unsubscribe(characteristic: GATTClientCharacteristic, callback?: (error?: Error) => void): void;
9685

97-
replyToPasskey(action: string, data?: number | ArrayBuffer) : void;
86+
replyToPasskey(action: string, data?: number | ArrayBuffer): void;
9887

9988
get maximumWrite(): number;
10089

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
declare module "embedded:io/bluetoothle/peripheral" {
2+
import type { Buffer } from "embedded:io/_common";
3+
import type { GATTSecurityOptions, GATTSecurityState } from "embedded:io/bluetoothle/_common";
4+
5+
interface GATTServerOptions {
6+
mtu?: number;
7+
services: GATTServerService[];
8+
security?: GATTSecurityOptions;
9+
onReady?(this: GATTServer): void;
10+
onConnect?(this: GATTServer, connection: GATTServerConnection): void;
11+
onDisconnect?(this: GATTServer, connection: GATTServerConnection): void;
12+
onPasskey?(this: GATTServer, connection: GATTServerConnection, action: "input" | "display" | "compareNumber" | "outOfBand", data?: number | ArrayBuffer): void;
13+
onSecured?(this: GATTServer, connection: GATTServerConnection, state: GATTSecurityState): void;
14+
onWarning?(this: GATTServer, message: string): void;
15+
}
16+
17+
interface GATTServerConnection {
18+
close(): void;
19+
notify(characteristic: GATTServerCharacteristic, value: ArrayBuffer, callback?: (error?: Error) => void): void;
20+
replyToPasskey(action: "input" | "compareNumber" | "outOfBand", value: number | boolean | ArrayBuffer): void;
21+
get maxinumWrite(): number;
22+
}
23+
24+
interface GATTServerService {
25+
uuid: string;
26+
characteristics?: GATTServerCharacteristic[];
27+
}
28+
29+
interface GATTServerCharacteristic {
30+
uuid: string;
31+
properties?: number;
32+
value?: Buffer;
33+
descriptors?: GATTServerDescriptor[];
34+
35+
onRead?(this: GATTServerCharacteristic, connection: GATTServerConnection): Buffer;
36+
onWrite?(this: GATTServerCharacteristic, value: ArrayBuffer, connection: GATTServerConnection): void;
37+
onSubscribe?(this: GATTServerCharacteristic, connection: GATTServerConnection): void;
38+
onUnsubscribe?(cthis: GATTServerCharacteristic, onnection: GATTServerConnection): void;
39+
}
40+
41+
interface GATTServerDescriptor {
42+
uuid: string;
43+
value?: Buffer;
44+
45+
onRead?(connection: GATTServerConnection): Buffer;
46+
onWrite?(value: ArrayBuffer, connection: GATTServerConnection): void;
47+
}
48+
49+
interface GATTServerAdvertisingRecords {
50+
name?: string;
51+
services?: string[];
52+
manufacturerData?: { manufacturer: number, data: Buffer };
53+
flags?: number;
54+
[ADType: number]: Buffer;
55+
}
56+
57+
class GATTServer {
58+
constructor(options: GATTServerOptions);
59+
60+
close?(): void;
61+
addService(service: GATTServerService): void;
62+
deleteService(service: GATTServerService): void;
63+
startAdvertising(scan: GATTServerAdvertisingRecords, response?: GATTServerAdvertisingRecords): void;
64+
stopAdvertising(): void;
65+
66+
static readonly properties: {
67+
authenticatedSignedWrites: 64;
68+
broadcast: 1;
69+
indicate: 32;
70+
notify: 16;
71+
read: 2;
72+
readAuthenticated: 1026;
73+
readEncrypted: 514;
74+
reliableWrite: 128;
75+
subscribeAuthenticated: 65552;
76+
subscribeEncrypted: 32784;
77+
write: 8;
78+
writeAuthenticated: 8200;
79+
writeEncrypted: 4104;
80+
writeWithOutResponse: 4;
81+
};
82+
static readonly advertise: {
83+
limitedDiscoverable: 1;
84+
generalDiscoverable: 2;
85+
bleOnly: 4;
86+
dualModeController: 8;
87+
dualModeHost: 16;
88+
}
89+
}
90+
91+
export { GATTServer };
92+
}

0 commit comments

Comments
 (0)