pxt-microbit 4.1.5 → 4.1.9

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.
Files changed (59) hide show
  1. package/built/common-sim.d.ts +55 -2
  2. package/built/common-sim.js +338 -6
  3. package/built/hexcache/167b21509d45dcf8aa9ac0e8dee0ad14c23cfa41fd75bbf9d0bb839519ac56b1.hex +14849 -0
  4. package/built/hexcache/{6526a3337377701ca7bf1d9940f76fdccac145405380ee3ecc2c96f6049e34ce.hex → 5f77c6b19fd0775b3c9f06534d4d55b43bba44d755df21a7ea304a6b4bc8c33d.hex} +10762 -10738
  5. package/built/hexcache/77bf628097cfa081fbde884794a216b621827ef66ce3beeee76691a64a8f2f84.hex +14318 -0
  6. package/built/hexcache/f091c776e3c7f7fdaae7df4b89e0390e843a916f5a561903fa6188993a5bffe1.hex +20247 -0
  7. package/built/sim-strings.json +3 -3
  8. package/built/sim.js +10 -12
  9. package/built/target-strings.json +1 -1
  10. package/built/target.js +129 -49
  11. package/built/target.json +129 -49
  12. package/built/targetlight.json +6 -6
  13. package/built/web/blockly.css +1 -1
  14. package/built/web/react-common-skillmap.css +1 -0
  15. package/built/web/rtlblockly.css +1 -1
  16. package/built/web/rtlreact-common-skillmap.css +1 -0
  17. package/built/web/rtlsemantic.css +16 -16
  18. package/built/web/semantic.css +16 -16
  19. package/docs/blocks/comments.md +131 -0
  20. package/docs/blocks/loops.md +12 -0
  21. package/docs/device/usb/webusb.md +31 -9
  22. package/docs/device/usb/windows-chrome.md +14 -24
  23. package/docs/device/usb/windows-edge.md +11 -13
  24. package/docs/device/usb.md +10 -4
  25. package/docs/device.md +28 -12
  26. package/docs/docs.md +1 -1
  27. package/docs/extensions.md +126 -2
  28. package/docs/projects/SUMMARY.md +1 -1
  29. package/docs/projects/micro-chat.md +8 -8
  30. package/docs/projects/mood-radio.md +3 -1
  31. package/docs/projects/multi-dice.md +8 -6
  32. package/docs/projects/plot-acceleration.md +2 -2
  33. package/docs/projects/v2-morse-chat.md +2 -2
  34. package/docs/projects/v2-pet-hamster.md +1 -1
  35. package/docs/projects.md +3 -3
  36. package/docs/reference/basic/forever.md +17 -4
  37. package/docs/reference/basic/show-number.md +1 -1
  38. package/docs/reference/game/change.md +10 -6
  39. package/docs/reference/game/get.md +6 -6
  40. package/docs/reference/game/set.md +29 -12
  41. package/docs/reference/loops/every-interval.md +42 -0
  42. package/docs/reference/radio/on-received-buffer.md +1 -0
  43. package/docs/reference/radio/on-received-number.md +2 -0
  44. package/docs/reference/radio/on-received-string.md +1 -0
  45. package/docs/reference/radio/on-received-value.md +1 -0
  46. package/docs/reference/radio/received-packet.md +1 -0
  47. package/docs/reference/radio/send-buffer.md +1 -0
  48. package/docs/reference/radio/send-string.md +1 -0
  49. package/docs/reference/radio/set-group.md +8 -0
  50. package/docs/reference/radio/write-received-packet-to-serial.md +1 -0
  51. package/docs/reference/radio/write-value-to-serial.md +1 -0
  52. package/docs/{v2tutorials.md → tutorials-v2.md} +1 -1
  53. package/package.json +5 -5
  54. package/pxtarget.json +1 -1
  55. package/sim/public/icons/jacdac.svg +1 -1
  56. package/targetconfig.json +48 -9
  57. package/built/hexcache/02e34856c566087a1e5f0212e31686199c414ee7c8a2b9c36be7167d71548860.hex +0 -13960
  58. package/built/hexcache/447fa4d5b24ea1ca19eab3745af559cd49d5831ea3e3d6750812b3af3de0f2c4.hex +0 -14499
  59. package/built/hexcache/8fc8a1499d69a5d8cc851cf49d16112b3021ab801238204dacf84073acf90e7c.hex +0 -20222
