pxt-common-packages 9.5.3 → 9.5.4
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/built/common-sim.d.ts +5 -0
- package/built/common-sim.js +52 -22
- package/libs/matrix-keypad/built/debug/binary.js +8 -8
- package/libs/radio/_locales/radio-jsdoc-strings.json +2 -0
- package/libs/radio/radio.cpp +55 -3
- package/libs/radio/shims.d.ts +14 -0
- package/libs/radio/sim/radio.ts +18 -5
- package/libs/radio/sim/state.ts +37 -17
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- package/libs/sprite-scaling/built/debug/binary.js +6782 -6782
- package/package.json +1 -1
package/built/common-sim.d.ts
CHANGED
|
@@ -882,6 +882,8 @@ declare namespace pxsim.radio {
|
|
|
882
882
|
function sendRawPacket(buf: RefBuffer): void;
|
|
883
883
|
function readRawPacket(): RefBuffer;
|
|
884
884
|
function onDataReceived(handler: RefAction): void;
|
|
885
|
+
function off(): void;
|
|
886
|
+
function on(): void;
|
|
885
887
|
}
|
|
886
888
|
declare namespace pxsim {
|
|
887
889
|
interface RadioBoard extends EventBusBoard {
|
|
@@ -924,12 +926,15 @@ declare namespace pxsim {
|
|
|
924
926
|
datagram: RadioDatagram;
|
|
925
927
|
groupId: number;
|
|
926
928
|
band: number;
|
|
929
|
+
enable: boolean;
|
|
927
930
|
constructor(runtime: Runtime, board: BaseBoard, dal: RadioDAL);
|
|
928
931
|
private handleMessage;
|
|
929
932
|
setGroup(id: number): void;
|
|
930
933
|
setTransmitPower(power: number): void;
|
|
931
934
|
setTransmitSerialNumber(sn: boolean): void;
|
|
932
935
|
setFrequencyBand(band: number): void;
|
|
936
|
+
off(): void;
|
|
937
|
+
on(): void;
|
|
933
938
|
raiseEvent(id: number, eventid: number): void;
|
|
934
939
|
receivePacket(packet: SimulatorRadioPacketMessage): void;
|
|
935
940
|
}
|
package/built/common-sim.js
CHANGED
|
@@ -3119,11 +3119,13 @@ var pxsim;
|
|
|
3119
3119
|
function sendRawPacket(buf) {
|
|
3120
3120
|
let cb = pxsim.getResume();
|
|
3121
3121
|
const state = pxsim.getRadioState();
|
|
3122
|
-
state.
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3122
|
+
if (state.enable) {
|
|
3123
|
+
state.datagram.send({
|
|
3124
|
+
type: 0,
|
|
3125
|
+
groupId: state.groupId,
|
|
3126
|
+
bufferData: buf.data
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3127
3129
|
setTimeout(cb, 1);
|
|
3128
3130
|
}
|
|
3129
3131
|
radio.sendRawPacket = sendRawPacket;
|
|
@@ -3147,6 +3149,16 @@ var pxsim;
|
|
|
3147
3149
|
state.datagram.onReceived(handler);
|
|
3148
3150
|
}
|
|
3149
3151
|
radio.onDataReceived = onDataReceived;
|
|
3152
|
+
function off() {
|
|
3153
|
+
const state = pxsim.getRadioState();
|
|
3154
|
+
state.off();
|
|
3155
|
+
}
|
|
3156
|
+
radio.off = off;
|
|
3157
|
+
function on() {
|
|
3158
|
+
const state = pxsim.getRadioState();
|
|
3159
|
+
state.on();
|
|
3160
|
+
}
|
|
3161
|
+
radio.on = on;
|
|
3150
3162
|
})(radio = pxsim.radio || (pxsim.radio = {}));
|
|
3151
3163
|
})(pxsim || (pxsim = {}));
|
|
3152
3164
|
var pxsim;
|
|
@@ -3215,6 +3227,7 @@ var pxsim;
|
|
|
3215
3227
|
this.power = 6; // default value
|
|
3216
3228
|
this.groupId = 0;
|
|
3217
3229
|
this.band = 7; // https://github.com/lancaster-university/microbit-dal/blob/master/inc/core/MicroBitConfig.h#L320
|
|
3230
|
+
this.enable = true;
|
|
3218
3231
|
this.board.addMessageListener(this.handleMessage.bind(this));
|
|
3219
3232
|
}
|
|
3220
3233
|
handleMessage(msg) {
|
|
@@ -3224,34 +3237,51 @@ var pxsim;
|
|
|
3224
3237
|
}
|
|
3225
3238
|
}
|
|
3226
3239
|
setGroup(id) {
|
|
3227
|
-
this.
|
|
3240
|
+
if (this.enable) {
|
|
3241
|
+
this.groupId = id & 0xff; // byte only
|
|
3242
|
+
}
|
|
3228
3243
|
}
|
|
3229
3244
|
setTransmitPower(power) {
|
|
3230
|
-
|
|
3231
|
-
|
|
3245
|
+
if (this.enable) {
|
|
3246
|
+
power = power | 0;
|
|
3247
|
+
this.power = Math.max(0, Math.min(7, power));
|
|
3248
|
+
}
|
|
3232
3249
|
}
|
|
3233
3250
|
setTransmitSerialNumber(sn) {
|
|
3234
3251
|
this.transmitSerialNumber = !!sn;
|
|
3235
3252
|
}
|
|
3236
3253
|
setFrequencyBand(band) {
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3254
|
+
if (this.enable) {
|
|
3255
|
+
band = band | 0;
|
|
3256
|
+
if (band < 0 || band > 83)
|
|
3257
|
+
return;
|
|
3258
|
+
this.band = band;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
off() {
|
|
3262
|
+
this.enable = false;
|
|
3263
|
+
}
|
|
3264
|
+
on() {
|
|
3265
|
+
this.enable = true;
|
|
3241
3266
|
}
|
|
3242
3267
|
raiseEvent(id, eventid) {
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3268
|
+
if (this.enable) {
|
|
3269
|
+
pxsim.Runtime.postMessage({
|
|
3270
|
+
type: "eventbus",
|
|
3271
|
+
broadcast: true,
|
|
3272
|
+
id,
|
|
3273
|
+
eventid,
|
|
3274
|
+
power: this.power,
|
|
3275
|
+
group: this.groupId
|
|
3276
|
+
});
|
|
3277
|
+
}
|
|
3251
3278
|
}
|
|
3252
3279
|
receivePacket(packet) {
|
|
3253
|
-
if (this.
|
|
3254
|
-
this.
|
|
3280
|
+
if (this.enable) {
|
|
3281
|
+
if (this.groupId == packet.payload.groupId) {
|
|
3282
|
+
this.datagram.queue(packet);
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3255
3285
|
}
|
|
3256
3286
|
}
|
|
3257
3287
|
pxsim.RadioState = RadioState;
|
|
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
|
|
|
56
56
|
const pxsim_numops = pxsim.numops;
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
function
|
|
59
|
+
function _main___P188726(s) {
|
|
60
60
|
let r0 = s.r0, step = s.pc;
|
|
61
61
|
s.pc = -1;
|
|
62
62
|
|
|
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
|
|
|
66
66
|
switch (step) {
|
|
67
67
|
case 0:
|
|
68
68
|
|
|
69
|
-
globals.
|
|
70
|
-
globals.
|
|
69
|
+
globals._intervals___188969 = (undefined);
|
|
70
|
+
globals._pollEventQueue___188982 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P188726.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P188726.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P188726_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P188726, depth: s.depth + 1,
|
|
82
82
|
pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
|
|
83
83
|
} }
|
|
84
84
|
|
|
@@ -88,5 +88,5 @@ function _main___P188722_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
91
|
+
return _main___P188726
|
|
92
92
|
})
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"radio": "Communicate data using radio packets",
|
|
3
3
|
"radio._packetProperty": "Gets a packet property.",
|
|
4
4
|
"radio._packetProperty|param|type": "the packet property type, eg: PacketProperty.time",
|
|
5
|
+
"radio.off": "Disables the radio for use as a multipoint sender/receiver.\nDisabling radio will help conserve battery power when it is not in use.",
|
|
6
|
+
"radio.on": "Initialises the radio for use as a multipoint sender/receiver\nOnly useful when the radio.off() is used beforehand.",
|
|
5
7
|
"radio.onDataReceived": "Used internally by the library.",
|
|
6
8
|
"radio.onReceivedBuffer": "Registers code to run when the radio receives a buffer.",
|
|
7
9
|
"radio.onReceivedNumber": "Registers code to run when the radio receives a number.",
|
package/libs/radio/radio.cpp
CHANGED
|
@@ -73,28 +73,80 @@ CODAL_RADIO* getRadio() {
|
|
|
73
73
|
#endif // #else
|
|
74
74
|
|
|
75
75
|
bool radioEnabled = false;
|
|
76
|
+
bool init = false;
|
|
76
77
|
int radioEnable() {
|
|
77
78
|
#ifdef CODAL_RADIO
|
|
78
79
|
auto radio = getRadio();
|
|
79
80
|
if (NULL == radio)
|
|
80
81
|
return DEVICE_NOT_SUPPORTED;
|
|
81
82
|
|
|
83
|
+
if (init && !radioEnabled) {
|
|
84
|
+
//If radio was explicitly disabled from a call to off API
|
|
85
|
+
//We don't want to enable it here. User needs to call on API first.
|
|
86
|
+
return DEVICE_NOT_SUPPORTED;
|
|
87
|
+
}
|
|
88
|
+
|
|
82
89
|
int r = radio->enable();
|
|
83
90
|
if (r != DEVICE_OK) {
|
|
84
91
|
target_panic(43);
|
|
85
92
|
return r;
|
|
86
93
|
}
|
|
87
|
-
if (!
|
|
88
|
-
getRadio()->setGroup(pxt::programHash()
|
|
94
|
+
if (!init) {
|
|
95
|
+
getRadio()->setGroup(0); //Default group zero. This used to be pxt::programHash()
|
|
89
96
|
getRadio()->setTransmitPower(6); // start with high power by default
|
|
90
|
-
|
|
97
|
+
init = true;
|
|
91
98
|
}
|
|
99
|
+
radioEnabled = true;
|
|
92
100
|
return r;
|
|
93
101
|
#else
|
|
94
102
|
return DEVICE_NOT_SUPPORTED;
|
|
95
103
|
#endif
|
|
96
104
|
}
|
|
97
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Disables the radio for use as a multipoint sender/receiver.
|
|
108
|
+
* Disabling radio will help conserve battery power when it is not in use.
|
|
109
|
+
*/
|
|
110
|
+
//% help=radio/off
|
|
111
|
+
void off() {
|
|
112
|
+
#ifdef CODAL_RADIO
|
|
113
|
+
auto radio = getRadio();
|
|
114
|
+
if (NULL == radio)
|
|
115
|
+
return;
|
|
116
|
+
|
|
117
|
+
int r = radio->disable();
|
|
118
|
+
if (r != DEVICE_OK) {
|
|
119
|
+
target_panic(43);
|
|
120
|
+
} else {
|
|
121
|
+
radioEnabled = false;
|
|
122
|
+
}
|
|
123
|
+
#else
|
|
124
|
+
return;
|
|
125
|
+
#endif
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Initialises the radio for use as a multipoint sender/receiver
|
|
130
|
+
* Only useful when the radio.off() is used beforehand.
|
|
131
|
+
*/
|
|
132
|
+
//% help=radio/on
|
|
133
|
+
void on() {
|
|
134
|
+
#ifdef CODAL_RADIO
|
|
135
|
+
auto radio = getRadio();
|
|
136
|
+
if (NULL == radio)
|
|
137
|
+
return;
|
|
138
|
+
|
|
139
|
+
int r = radio->enable();
|
|
140
|
+
if (r != DEVICE_OK) {
|
|
141
|
+
target_panic(43);
|
|
142
|
+
} else {
|
|
143
|
+
radioEnabled = true;
|
|
144
|
+
}
|
|
145
|
+
#else
|
|
146
|
+
return;
|
|
147
|
+
#endif
|
|
148
|
+
}
|
|
149
|
+
|
|
98
150
|
/**
|
|
99
151
|
* Sends an event over radio to neigboring devices
|
|
100
152
|
*/
|
package/libs/radio/shims.d.ts
CHANGED
|
@@ -5,6 +5,20 @@
|
|
|
5
5
|
//% color=#E3008C weight=96 icon="\uf012"
|
|
6
6
|
declare namespace radio {
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Disables the radio for use as a multipoint sender/receiver.
|
|
10
|
+
* Disabling radio will help conserve battery power when it is not in use.
|
|
11
|
+
*/
|
|
12
|
+
//% help=radio/off shim=radio::off
|
|
13
|
+
function off(): void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initialises the radio for use as a multipoint sender/receiver
|
|
17
|
+
* Only useful when the radio.off() is used beforehand.
|
|
18
|
+
*/
|
|
19
|
+
//% help=radio/on shim=radio::on
|
|
20
|
+
function on(): void;
|
|
21
|
+
|
|
8
22
|
/**
|
|
9
23
|
* Sends an event over radio to neigboring devices
|
|
10
24
|
*/
|
package/libs/radio/sim/radio.ts
CHANGED
|
@@ -22,11 +22,13 @@ namespace pxsim.radio {
|
|
|
22
22
|
export function sendRawPacket(buf: RefBuffer) {
|
|
23
23
|
let cb = getResume();
|
|
24
24
|
const state = pxsim.getRadioState();
|
|
25
|
-
state.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
if (state.enable) {
|
|
26
|
+
state.datagram.send({
|
|
27
|
+
type: 0,
|
|
28
|
+
groupId: state.groupId,
|
|
29
|
+
bufferData: buf.data
|
|
30
|
+
});
|
|
31
|
+
}
|
|
30
32
|
setTimeout(cb, 1);
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -50,4 +52,15 @@ namespace pxsim.radio {
|
|
|
50
52
|
const state = pxsim.getRadioState();
|
|
51
53
|
state.datagram.onReceived(handler);
|
|
52
54
|
}
|
|
55
|
+
|
|
56
|
+
export function off(){
|
|
57
|
+
const state = pxsim.getRadioState();
|
|
58
|
+
state.off();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function on(){
|
|
62
|
+
const state = pxsim.getRadioState();
|
|
63
|
+
state.on();
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
}
|
package/libs/radio/sim/state.ts
CHANGED
|
@@ -87,13 +87,14 @@ namespace pxsim {
|
|
|
87
87
|
datagram: RadioDatagram;
|
|
88
88
|
groupId: number;
|
|
89
89
|
band: number;
|
|
90
|
+
enable: boolean;
|
|
90
91
|
|
|
91
92
|
constructor(private readonly runtime: Runtime, private readonly board: BaseBoard, dal: RadioDAL) {
|
|
92
93
|
this.datagram = new RadioDatagram(runtime, dal);
|
|
93
94
|
this.power = 6; // default value
|
|
94
95
|
this.groupId = 0;
|
|
95
96
|
this.band = 7; // https://github.com/lancaster-university/microbit-dal/blob/master/inc/core/MicroBitConfig.h#L320
|
|
96
|
-
|
|
97
|
+
this.enable = true;
|
|
97
98
|
this.board.addMessageListener(this.handleMessage.bind(this))
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -105,12 +106,16 @@ namespace pxsim {
|
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
public setGroup(id: number) {
|
|
108
|
-
this.
|
|
109
|
+
if (this.enable) {
|
|
110
|
+
this.groupId = id & 0xff; // byte only
|
|
111
|
+
}
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
setTransmitPower(power: number) {
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
if (this.enable) {
|
|
116
|
+
power = power | 0;
|
|
117
|
+
this.power = Math.max(0, Math.min(7, power));
|
|
118
|
+
}
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
setTransmitSerialNumber(sn: boolean) {
|
|
@@ -118,25 +123,40 @@ namespace pxsim {
|
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
setFrequencyBand(band: number) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
if (this.enable) {
|
|
127
|
+
band = band | 0;
|
|
128
|
+
if (band < 0 || band > 83) return;
|
|
129
|
+
this.band = band;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
off() {
|
|
134
|
+
this.enable = false;
|
|
124
135
|
}
|
|
125
136
|
|
|
137
|
+
on() {
|
|
138
|
+
this.enable = true;
|
|
139
|
+
}
|
|
140
|
+
|
|
126
141
|
raiseEvent(id: number, eventid: number) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
if (this.enable) {
|
|
143
|
+
Runtime.postMessage(<SimulatorEventBusMessage>{
|
|
144
|
+
type: "eventbus",
|
|
145
|
+
broadcast: true,
|
|
146
|
+
id,
|
|
147
|
+
eventid,
|
|
148
|
+
power: this.power,
|
|
149
|
+
group: this.groupId
|
|
150
|
+
})
|
|
151
|
+
}
|
|
135
152
|
}
|
|
136
153
|
|
|
137
154
|
receivePacket(packet: SimulatorRadioPacketMessage) {
|
|
138
|
-
if (this.
|
|
139
|
-
this.
|
|
155
|
+
if (this.enable) {
|
|
156
|
+
if (this.groupId == packet.payload.groupId) {
|
|
157
|
+
this.datagram.queue(packet)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
140
160
|
}
|
|
141
161
|
}
|
|
142
162
|
}
|
|
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
|
|
|
56
56
|
const pxsim_numops = pxsim.numops;
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
function
|
|
59
|
+
function _main___P186885(s) {
|
|
60
60
|
let r0 = s.r0, step = s.pc;
|
|
61
61
|
s.pc = -1;
|
|
62
62
|
|
|
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
|
|
|
66
66
|
switch (step) {
|
|
67
67
|
case 0:
|
|
68
68
|
|
|
69
|
-
globals.
|
|
70
|
-
globals.
|
|
69
|
+
globals._intervals___187128 = (undefined);
|
|
70
|
+
globals._pollEventQueue___187141 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P186885.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"radio-broadcast.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P186885.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P186885_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P186885, depth: s.depth + 1,
|
|
82
82
|
pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
|
|
83
83
|
} }
|
|
84
84
|
|
|
@@ -88,5 +88,5 @@ function _main___P186883_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
91
|
+
return _main___P186885
|
|
92
92
|
})
|