support for exposing device name
This commit is contained in:
parent
512e40fae3
commit
55859b1237
@ -155,4 +155,12 @@ namespace control {
|
|||||||
void onEvent(int src, int value, Action handler) {
|
void onEvent(int src, int value, Action handler) {
|
||||||
registerWithDal(src, value, handler);
|
registerWithDal(src, value, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a friendly name for the device derived from the its serial number
|
||||||
|
*/
|
||||||
|
//% blockId="control_device_name" block="device name" weight=10
|
||||||
|
StringData* deviceName() {
|
||||||
|
return ManagedString(microbit_friendly_name()).leakData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
libs/microbit/shims.d.ts
vendored
6
libs/microbit/shims.d.ts
vendored
@ -342,6 +342,12 @@ declare namespace control {
|
|||||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
|
||||||
//% blockExternalInputs=1 shim=control::onEvent
|
//% blockExternalInputs=1 shim=control::onEvent
|
||||||
function onEvent(src: number, value: number, handler: () => void): void;
|
function onEvent(src: number, value: number, handler: () => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a friendly name for the device derived from the its serial number
|
||||||
|
*/
|
||||||
|
//% blockId="control_device_name" block="device name" weight=10 shim=control::deviceName
|
||||||
|
function deviceName(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,6 +227,13 @@ namespace pxsim.control {
|
|||||||
U.userError("reset not implemented in simulator yet")
|
U.userError("reset not implemented in simulator yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function deviceName() : string {
|
||||||
|
let b = board();
|
||||||
|
return b && b.id
|
||||||
|
? b.id.slice(0, 4)
|
||||||
|
: 'abcd';
|
||||||
|
}
|
||||||
|
|
||||||
export function onEvent(id: number, evid: number, handler: RefAction) {
|
export function onEvent(id: number, evid: number, handler: RefAction) {
|
||||||
pxt.registerWithDal(id, evid, handler)
|
pxt.registerWithDal(id, evid, handler)
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.id = "b" + Math.random();
|
this.id = "b" + Math.random().toString().slice(1);
|
||||||
this.animationQ = new AnimationQueue(runtime);
|
this.animationQ = new AnimationQueue(runtime);
|
||||||
this.bus = new EventBus(runtime);
|
this.bus = new EventBus(runtime);
|
||||||
this.radio = new RadioBus(runtime);
|
this.radio = new RadioBus(runtime);
|
||||||
|
Loading…
Reference in New Issue
Block a user