@@ -1007,6 +1007,8 @@ declare namespace pxsim.ImageMethods {
1007
1007
  function _fillCircle(img: RefImage, cxy: number, r: number, c: number): void;
1008
1008
  function _blitRow(img: RefImage, xy: number, from: RefImage, xh: number): void;
1009
1009
  function blitRow(img: RefImage, x: number, y: number, from: RefImage, fromX: number, fromH: number): void;
1010
+ function _blit(img: RefImage, src: RefImage, args: RefCollection): void;
1011
+ function blit(dst: RefImage, src: RefImage, args: RefCollection): void;
1010
1012
  }
1011
1013
  declare namespace pxsim.image {
1012
1014
  function byteHeight(h: number, bpp: number): number;
@@ -1075,8 +1077,8 @@ declare namespace pxsim.visuals {
1075
1077
  }
1076
1078
  }
1077
1079
  declare namespace pxsim.settings {
1078
- function _set(key: string, buf: RefBuffer): 0 | -1;
1079
- function _remove(key: string): 0 | -1;
1080
+ function _set(key: string, buf: RefBuffer): -1 | 0;
1081
+ function _remove(key: string): -1 | 0;
1080
1082
  function _exists(key: string): boolean;
1081
1083
  function _get(key: string): RefBuffer;
1082
1084
  function _userClean(): void;
@@ -1179,3 +1181,54 @@ declare namespace pxsim.TouchButtonMethods {
1179
1181
  declare namespace pxsim.AnalogInOutPinMethods {
1180
1182
  function touchButton(name: pins.AnalogInOutPin): TouchButton;
1181
1183
  }
1184
+ declare namespace pxsim {
1185
+ interface WifiSocketBoard extends CommonBoard {
1186
+ wifiSocketState: WifiSocketState;
1187
+ }
1188
+ class WifiSocket {
1189
+ private fd;
1190
+ ws: WebSocket;
1191
+ _err: number;
1192
+ buffers: Uint8Array[];
1193
+ readers: (() => void)[];
1194
+ bytesAvail: number;
1195
+ reqInit: RequestInit;
1196
+ reqUrl: string;
1197
+ reqSent: boolean;
1198
+ constructor(fd: number);
1199
+ openReq(host: string, port: number): Promise<number>;
1200
+ _queue(data: string | Uint8Array | ArrayBuffer): void;
1201
+ openWS(url: string, proto: string[]): Promise<number>;
1202
+ waitRead(): Promise<void>;
1203
+ read(maxlen: number): number | RefBuffer;
1204
+ private handleFetch;
1205
+ write(buf: RefBuffer): Promise<number>;
1206
+ close(): void;
1207
+ }
1208
+ class WifiSocketState {
1209
+ sockets: WifiSocket[];
1210
+ }
1211
+ }
1212
+ declare namespace pxsim._wifi {
1213
+ type int32 = number;
1214
+ export function _allowed(): boolean;
1215
+ export function socketAlloc(): int32;
1216
+ export function socketConnectTLS(fd: int32, host: string, port: int32): Promise<int32>;
1217
+ export function socketWrite(fd: int32, data: RefBuffer): Promise<int32>;
1218
+ export function socketRead(fd: int32, size: int32): Promise<number | RefBuffer>;
1219
+ export function socketBytesAvailable(fd: int32): int32;
1220
+ export function socketClose(fd: int32): int32;
1221
+ export function eventID(): int32;
1222
+ export function scanStart(): void;
1223
+ export function scanResults(): RefBuffer;
1224
+ export function connect(ssid: string, pass: string): int32;
1225
+ export function disconnect(): int32;
1226
+ export function isConnected(): boolean;
1227
+ export function ipInfo(): RefBuffer;
1228
+ export function rssi(): number;
1229
+ export function _raiseEvent(id: number): void;
1230
+ export {};
1231
+ }
1232
+ declare namespace pxsim.crypto {
1233
+ function _sha256(bufs: RefCollection): Promise<RefBuffer>;
1234
+ }
@@ -604,22 +604,20 @@ var pxsim;
604
604
  }
605
605
  control.profilingEnabled = profilingEnabled;
606
606
  function __log(priority, str) {
607
- let prefix = "";
608
607
  switch (priority) {
609
608
  case 0:
610
- prefix = "d>";
609
+ console.debug("d>" + str);
611
610
  break;
612
611
  case 1:
613
- prefix = "l>";
612
+ console.log("l>" + str);
614
613
  break;
615
614
  case 2:
616
- prefix = "w>";
615
+ console.warn("w>" + str);
617
616
  break;
618
617
  case 3:
619
- prefix = "e>";
618
+ console.error("e>" + str);
620
619
  break;
621
620
  }
622
- console.log(prefix + str);
623
621
  pxsim.runtime.board.writeSerial(str);
624
622
  }
625
623
  control.__log = __log;
@@ -3906,6 +3904,44 @@ var pxsim;
3906
3904
  }
