@microbit/microbit-connection 0.9.0-apps.alpha.18 → 0.9.0-apps.alpha.19
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/build/cjs/bluetooth/connection.d.ts +242 -1
- package/build/cjs/bluetooth/connection.js +52 -4
- package/build/cjs/bluetooth/connection.js.map +1 -1
- package/build/cjs/bluetooth/device-wrapper.d.ts +6 -0
- package/build/cjs/bluetooth/device-wrapper.js +27 -0
- package/build/cjs/bluetooth/device-wrapper.js.map +1 -1
- package/build/cjs/bluetooth/flashing/nordic-dfu.js +14 -3
- package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -1
- package/build/cjs/bluetooth/services/event-service.d.ts +48 -0
- package/build/cjs/bluetooth/services/event-service.js +273 -0
- package/build/cjs/bluetooth/services/event-service.js.map +1 -0
- package/build/cjs/bluetooth/services/event-service.test.d.ts +1 -0
- package/build/cjs/bluetooth/services/event-service.test.js +252 -0
- package/build/cjs/bluetooth/services/event-service.test.js.map +1 -0
- package/build/cjs/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/cjs/bluetooth/services/io-pin-service.js +173 -0
- package/build/cjs/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/cjs/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/cjs/bluetooth/services/temperature-service.js +80 -0
- package/build/cjs/bluetooth/services/temperature-service.js.map +1 -0
- package/build/cjs/index.d.ts +4 -3
- package/build/cjs/index.js +4 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/microbit-events.d.ts +67 -0
- package/build/cjs/microbit-events.js +55 -0
- package/build/cjs/microbit-events.js.map +1 -0
- package/build/cjs/service-events.d.ts +49 -1
- package/build/cjs/service-events.js.map +1 -1
- package/build/esm/bluetooth/connection.d.ts +242 -1
- package/build/esm/bluetooth/connection.js +53 -5
- package/build/esm/bluetooth/connection.js.map +1 -1
- package/build/esm/bluetooth/device-wrapper.d.ts +6 -0
- package/build/esm/bluetooth/device-wrapper.js +27 -0
- package/build/esm/bluetooth/device-wrapper.js.map +1 -1
- package/build/esm/bluetooth/flashing/nordic-dfu.js +14 -3
- package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -1
- package/build/esm/bluetooth/services/event-service.d.ts +48 -0
- package/build/esm/bluetooth/services/event-service.js +269 -0
- package/build/esm/bluetooth/services/event-service.js.map +1 -0
- package/build/esm/bluetooth/services/event-service.test.d.ts +1 -0
- package/build/esm/bluetooth/services/event-service.test.js +250 -0
- package/build/esm/bluetooth/services/event-service.test.js.map +1 -0
- package/build/esm/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/esm/bluetooth/services/io-pin-service.js +169 -0
- package/build/esm/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/esm/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/esm/bluetooth/services/temperature-service.js +76 -0
- package/build/esm/bluetooth/services/temperature-service.js.map +1 -0
- package/build/esm/index.d.ts +4 -3
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/microbit-events.d.ts +67 -0
- package/build/esm/microbit-events.js +52 -0
- package/build/esm/microbit-events.js.map +1 -0
- package/build/esm/service-events.d.ts +49 -1
- package/build/esm/service-events.js.map +1 -1
- package/package.json +1 -1
package/build/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProgressStage = exports.assertConnected = exports.FlashDataError = exports.DeviceError = exports.ConnectionStatus = exports.ButtonState = void 0;
|
|
3
|
+
exports.ProgressStage = exports.assertConnected = exports.GestureEvent = exports.FlashDataError = exports.DeviceError = exports.ConnectionStatus = exports.ButtonState = exports.ButtonAction = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @module @microbit/microbit-connection
|
|
6
6
|
*/
|
|
@@ -12,4 +12,7 @@ Object.defineProperty(exports, "ProgressStage", { enumerable: true, get: functio
|
|
|
12
12
|
Object.defineProperty(exports, "assertConnected", { enumerable: true, get: function () { return device_js_1.assertConnected; } });
|
|
13
13
|
const service_events_js_1 = require("./service-events.js");
|
|
14
14
|
Object.defineProperty(exports, "ButtonState", { enumerable: true, get: function () { return service_events_js_1.ButtonState; } });
|
|
15
|
+
const microbit_events_js_1 = require("./microbit-events.js");
|
|
16
|
+
Object.defineProperty(exports, "ButtonAction", { enumerable: true, get: function () { return microbit_events_js_1.ButtonAction; } });
|
|
17
|
+
Object.defineProperty(exports, "GestureEvent", { enumerable: true, get: function () { return microbit_events_js_1.GestureEvent; } });
|
|
15
18
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2CAgBqB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2CAgBqB;AAsBnB,iGAjCA,4BAAgB,OAiCA;AAChB,4FA/BA,uBAAW,OA+BA;AACX,+FA9BA,0BAAc,OA8BA;AAGd,8FA7BA,yBAAa,OA6BA;AADb,gGA3BA,2BAAe,OA2BA;AAxBjB,2DAc6B;AAK3B,4FAdA,+BAAW,OAcA;AAJb,6DAAkE;AAGhE,6FAHO,iCAAY,OAGP;AAKZ,6FARqB,iCAAY,OAQrB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Well-known micro:bit message bus event source IDs and values.
|
|
3
|
+
*
|
|
4
|
+
* Source IDs differ between V1 (DAL) and V2 (CODAL). Event values are
|
|
5
|
+
* identical across versions (V2 adds TwoG to gesture values).
|
|
6
|
+
*
|
|
7
|
+
* @see https://lancaster-university.github.io/microbit-docs/
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Event source IDs for micro:bit V1 (DAL).
|
|
11
|
+
*/
|
|
12
|
+
export declare const V1Source: {
|
|
13
|
+
readonly ButtonA: 1;
|
|
14
|
+
readonly ButtonB: 2;
|
|
15
|
+
readonly ButtonAB: 26;
|
|
16
|
+
readonly Gesture: 27;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Event source IDs for micro:bit V2 (CODAL).
|
|
20
|
+
*/
|
|
21
|
+
export declare const V2Source: {
|
|
22
|
+
readonly ButtonA: 1;
|
|
23
|
+
readonly ButtonB: 2;
|
|
24
|
+
readonly ButtonAB: 3;
|
|
25
|
+
readonly Gesture: 13;
|
|
26
|
+
readonly Logo: 121;
|
|
27
|
+
};
|
|
28
|
+
export declare const EventSource: {
|
|
29
|
+
readonly v1: {
|
|
30
|
+
readonly ButtonA: 1;
|
|
31
|
+
readonly ButtonB: 2;
|
|
32
|
+
readonly ButtonAB: 26;
|
|
33
|
+
readonly Gesture: 27;
|
|
34
|
+
};
|
|
35
|
+
readonly v2: {
|
|
36
|
+
readonly ButtonA: 1;
|
|
37
|
+
readonly ButtonB: 2;
|
|
38
|
+
readonly ButtonAB: 3;
|
|
39
|
+
readonly Gesture: 13;
|
|
40
|
+
readonly Logo: 121;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare const GestureEvent: {
|
|
44
|
+
readonly TiltUp: 1;
|
|
45
|
+
readonly TiltDown: 2;
|
|
46
|
+
readonly TiltLeft: 3;
|
|
47
|
+
readonly TiltRight: 4;
|
|
48
|
+
readonly FaceUp: 5;
|
|
49
|
+
readonly FaceDown: 6;
|
|
50
|
+
readonly Freefall: 7;
|
|
51
|
+
readonly Acceleration3g: 8;
|
|
52
|
+
readonly Acceleration6g: 9;
|
|
53
|
+
readonly Acceleration8g: 10;
|
|
54
|
+
readonly Shake: 11;
|
|
55
|
+
/** V2 only. */
|
|
56
|
+
readonly Acceleration2g: 12;
|
|
57
|
+
};
|
|
58
|
+
export type GestureEvent = (typeof GestureEvent)[keyof typeof GestureEvent];
|
|
59
|
+
export declare const ButtonAction: {
|
|
60
|
+
readonly Down: 1;
|
|
61
|
+
readonly Up: 2;
|
|
62
|
+
readonly Click: 3;
|
|
63
|
+
readonly LongClick: 4;
|
|
64
|
+
readonly Hold: 5;
|
|
65
|
+
readonly DoubleClick: 6;
|
|
66
|
+
};
|
|
67
|
+
export type ButtonAction = (typeof ButtonAction)[keyof typeof ButtonAction];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Well-known micro:bit message bus event source IDs and values.
|
|
4
|
+
*
|
|
5
|
+
* Source IDs differ between V1 (DAL) and V2 (CODAL). Event values are
|
|
6
|
+
* identical across versions (V2 adds TwoG to gesture values).
|
|
7
|
+
*
|
|
8
|
+
* @see https://lancaster-university.github.io/microbit-docs/
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ButtonAction = exports.GestureEvent = exports.EventSource = exports.V2Source = exports.V1Source = void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Event source IDs for micro:bit V1 (DAL).
|
|
14
|
+
*/
|
|
15
|
+
exports.V1Source = {
|
|
16
|
+
ButtonA: 1,
|
|
17
|
+
ButtonB: 2,
|
|
18
|
+
ButtonAB: 26,
|
|
19
|
+
Gesture: 27,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Event source IDs for micro:bit V2 (CODAL).
|
|
23
|
+
*/
|
|
24
|
+
exports.V2Source = {
|
|
25
|
+
ButtonA: 1,
|
|
26
|
+
ButtonB: 2,
|
|
27
|
+
ButtonAB: 3,
|
|
28
|
+
Gesture: 13,
|
|
29
|
+
Logo: 121,
|
|
30
|
+
};
|
|
31
|
+
exports.EventSource = { v1: exports.V1Source, v2: exports.V2Source };
|
|
32
|
+
exports.GestureEvent = {
|
|
33
|
+
TiltUp: 1,
|
|
34
|
+
TiltDown: 2,
|
|
35
|
+
TiltLeft: 3,
|
|
36
|
+
TiltRight: 4,
|
|
37
|
+
FaceUp: 5,
|
|
38
|
+
FaceDown: 6,
|
|
39
|
+
Freefall: 7,
|
|
40
|
+
Acceleration3g: 8,
|
|
41
|
+
Acceleration6g: 9,
|
|
42
|
+
Acceleration8g: 10,
|
|
43
|
+
Shake: 11,
|
|
44
|
+
/** V2 only. */
|
|
45
|
+
Acceleration2g: 12,
|
|
46
|
+
};
|
|
47
|
+
exports.ButtonAction = {
|
|
48
|
+
Down: 1,
|
|
49
|
+
Up: 2,
|
|
50
|
+
Click: 3,
|
|
51
|
+
LongClick: 4,
|
|
52
|
+
Hold: 5,
|
|
53
|
+
DoubleClick: 6,
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=microbit-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microbit-events.js","sourceRoot":"","sources":["../../src/microbit-events.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,EAAE;CACH,CAAC;AAEX;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,GAAG;CACD,CAAC;AAEE,QAAA,WAAW,GAAG,EAAE,EAAE,EAAE,gBAAQ,EAAE,EAAE,EAAE,gBAAQ,EAAW,CAAC;AAEtD,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,EAAE;IAClB,KAAK,EAAE,EAAE;IACT,eAAe;IACf,cAAc,EAAE,EAAE;CACV,CAAC;AAGE,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,CAAC;IACP,EAAE,EAAE,CAAC;IACL,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,CAAC;IACP,WAAW,EAAE,CAAC;CACN,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DeviceConnectionEventMap } from "./device.js";
|
|
2
|
+
import type { GestureEvent, ButtonAction } from "./microbit-events.js";
|
|
2
3
|
export interface AccelerometerData {
|
|
3
4
|
x: number;
|
|
4
5
|
y: number;
|
|
@@ -10,7 +11,7 @@ export declare const ButtonState: {
|
|
|
10
11
|
readonly LongPress: 2;
|
|
11
12
|
};
|
|
12
13
|
export type ButtonState = (typeof ButtonState)[keyof typeof ButtonState];
|
|
13
|
-
export type
|
|
14
|
+
export type ButtonActionType = "buttonachanged" | "buttonbchanged";
|
|
14
15
|
export interface ButtonData {
|
|
15
16
|
button: "A" | "B";
|
|
16
17
|
state: ButtonState;
|
|
@@ -26,6 +27,45 @@ export interface MagnetometerData {
|
|
|
26
27
|
y: number;
|
|
27
28
|
z: number;
|
|
28
29
|
}
|
|
30
|
+
export interface TemperatureData {
|
|
31
|
+
celsius: number;
|
|
32
|
+
}
|
|
33
|
+
export interface PinValue {
|
|
34
|
+
/** Pin number (0-18). */
|
|
35
|
+
pin: number;
|
|
36
|
+
/**
|
|
37
|
+
* Pin value. For digital pins: 0 or 1.
|
|
38
|
+
* For analog pins: 0-255 (the 10-bit analog reading scaled to 8 bits).
|
|
39
|
+
*/
|
|
40
|
+
value: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Data from a `pinchanged` event.
|
|
44
|
+
*
|
|
45
|
+
* Contains only the input pins whose values changed since the last
|
|
46
|
+
* notification, up to a firmware limit of 10 pins per event
|
|
47
|
+
* (lowest-numbered first). Use {@link MicrobitBluetoothConnection.readPins}
|
|
48
|
+
* to read all input pins on demand.
|
|
49
|
+
*/
|
|
50
|
+
export interface PinData {
|
|
51
|
+
data: PinValue[];
|
|
52
|
+
}
|
|
53
|
+
export interface GestureData {
|
|
54
|
+
gesture: GestureEvent;
|
|
55
|
+
}
|
|
56
|
+
export interface ButtonActionData {
|
|
57
|
+
button: "A" | "B" | "AB" | "Logo";
|
|
58
|
+
action: ButtonAction;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A raw event from the micro:bit's message bus, received via the
|
|
62
|
+
* BLE Event Service. Use {@link MicrobitBluetoothConnection.subscribeToEvent}
|
|
63
|
+
* to register which events the micro:bit should forward.
|
|
64
|
+
*/
|
|
65
|
+
export interface MicrobitEventData {
|
|
66
|
+
source: number;
|
|
67
|
+
value: number;
|
|
68
|
+
}
|
|
29
69
|
export interface UartData {
|
|
30
70
|
value: Uint8Array;
|
|
31
71
|
}
|
|
@@ -38,6 +78,14 @@ export interface ServiceConnectionEventMap {
|
|
|
38
78
|
buttonachanged: ButtonData;
|
|
39
79
|
buttonbchanged: ButtonData;
|
|
40
80
|
magnetometerdatachanged: MagnetometerData;
|
|
81
|
+
temperaturechanged: TemperatureData;
|
|
82
|
+
pinchanged: PinData;
|
|
83
|
+
gesturechanged: GestureData;
|
|
84
|
+
buttonaaction: ButtonActionData;
|
|
85
|
+
buttonbaction: ButtonActionData;
|
|
86
|
+
buttonabaction: ButtonActionData;
|
|
87
|
+
logoaction: ButtonActionData;
|
|
88
|
+
microbitevent: MicrobitEventData;
|
|
41
89
|
uartdata: UartData;
|
|
42
90
|
}
|
|
43
91
|
type AllEventMap = ServiceConnectionEventMap & DeviceConnectionEventMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-events.js","sourceRoot":"","sources":["../../src/service-events.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"service-events.js","sourceRoot":"","sources":["../../src/service-events.ts"],"names":[],"mappings":";;;AASa,QAAA,WAAW,GAAG;IACzB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,CAAC;CACJ,CAAC"}
|
|
@@ -1,11 +1,62 @@
|
|
|
1
1
|
import { BackgroundErrorData, ConnectionStatusChange, DeviceConnection, FlashDataSource, FlashOptions } from "../device.js";
|
|
2
2
|
import { Logging } from "../logging.js";
|
|
3
|
-
import { AccelerometerData, ButtonData, LedMatrix, MagnetometerData, UartData } from "../service-events.js";
|
|
3
|
+
import { AccelerometerData, ButtonActionData, ButtonData, GestureData, LedMatrix, MagnetometerData, MicrobitEventData, PinData, PinValue, TemperatureData, UartData } from "../service-events.js";
|
|
4
4
|
import { DeviceBondState } from "./device-bond-state.js";
|
|
5
5
|
export interface MicrobitBluetoothConnectionOptions {
|
|
6
6
|
logging?: Logging;
|
|
7
7
|
deviceBondState?: DeviceBondState;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A Bluetooth connection to a micro:bit device.
|
|
11
|
+
*
|
|
12
|
+
* Events and methods rely on specific BLE services being present in the
|
|
13
|
+
* micro:bit's firmware. Which services are available depends on the firmware
|
|
14
|
+
* build for C++ and for a MakeCode program depends on the service blocks added
|
|
15
|
+
* from the Bluetooth extension.
|
|
16
|
+
*
|
|
17
|
+
* The table below maps each event and method to the BLE service it requires.
|
|
18
|
+
* If a service is not present, the event will silently not fire (no error is
|
|
19
|
+
* raised) and methods that depend on it will throw.
|
|
20
|
+
*
|
|
21
|
+
* ### Accelerometer Service
|
|
22
|
+
* - `accelerometerdatachanged` event
|
|
23
|
+
* - {@link getAccelerometerData}, {@link getAccelerometerPeriod}, {@link setAccelerometerPeriod}
|
|
24
|
+
*
|
|
25
|
+
* ### Button Service
|
|
26
|
+
* - `buttonachanged`, `buttonbchanged` events
|
|
27
|
+
*
|
|
28
|
+
* ### Event Service
|
|
29
|
+
* - `gesturechanged` event — also requires the accelerometer hardware to be
|
|
30
|
+
* active; this happens automatically if the Accelerometer Service is present
|
|
31
|
+
* - `buttonaaction`, `buttonbaction`, `buttonabaction` events
|
|
32
|
+
* - `logoaction` event (V2 only)
|
|
33
|
+
* - `microbitevent` event
|
|
34
|
+
* - {@link subscribeToEvent}, {@link sendEvent}
|
|
35
|
+
*
|
|
36
|
+
* ### IO Pin Service
|
|
37
|
+
* - `pinchanged` event
|
|
38
|
+
* - {@link getAnalogPins}, {@link setAnalogPins}
|
|
39
|
+
* - {@link getInputPins}, {@link setInputPins}
|
|
40
|
+
* - {@link readPins}, {@link writePins}, {@link writePinPwm}
|
|
41
|
+
*
|
|
42
|
+
* ### LED Service
|
|
43
|
+
* - {@link setLedText}, {@link getLedScrollingDelay}, {@link setLedScrollingDelay}
|
|
44
|
+
* - {@link getLedMatrix}, {@link setLedMatrix}
|
|
45
|
+
*
|
|
46
|
+
* ### Magnetometer Service
|
|
47
|
+
* - `magnetometerdatachanged` event
|
|
48
|
+
* - {@link getMagnetometerData}, {@link getMagnetometerBearing}
|
|
49
|
+
* - {@link getMagnetometerPeriod}, {@link setMagnetometerPeriod}
|
|
50
|
+
* - {@link triggerMagnetometerCalibration}
|
|
51
|
+
*
|
|
52
|
+
* ### Temperature Service
|
|
53
|
+
* - `temperaturechanged` event
|
|
54
|
+
* - {@link getTemperature}, {@link getTemperaturePeriod}, {@link setTemperaturePeriod}
|
|
55
|
+
*
|
|
56
|
+
* ### UART Service
|
|
57
|
+
* - `uartdata` event
|
|
58
|
+
* - {@link uartWrite}
|
|
59
|
+
*/
|
|
9
60
|
export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
10
61
|
readonly type: "bluetooth";
|
|
11
62
|
addEventListener(type: "status", listener: (data: ConnectionStatusChange) => void): void;
|
|
@@ -13,9 +64,30 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
13
64
|
addEventListener(type: "beforerequestdevice", listener: () => void): void;
|
|
14
65
|
addEventListener(type: "afterrequestdevice", listener: () => void): void;
|
|
15
66
|
addEventListener(type: "flash", listener: () => void): void;
|
|
67
|
+
/** Requires: Accelerometer Service. */
|
|
16
68
|
addEventListener(type: "accelerometerdatachanged", listener: (data: AccelerometerData) => void): void;
|
|
69
|
+
/** Requires: Button Service. */
|
|
17
70
|
addEventListener(type: "buttonachanged" | "buttonbchanged", listener: (data: ButtonData) => void): void;
|
|
71
|
+
/** Requires: Magnetometer Service. */
|
|
18
72
|
addEventListener(type: "magnetometerdatachanged", listener: (data: MagnetometerData) => void): void;
|
|
73
|
+
/** Requires: Temperature Service. */
|
|
74
|
+
addEventListener(type: "temperaturechanged", listener: (data: TemperatureData) => void): void;
|
|
75
|
+
/** Requires: IO Pin Service. */
|
|
76
|
+
addEventListener(type: "pinchanged", listener: (data: PinData) => void): void;
|
|
77
|
+
/** Requires: Event Service. The accelerometer hardware must also be active (automatic if the Accelerometer Service is present). */
|
|
78
|
+
addEventListener(type: "gesturechanged", listener: (data: GestureData) => void): void;
|
|
79
|
+
/** Requires: Event Service. */
|
|
80
|
+
addEventListener(type: "buttonaaction" | "buttonbaction" | "buttonabaction", listener: (data: ButtonActionData) => void): void;
|
|
81
|
+
/** Requires: Event Service. V2 only. */
|
|
82
|
+
addEventListener(type: "logoaction", listener: (data: ButtonActionData) => void): void;
|
|
83
|
+
/**
|
|
84
|
+
* Requires: Event Service. Receives raw micro:bit message bus events
|
|
85
|
+
* registered via {@link subscribeToEvent}. Higher-level events supported
|
|
86
|
+
* by the event service, like `gesturechanged` and button actions, are not
|
|
87
|
+
* included here unless you subscribe to them using {@link subscribeToEvent}.
|
|
88
|
+
*/
|
|
89
|
+
addEventListener(type: "microbitevent", listener: (data: MicrobitEventData) => void): void;
|
|
90
|
+
/** Requires: UART Service. */
|
|
19
91
|
addEventListener(type: "uartdata", listener: (data: UartData) => void): void;
|
|
20
92
|
removeEventListener(type: "status", listener: (data: ConnectionStatusChange) => void): void;
|
|
21
93
|
removeEventListener(type: "backgrounderror", listener: (data: BackgroundErrorData) => void): void;
|
|
@@ -25,6 +97,12 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
25
97
|
removeEventListener(type: "accelerometerdatachanged", listener: (data: AccelerometerData) => void): void;
|
|
26
98
|
removeEventListener(type: "buttonachanged" | "buttonbchanged", listener: (data: ButtonData) => void): void;
|
|
27
99
|
removeEventListener(type: "magnetometerdatachanged", listener: (data: MagnetometerData) => void): void;
|
|
100
|
+
removeEventListener(type: "temperaturechanged", listener: (data: TemperatureData) => void): void;
|
|
101
|
+
removeEventListener(type: "pinchanged", listener: (data: PinData) => void): void;
|
|
102
|
+
removeEventListener(type: "gesturechanged", listener: (data: GestureData) => void): void;
|
|
103
|
+
removeEventListener(type: "buttonaaction" | "buttonbaction" | "buttonabaction", listener: (data: ButtonActionData) => void): void;
|
|
104
|
+
removeEventListener(type: "logoaction", listener: (data: ButtonActionData) => void): void;
|
|
105
|
+
removeEventListener(type: "microbitevent", listener: (data: MicrobitEventData) => void): void;
|
|
28
106
|
removeEventListener(type: "uartdata", listener: (data: UartData) => void): void;
|
|
29
107
|
/**
|
|
30
108
|
* Sets micro:bit name filter for device requesting.
|
|
@@ -35,6 +113,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
35
113
|
/**
|
|
36
114
|
* Gets micro:bit accelerometer data.
|
|
37
115
|
*
|
|
116
|
+
* Requires: Accelerometer Service.
|
|
117
|
+
*
|
|
38
118
|
* @returns accelerometer data.
|
|
39
119
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
40
120
|
*/
|
|
@@ -42,6 +122,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
42
122
|
/**
|
|
43
123
|
* Gets micro:bit accelerometer period.
|
|
44
124
|
*
|
|
125
|
+
* Requires: Accelerometer Service.
|
|
126
|
+
*
|
|
45
127
|
* @returns accelerometer period.
|
|
46
128
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
47
129
|
*/
|
|
@@ -49,6 +131,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
49
131
|
/**
|
|
50
132
|
* Sets micro:bit accelerometer period.
|
|
51
133
|
*
|
|
134
|
+
* Requires: Accelerometer Service.
|
|
135
|
+
*
|
|
52
136
|
* @param value The accelerometer period.
|
|
53
137
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
54
138
|
*/
|
|
@@ -56,6 +140,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
56
140
|
/**
|
|
57
141
|
* Sets micro:bit LED text.
|
|
58
142
|
*
|
|
143
|
+
* Requires: LED Service.
|
|
144
|
+
*
|
|
59
145
|
* @param text The text displayed on micro:bit LED.
|
|
60
146
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
61
147
|
*/
|
|
@@ -63,6 +149,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
63
149
|
/**
|
|
64
150
|
* Gets micro:bit LED scrolling delay.
|
|
65
151
|
*
|
|
152
|
+
* Requires: LED Service.
|
|
153
|
+
*
|
|
66
154
|
* @returns LED scrolling delay in milliseconds.
|
|
67
155
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
68
156
|
*/
|
|
@@ -70,6 +158,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
70
158
|
/**
|
|
71
159
|
* Sets micro:bit LED scrolling delay.
|
|
72
160
|
*
|
|
161
|
+
* Requires: LED Service.
|
|
162
|
+
*
|
|
73
163
|
* @param delayInMillis LED scrolling delay in milliseconds.
|
|
74
164
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
75
165
|
*/
|
|
@@ -77,6 +167,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
77
167
|
/**
|
|
78
168
|
* Gets micro:bit LED matrix.
|
|
79
169
|
*
|
|
170
|
+
* Requires: LED Service.
|
|
171
|
+
*
|
|
80
172
|
* @returns a boolean matrix representing the micro:bit LED display.
|
|
81
173
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
82
174
|
*/
|
|
@@ -84,6 +176,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
84
176
|
/**
|
|
85
177
|
* Sets micro:bit LED matrix.
|
|
86
178
|
*
|
|
179
|
+
* Requires: LED Service.
|
|
180
|
+
*
|
|
87
181
|
* @param matrix an boolean matrix representing the micro:bit LED display.
|
|
88
182
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
89
183
|
*/
|
|
@@ -91,6 +185,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
91
185
|
/**
|
|
92
186
|
* Gets micro:bit magnetometer data.
|
|
93
187
|
*
|
|
188
|
+
* Requires: Magnetometer Service.
|
|
189
|
+
*
|
|
94
190
|
* @returns magnetometer data.
|
|
95
191
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
96
192
|
*/
|
|
@@ -98,6 +194,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
98
194
|
/**
|
|
99
195
|
* Gets micro:bit magnetometer bearing.
|
|
100
196
|
*
|
|
197
|
+
* Requires: Magnetometer Service.
|
|
198
|
+
*
|
|
101
199
|
* @returns magnetometer bearing.
|
|
102
200
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
103
201
|
*/
|
|
@@ -105,6 +203,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
105
203
|
/**
|
|
106
204
|
* Gets micro:bit magnetometer period.
|
|
107
205
|
*
|
|
206
|
+
* Requires: Magnetometer Service.
|
|
207
|
+
*
|
|
108
208
|
* @returns magnetometer period.
|
|
109
209
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
110
210
|
*/
|
|
@@ -112,6 +212,8 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
112
212
|
/**
|
|
113
213
|
* Sets micro:bit magnetometer period.
|
|
114
214
|
*
|
|
215
|
+
* Requires: Magnetometer Service.
|
|
216
|
+
*
|
|
115
217
|
* @param value magnetometer period.
|
|
116
218
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
117
219
|
*/
|
|
@@ -119,12 +221,151 @@ export interface MicrobitBluetoothConnection extends DeviceConnection {
|
|
|
119
221
|
/**
|
|
120
222
|
* Triggers micro:bit magnetometer calibration.
|
|
121
223
|
*
|
|
224
|
+
* Requires: Magnetometer Service.
|
|
225
|
+
*
|
|
122
226
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
123
227
|
*/
|
|
124
228
|
triggerMagnetometerCalibration(): Promise<void>;
|
|
229
|
+
/**
|
|
230
|
+
* Gets the micro:bit temperature in degrees Celsius.
|
|
231
|
+
*
|
|
232
|
+
* Requires: Temperature Service.
|
|
233
|
+
*
|
|
234
|
+
* @returns temperature in degrees Celsius.
|
|
235
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
236
|
+
*/
|
|
237
|
+
getTemperature(): Promise<number>;
|
|
238
|
+
/**
|
|
239
|
+
* Gets the micro:bit temperature sensor period.
|
|
240
|
+
*
|
|
241
|
+
* Requires: Temperature Service.
|
|
242
|
+
*
|
|
243
|
+
* @returns temperature period in milliseconds.
|
|
244
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
245
|
+
*/
|
|
246
|
+
getTemperaturePeriod(): Promise<number>;
|
|
247
|
+
/**
|
|
248
|
+
* Sets the micro:bit temperature sensor period.
|
|
249
|
+
*
|
|
250
|
+
* Requires: Temperature Service.
|
|
251
|
+
*
|
|
252
|
+
* @param value period in milliseconds.
|
|
253
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
254
|
+
*/
|
|
255
|
+
setTemperaturePeriod(value: number): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Gets which pins are configured as analog.
|
|
258
|
+
* All other pins are digital (the default).
|
|
259
|
+
*
|
|
260
|
+
* Requires: IO Pin Service.
|
|
261
|
+
*
|
|
262
|
+
* @returns array of pin numbers (0-18) configured as analog.
|
|
263
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
264
|
+
*/
|
|
265
|
+
getAnalogPins(): Promise<number[]>;
|
|
266
|
+
/**
|
|
267
|
+
* Sets which pins are configured as analog.
|
|
268
|
+
* All other pins become digital (the default).
|
|
269
|
+
*
|
|
270
|
+
* Requires: IO Pin Service.
|
|
271
|
+
*
|
|
272
|
+
* @param pins array of pin numbers (0-18) to configure as analog.
|
|
273
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
274
|
+
*/
|
|
275
|
+
setAnalogPins(pins: number[]): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Gets which pins are configured as inputs.
|
|
278
|
+
* Input pins are monitored and their values reported via notifications.
|
|
279
|
+
* All other pins are outputs (the default).
|
|
280
|
+
*
|
|
281
|
+
* Requires: IO Pin Service.
|
|
282
|
+
*
|
|
283
|
+
* @returns array of pin numbers (0-18) configured as inputs.
|
|
284
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
285
|
+
*/
|
|
286
|
+
getInputPins(): Promise<number[]>;
|
|
287
|
+
/**
|
|
288
|
+
* Sets which pins are configured as inputs.
|
|
289
|
+
* Input pins are monitored and their values reported via notifications.
|
|
290
|
+
* All other pins become outputs (the default).
|
|
291
|
+
*
|
|
292
|
+
* Note: configuring a pin as input overrides any existing pin mode
|
|
293
|
+
* (e.g. touch sensing used by MakeCode "on pin pressed" blocks).
|
|
294
|
+
* The two cannot be used on the same pin simultaneously.
|
|
295
|
+
*
|
|
296
|
+
* Requires: IO Pin Service.
|
|
297
|
+
*
|
|
298
|
+
* @param pins array of pin numbers (0-18) to configure as inputs.
|
|
299
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
300
|
+
*/
|
|
301
|
+
setInputPins(pins: number[]): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Reads current values of input pins. Unlike the `pinchanged` event
|
|
304
|
+
* (which only includes pins whose values changed), this returns every
|
|
305
|
+
* pin configured as an input, up to a firmware limit of 10 pins
|
|
306
|
+
* (lowest-numbered first).
|
|
307
|
+
*
|
|
308
|
+
* Requires: IO Pin Service.
|
|
309
|
+
*
|
|
310
|
+
* @returns array of pin/value pairs.
|
|
311
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
312
|
+
*/
|
|
313
|
+
readPins(): Promise<PinValue[]>;
|
|
314
|
+
/**
|
|
315
|
+
* Writes pin data for output pins.
|
|
316
|
+
*
|
|
317
|
+
* Requires: IO Pin Service.
|
|
318
|
+
*
|
|
319
|
+
* @param data array of pin/value pairs.
|
|
320
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
321
|
+
*/
|
|
322
|
+
writePins(data: PinValue[]): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Sets PWM output on a pin.
|
|
325
|
+
*
|
|
326
|
+
* Requires: IO Pin Service.
|
|
327
|
+
*
|
|
328
|
+
* @param pin Pin number (0-18).
|
|
329
|
+
* @param options PWM configuration.
|
|
330
|
+
* @param options.value Analog value (0-1024).
|
|
331
|
+
* @param options.period Period in microseconds.
|
|
332
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
333
|
+
*/
|
|
334
|
+
writePinPwm(pin: number, options: {
|
|
335
|
+
value: number;
|
|
336
|
+
period: number;
|
|
337
|
+
}): Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Register interest in a specific micro:bit message bus event.
|
|
340
|
+
* Tells the micro:bit to forward matching message bus traffic over BLE.
|
|
341
|
+
* Matching events are dispatched as `microbitevent`.
|
|
342
|
+
* Use 0 as the value to match all events from a source.
|
|
343
|
+
*
|
|
344
|
+
* For common message bus events, consider the higher-level alternatives:
|
|
345
|
+
* `gesturechanged`, `buttonaaction`, `buttonbaction`, `buttonabaction`.
|
|
346
|
+
*
|
|
347
|
+
* Requires: Event Service.
|
|
348
|
+
*
|
|
349
|
+
* @param source Event source ID.
|
|
350
|
+
* @param value Event value to match, or 0 for any.
|
|
351
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
352
|
+
*/
|
|
353
|
+
subscribeToEvent(source: number, value: number): Promise<void>;
|
|
354
|
+
/**
|
|
355
|
+
* Send an event to the micro:bit's message bus.
|
|
356
|
+
*
|
|
357
|
+
* Requires: Event Service.
|
|
358
|
+
*
|
|
359
|
+
* @param source Event source ID.
|
|
360
|
+
* @param value Event value.
|
|
361
|
+
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
362
|
+
*/
|
|
363
|
+
sendEvent(source: number, value: number): Promise<void>;
|
|
125
364
|
/**
|
|
126
365
|
* Write UART messages.
|
|
127
366
|
*
|
|
367
|
+
* Requires: UART Service.
|
|
368
|
+
*
|
|
128
369
|
* @param data UART message.
|
|
129
370
|
* @throws {DeviceError} with code `not-connected` if there is no connection.
|
|
130
371
|
*/
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
import { BleClient } from "@capacitor-community/bluetooth-le";
|
|
7
7
|
import { Capacitor } from "@capacitor/core";
|
|
8
8
|
import MemoryMap from "nrf-intel-hex";
|
|
9
|
-
import {
|
|
10
|
-
import { profile } from "./profile.js";
|
|
11
|
-
import { ConnectionStatus, DeviceError, FlashDataError, assertConnected, ProgressStage, } from "../device.js";
|
|
9
|
+
import { ConnectionStatus, DeviceError, FlashDataError, ProgressStage, assertConnected, } from "../device.js";
|
|
12
10
|
import { TypedEventTarget } from "../events.js";
|
|
13
11
|
import { ConsoleLogging } from "../logging.js";
|
|
12
|
+
import { BluetoothDeviceWrapper, isAndroid, scanningTimeoutInMs, } from "./device-wrapper.js";
|
|
14
13
|
import { fullFlash } from "./flashing/flashing-full.js";
|
|
15
14
|
import partialFlash, { PartialFlashResult, } from "./flashing/flashing-partial.js";
|
|
15
|
+
import { profile } from "./profile.js";
|
|
16
|
+
import { TimeoutError } from "../async-util.js";
|
|
16
17
|
import { throwIfUnavailable } from "../availability.js";
|
|
17
18
|
import { truncateHexAfterEof } from "../hex-util.js";
|
|
18
|
-
import { DefaultDeviceBondState, } from "./device-bond-state.js";
|
|
19
|
-
import { TimeoutError } from "../async-util.js";
|
|
20
19
|
import { withBleErrorMapping } from "./ble-error.js";
|
|
20
|
+
import { DefaultDeviceBondState, } from "./device-bond-state.js";
|
|
21
21
|
let bleClientInitialized = false;
|
|
22
22
|
/**
|
|
23
23
|
* A Bluetooth connection factory.
|
|
@@ -328,6 +328,54 @@ class MicrobitBluetoothConnectionImpl extends TypedEventTarget {
|
|
|
328
328
|
assertConnected(this.device);
|
|
329
329
|
return withBleErrorMapping(() => this.device.magnetometer.triggerCalibration());
|
|
330
330
|
}
|
|
331
|
+
async getTemperature() {
|
|
332
|
+
assertConnected(this.device);
|
|
333
|
+
return withBleErrorMapping(() => this.device.temperature.getData());
|
|
334
|
+
}
|
|
335
|
+
async getTemperaturePeriod() {
|
|
336
|
+
assertConnected(this.device);
|
|
337
|
+
return withBleErrorMapping(() => this.device.temperature.getPeriod());
|
|
338
|
+
}
|
|
339
|
+
async setTemperaturePeriod(value) {
|
|
340
|
+
assertConnected(this.device);
|
|
341
|
+
return withBleErrorMapping(() => this.device.temperature.setPeriod(value));
|
|
342
|
+
}
|
|
343
|
+
async getAnalogPins() {
|
|
344
|
+
assertConnected(this.device);
|
|
345
|
+
return withBleErrorMapping(() => this.device.ioPin.getAnalogPins());
|
|
346
|
+
}
|
|
347
|
+
async setAnalogPins(pins) {
|
|
348
|
+
assertConnected(this.device);
|
|
349
|
+
return withBleErrorMapping(() => this.device.ioPin.setAnalogPins(pins));
|
|
350
|
+
}
|
|
351
|
+
async getInputPins() {
|
|
352
|
+
assertConnected(this.device);
|
|
353
|
+
return withBleErrorMapping(() => this.device.ioPin.getInputPins());
|
|
354
|
+
}
|
|
355
|
+
async setInputPins(pins) {
|
|
356
|
+
assertConnected(this.device);
|
|
357
|
+
return withBleErrorMapping(() => this.device.ioPin.setInputPins(pins));
|
|
358
|
+
}
|
|
359
|
+
async readPins() {
|
|
360
|
+
assertConnected(this.device);
|
|
361
|
+
return withBleErrorMapping(() => this.device.ioPin.readPins());
|
|
362
|
+
}
|
|
363
|
+
async writePins(data) {
|
|
364
|
+
assertConnected(this.device);
|
|
365
|
+
return withBleErrorMapping(() => this.device.ioPin.writePins(data));
|
|
366
|
+
}
|
|
367
|
+
async writePinPwm(pin, options) {
|
|
368
|
+
assertConnected(this.device);
|
|
369
|
+
return withBleErrorMapping(() => this.device.ioPin.setPwm(pin, options.value, options.period));
|
|
370
|
+
}
|
|
371
|
+
async subscribeToEvent(source, value) {
|
|
372
|
+
assertConnected(this.device);
|
|
373
|
+
return withBleErrorMapping(() => this.device.events.subscribeToEvent(source, value));
|
|
374
|
+
}
|
|
375
|
+
async sendEvent(source, value) {
|
|
376
|
+
assertConnected(this.device);
|
|
377
|
+
return withBleErrorMapping(() => this.device.events.sendEvent(source, value));
|
|
378
|
+
}
|
|
331
379
|
async uartWrite(data) {
|
|
332
380
|
assertConnected(this.device);
|
|
333
381
|
return withBleErrorMapping(() => this.device.uart.writeData(data));
|