pxt-microbit 4.1.10 → 4.1.13

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/sim.d.ts CHANGED
@@ -1060,6 +1060,8 @@ declare namespace pxsim.radio {
1060
1060
  function sendRawPacket(buf: RefBuffer): void;
1061
1061
  function readRawPacket(): RefBuffer;
1062
1062
  function onDataReceived(handler: RefAction): void;
1063
+ function off(): void;
1064
+ function on(): void;
1063
1065
  }
1064
1066
  declare namespace pxsim {
1065
1067
  interface RadioBoard extends EventBusBoard {
@@ -1102,12 +1104,15 @@ declare namespace pxsim {
1102
1104
  datagram: RadioDatagram;
1103
1105
  groupId: number;
1104
1106
  band: number;
1107
+ enable: boolean;
1105
1108
  constructor(runtime: Runtime, board: BaseBoard, dal: RadioDAL);
1106
1109
  private handleMessage;
1107
1110
  setGroup(id: number): void;
1108
1111
  setTransmitPower(power: number): void;
1109
1112
  setTransmitSerialNumber(sn: boolean): void;
1110
1113
  setFrequencyBand(band: number): void;
1114
+ off(): void;
1115
+ on(): void;
1111
1116
  raiseEvent(id: number, eventid: number): void;
1112
1117
  receivePacket(packet: SimulatorRadioPacketMessage): void;
1113
1118
  }
package/built/sim.js CHANGED
@@ -5139,11 +5139,13 @@ var pxsim;
5139
5139
  function sendRawPacket(buf) {
5140
5140
  let cb = pxsim.getResume();
5141
5141
  const state = pxsim.getRadioState();
5142
- state.datagram.send({
5143
- type: 0,
5144
- groupId: state.groupId,
5145
- bufferData: buf.data
5146
- });
5142
+ if (state.enable) {
5143
+ state.datagram.send({
5144
+ type: 0,
5145
+ groupId: state.groupId,
5146
+ bufferData: buf.data
5147
+ });
5148
+ }
5147
5149
  setTimeout(cb, 1);
5148
5150
  }
5149
5151
  radio.sendRawPacket = sendRawPacket;
@@ -5167,6 +5169,16 @@ var pxsim;
5167
5169
  state.datagram.onReceived(handler);
5168
5170
  }
5169
5171
  radio.onDataReceived = onDataReceived;
5172
+ function off() {
5173
+ const state = pxsim.getRadioState();
5174
+ state.off();
5175
+ }
5176
+ radio.off = off;
5177
+ function on() {
5178
+ const state = pxsim.getRadioState();
5179
+ state.on();
5180
+ }
5181
+ radio.on = on;
5170
5182
  })(radio = pxsim.radio || (pxsim.radio = {}));
5171
5183
  })(pxsim || (pxsim = {}));
5172
5184
  var pxsim;
@@ -5235,6 +5247,7 @@ var pxsim;
5235
5247
  this.power = 6; // default value
5236
5248
  this.groupId = 0;
5237
5249
  this.band = 7; // https://github.com/lancaster-university/microbit-dal/blob/master/inc/core/MicroBitConfig.h#L320
5250
+ this.enable = true;
5238
5251
  this.board.addMessageListener(this.handleMessage.bind(this));
5239
5252
  }
5240
5253
  handleMessage(msg) {
@@ -5244,34 +5257,51 @@ var pxsim;
5244
5257
  }
5245
5258
  }
5246
5259
  setGroup(id) {
5247
- this.groupId = id & 0xff; // byte only
5260
+ if (this.enable) {
5261
+ this.groupId = id & 0xff; // byte only
5262
+ }
5248
5263
  }
5249
5264
  setTransmitPower(power) {
5250
- power = power | 0;
5251
- this.power = Math.max(0, Math.min(7, power));
5265
+ if (this.enable) {
5266
+ power = power | 0;
5267
+ this.power = Math.max(0, Math.min(7, power));
5268
+ }
5252
5269
  }
5253
5270
  setTransmitSerialNumber(sn) {
5254
5271
  this.transmitSerialNumber = !!sn;
5255
5272
  }
5256
5273
  setFrequencyBand(band) {
5257
- band = band | 0;
5258
- if (band < 0 || band > 83)
5259
- return;
5260
- this.band = band;
5274
+ if (this.enable) {
5275
+ band = band | 0;
5276
+ if (band < 0 || band > 83)
5277
+ return;
5278
+ this.band = band;
5279
+ }
5280
+ }
5281
+ off() {
5282
+ this.enable = false;
5283
+ }
5284
+ on() {
5285
+ this.enable = true;
5261
5286
  }
5262
5287
  raiseEvent(id, eventid) {
5263
- pxsim.Runtime.postMessage({
5264
- type: "eventbus",
5265
- broadcast: true,
5266
- id,
5267
- eventid,
5268
- power: this.power,
5269
- group: this.groupId
5270
- });
5288
+ if (this.enable) {
5289
+ pxsim.Runtime.postMessage({
5290
+ type: "eventbus",
5291
+ broadcast: true,
5292
+ id,
5293
+ eventid,
5294
+ power: this.power,
5295
+ group: this.groupId
5296
+ });
5297
+ }
5271
5298
  }
5272
5299
  receivePacket(packet) {
5273
- if (this.groupId == packet.payload.groupId)
5274
- this.datagram.queue(packet);
5300
+ if (this.enable) {
5301
+ if (this.groupId == packet.payload.groupId) {
5302
+ this.datagram.queue(packet);
5303
+ }
5304
+ }
5275
5305
  }
5276
5306
  }
5277
5307
  pxsim.RadioState = RadioState;