3907
3905
  }
3908
3906
  ImageMethods.blitRow = blitRow;
3907
+ function _blit(img, src, args) {
3908
+ blit(img, src, args);
3909
+ }
3910
+ ImageMethods._blit = _blit;
3911
+ function blit(dst, src, args) {
3912
+ const xDst = args.getAt(0);
3913
+ const yDst = args.getAt(1);
3914
+ const wDst = args.getAt(2);
3915
+ const hDst = args.getAt(3);
3916
+ const xSrc = args.getAt(4);
3917
+ const ySrc = args.getAt(5);
3918
+ const wSrc = args.getAt(6);
3919
+ const hSrc = args.getAt(7);
3920
+ const transparent = args.getAt(8);
3921
+ const xSrcStep = ((wSrc << 16) / wDst) | 0;
3922
+ const ySrcStep = ((hSrc << 16) / hDst) | 0;
3923
+ const xDstClip = Math.abs(Math.min(0, xDst));
3924
+ const yDstClip = Math.abs(Math.min(0, yDst));
3925
+ const xDstStart = xDst + xDstClip;
3926
+ const yDstStart = yDst + yDstClip;
3927
+ const xDstEnd = Math.min(dst._width, xDst + wDst);
3928
+ const yDstEnd = Math.min(dst._height, yDst + hDst);
3929
+ const xSrcStart = Math.max(0, (xSrc << 16) + xDstClip * xSrcStep);
3930
+ const ySrcStart = Math.max(0, (ySrc << 16) + yDstClip * ySrcStep);
3931
+ const xSrcEnd = Math.min(src._width, xSrc + wSrc) << 16;
3932
+ const ySrcEnd = Math.min(src._height, ySrc + hSrc) << 16;
3933
+ for (let yDstCur = yDstStart, ySrcCur = ySrcStart; yDstCur < yDstEnd && ySrcCur < ySrcEnd; ++yDstCur, ySrcCur += ySrcStep) {
3934
+ const ySrcCurI = ySrcCur >> 16;
3935
+ for (let xDstCur = xDstStart, xSrcCur = xSrcStart; xDstCur < xDstEnd && xSrcCur < xSrcEnd; ++xDstCur, xSrcCur += xSrcStep) {
3936
+ const xSrcCurI = xSrcCur >> 16;
3937
+ const cSrc = getPixel(src, xSrcCurI, ySrcCurI);
3938
+ if (!transparent || cSrc) {
3939
+ setPixel(dst, xDstCur, yDstCur, cSrc);
3940
+ }
3941
+ }
3942
+ }
3943
+ }
3944
+ ImageMethods.blit = blit;
3909
3945
  })(ImageMethods = pxsim.ImageMethods || (pxsim.ImageMethods = {}));
3910
3946
  })(pxsim || (pxsim = {}));
3911
3947
  (function (pxsim) {
@@ -4689,3 +4725,299 @@ var pxsim;
4689
4725
  AnalogInOutPinMethods.touchButton = touchButton;
4690
4726
  })(AnalogInOutPinMethods = pxsim.AnalogInOutPinMethods || (pxsim.AnalogInOutPinMethods = {}));
4691
4727
  })(pxsim || (pxsim = {}));
4728
+ var pxsim;
4729
+ (function (pxsim) {
4730
+ class WifiSocket {
4731
+ constructor(fd) {
4732
+ this.fd = fd;
4733
+ this.buffers = [];
4734
+ this.readers = [];
4735
+ this.bytesAvail = 0;
4736
+ this.reqInit = {
4737
+ headers: {},
4738
+ credentials: "omit",
4739
+ mode: "cors",
4740
+ cache: "no-cache",
4741
+ redirect: "manual",
4742
+ referrer: "",
4743
+ };
4744
+ this.reqSent = false;
4745
+ }
4746
+ async openReq(host, port) {
4747
+ if (!/^[\w\-\.]+$/.test(host))
4748
+ throw new Error("bad host");
4749
+ this.reqUrl = "https://" + host + ":" + port + "/";
4750
+ return 0;
4751
+ }
4752
+ _queue(data) {
4753
+ let buf;
4754
+ if (data instanceof ArrayBuffer)
4755
+ buf = new Uint8Array(data);
4756
+ else if (data instanceof Uint8Array)
4757
+ buf = data;
4758
+ else
4759
+ buf = pxsim.U.stringToUint8Array(pxsim.U.toUTF8(data));
4760
+ this.buffers.push(buf);
4761
+ if (buf.length && this.bytesAvail == 0)
4762
+ pxsim._wifi._raiseEvent(1000 + this.fd);
4763
+ this.bytesAvail += buf.length;
4764
+ const rr = this.readers;
4765
+ this.readers = [];
4766
+ for (const r of rr)
4767
+ r();
4768
+ }
4769
+ openWS(url, proto) {
4770
+ this.ws = new WebSocket(url, proto);
4771
+ this.ws.binaryType = "arraybuffer";
4772
+ return new Promise((resolve) => {
4773
+ this.ws.onopen = () => {
4774
+ this.ws.onerror = err => {
4775
+ console.log("ws error", err);
4776
+ this._err = -2;
4777
+ };
4778
+ resolve(0);
4779
+ };
4780
+ this.ws.onclose = () => {
4781
+ console.log("ws close");
4782
+ this._err = -20;
4783
+ };
4784
+ this.ws.onmessage = ev => {
4785
+ this._queue(ev.data);
4786
+ };
4787
+ this.ws.onerror = () => resolve(-1);
4788
+ });
4789
+ }
4790
+ waitRead() {
4791
+ return new Promise(resolve => {
4792
+ this.readers.push(resolve);
4793
+ });
4794
+ }
4795
+ read(maxlen) {
4796
+ if (this._err)
4797
+ return this._err;
4798
+ let b = this.buffers[0];
4799
+ if (b) {
4800
+ if (b.length <= maxlen) {
4801
+ this.buffers.shift();
4802
+ }
4803
+ else {
4804
+ this.buffers[0] = b.slice(maxlen);
4805
+ b = b.slice(0, maxlen);
4806
+ }
4807
+ this.bytesAvail -= b.length;
4808
+ return new pxsim.RefBuffer(b);
4809
+ }
4810
+ return null;
4811
+ }
4812
+ async handleFetch() {
4813
+ // we ignore post for now
4814
+ this.reqSent = true;
4815
+ const resp = await fetch(this.reqUrl, this.reqInit);
4816
+ this._queue(`HTTP/1.1 ${resp.status} ${resp.statusText}\r\n`);
4817
+ resp.headers.forEach((v, k) => {
4818
+ if (k.toLowerCase() == "content-length")
4819
+ return;
4820
+ this._queue(`${k}: ${v}\r\n`);
4821
+ });
4822
+ const data = await resp.arrayBuffer();
4823
+ this._queue(`Content-Length: ${data.byteLength}\r\n`);
4824
+ this._queue(`\r\n`);
4825
+ this._queue(data);
4826
+ return 0;
4827
+ }
4828
+ async write(buf) {
4829
+ if (this._err)
4830
+ return this._err;
4831
+ if (this.ws)
4832
+ this.ws.send(buf.data);
4833
+ else {
4834
+ if (this.reqSent)
4835
+ return -2;
4836
+ let str = pxsim.U.fromUTF8(pxsim.U.uint8ArrayToString(buf.data));
4837
+ if (str == "\r\n") {
4838
+ const dummy = this.handleFetch();
4839
+ return 0;
4840
+ }
4841
+ str = str.replace(/\r?\n$/, "");
4842
+ if (!this.reqInit.method) {
4843
+ const m = /^\s*(\S+)\s+\/(\S+)/.exec(str);
4844
+ if (m) {
4845
+ this.reqInit.method = m[1];
4846
+ this.reqUrl += m[2];
4847
+ }
4848
+ }
4849
+ else {
4850
+ const m = /^([^:]+):\s*(.*)/.exec(str);
4851
+ if (m) {
4852
+ this.reqInit.headers[m[1]] = m[2];
4853
+ }
4854
+ }
4855
+ }
4856
+ return 0;
4857
+ }
4858
+ close() {
4859
+ if (this.ws)
4860
+ this.ws.close();
4861
+ }
4862
+ }
4863
+ pxsim.WifiSocket = WifiSocket;
4864
+ class WifiSocketState {
4865
+ constructor() {
4866
+ this.sockets = [null];
4867
+ }
4868
+ }
4869
+ pxsim.WifiSocketState = WifiSocketState;
4870
+ })(pxsim || (pxsim = {}));
4871
+ (function (pxsim) {
4872
+ var _wifi;
4873
+ (function (_wifi) {
4874
+ const MAX_SOCKET = 16;
4875
+ const WIFI_ID = 1234;
4876
+ function _allowed() {
4877
+ var _a, _b, _c;
4878
+ const bid = (_c = (_b = (_a = pxsim.board()) === null || _a === void 0 ? void 0 : _a.runOptions) === null || _b === void 0 ? void 0 : _b.boardDefinition) === null || _c === void 0 ? void 0 : _c.id;
4879
+ return /esp32|-s2/.test(bid);
4880
+ }
4881
+ _wifi._allowed = _allowed;
4882
+ function getState() {
4883
+ const b = pxsim.board();
4884
+ if (!b.wifiSocketState) {
4885
+ if (!_allowed())
4886
+ throw new Error("_wifi not enabled");
4887
+ b.wifiSocketState = new pxsim.WifiSocketState();
4888
+ }
4889
+ return b.wifiSocketState;
4890
+ }
4891
+ function getSock(fd) {
4892
+ if (fd < 0 || fd >= MAX_SOCKET)
4893
+ return null;
4894
+ return getState().sockets[fd];
4895
+ }
4896
+ function socketAlloc() {
4897
+ const state = getState();
4898
+ for (let i = 1; i < state.sockets.length; ++i) {
4899
+ if (!state.sockets[i]) {
4900
+ state.sockets[i] = new pxsim.WifiSocket(i);
4901
+ return i;
4902
+ }
4903
+ }
4904
+ const idx = state.sockets.length;
4905
+ if (idx > MAX_SOCKET)
4906
+ return -1;
4907
+ state.sockets.push(new pxsim.WifiSocket(idx));
4908
+ return idx;
4909
+ }
4910
+ _wifi.socketAlloc = socketAlloc;
4911
+ function socketConnectTLS(fd, host, port) {
4912
+ const sock = getSock(fd);
4913
+ if (!sock)
4914
+ return Promise.resolve(-11);
4915
+ // TODO loosen this up in future
4916
+ if (port == 8883 && /\.azure-devices.net$/.test(host)) {
4917
+ return sock.openWS("wss://" + host + "/$iothub/websocket?iothub-no-client-cert=true", ["mqtt"]);
4918
+ }
4919
+ else if (port == 443 && host == "microsoft.github.io") {
4920
+ return sock.openReq(host, port);
4921
+ }
4922
+ else {
4923
+ console.log("invalid host: " + host);
4924
+ return Promise.resolve(-1);
4925
+ }
4926
+ }
4927
+ _wifi.socketConnectTLS = socketConnectTLS;
4928
+ async function socketWrite(fd, data) {
4929
+ const sock = getSock(fd);
4930
+ if (!sock)
4931
+ return -11;
4932
+ return sock.write(data);
4933
+ }
4934
+ _wifi.socketWrite = socketWrite;
4935
+ async function socketRead(fd, size) {
4936
+ const sock = getSock(fd);
4937
+ if (!sock)
4938
+ return -11;
4939
+ for (;;) {
4940
+ const buf = sock.read(size);
4941
+ if (buf)
4942
+ return buf;
4943
+ await sock.waitRead();
4944
+ }
4945
+ }
4946
+ _wifi.socketRead = socketRead;
4947
+ function socketBytesAvailable(fd) {
4948
+ const sock = getSock(fd);
4949
+ if (!sock)
4950
+ return -11;
4951
+ return sock.bytesAvail;
4952
+ }
4953
+ _wifi.socketBytesAvailable = socketBytesAvailable;
4954
+ function socketClose(fd) {
4955
+ const sock = getSock(fd);
4956
+ if (!sock)
4957
+ return -11;
4958
+ sock.close();
4959
+ return 0;
4960
+ }
4961
+ _wifi.socketClose = socketClose;
4962
+ function eventID() {
4963
+ return WIFI_ID;
4964
+ }
4965
+ _wifi.eventID = eventID;
4966
+ function scanStart() {
4967
+ _raiseEvent(1 /* ScanDone */);
4968
+ }
4969
+ _wifi.scanStart = scanStart;
4970
+ function scanResults() {
4971
+ const b = new Uint8Array(7);
4972
+ b[0] = -20; // rssi
4973
+ b[1] = 0; // authmode
4974
+ b.set(pxsim.U.stringToUint8Array("WiFi"), 2);
4975
+ return new pxsim.RefBuffer(b);
4976
+ }
4977
+ _wifi.scanResults = scanResults;
4978
+ function connect(ssid, pass) {
4979
+ _raiseEvent(2 /* GotIP */);
4980
+ return 0;
4981
+ }
4982
+ _wifi.connect = connect;
4983
+ function disconnect() {
4984
+ return 0;
4985
+ }
4986
+ _wifi.disconnect = disconnect;
4987
+ function isConnected() { return true; }
4988
+ _wifi.isConnected = isConnected;
4989
+ function ipInfo() { return new pxsim.RefBuffer(new Uint8Array(4 * 3)); }
4990
+ _wifi.ipInfo = ipInfo;
4991
+ function rssi() { return -24; }
4992
+ _wifi.rssi = rssi;
4993
+ function _raiseEvent(id) {
4994
+ pxsim.control.raiseEvent(_wifi.eventID(), id, undefined);
4995
+ }
4996
+ _wifi._raiseEvent = _raiseEvent;
4997
+ })(_wifi = pxsim._wifi || (pxsim._wifi = {}));
4998
+ })(pxsim || (pxsim = {}));
4999
+ (function (pxsim) {
5000
+ var crypto;
5001
+ (function (crypto) {
5002
+ function _sha256(bufs) {
5003
+ var _a, _b;
5004
+ let len = 0;
5005
+ const buffers = bufs.toArray().filter(e => e instanceof pxsim.RefBuffer).map((b) => {
5006
+ len += b.data.length;
5007
+ return b.data;
5008
+ });
5009
+ const concat = new Uint8Array(len);
5010
+ len = 0;
5011
+ for (const b of buffers) {
5012
+ concat.set(b, len);
5013
+ len += b.length;
5014
+ }
5015
+ const r = (_b = (_a = window === null || window === void 0 ? void 0 : window.crypto) === null || _a === void 0 ? void 0 : _a.subtle) === null || _b === void 0 ? void 0 : _b.digest("SHA-256", concat);
5016
+ if (r)
5017
+ return r.then(buf => new pxsim.RefBuffer(new Uint8Array(buf)));
5018
+ else
5019
+ return Promise.resolve(undefined);
5020
+ }
5021
+ crypto._sha256 = _sha256;
5022
+ })(crypto = pxsim.crypto || (pxsim.crypto = {}));
5023
+ })(pxsim || (pxsim = {}));