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/target.js CHANGED
@@ -383,7 +383,7 @@ var pxtTargetBundle = {
383
383
  "driveDisplayName": "MICROBIT",
384
384
  "appStoreID": "1092687276",
385
385
  "mobileSafariDownloadProtocol": "microbithex://?data",
386
- "crowdinProject": "kindscript",
386
+ "crowdinProject": "makecode",
387
387
  "extendEditor": true,
388
388
  "extendFieldEditors": true,
389
389
  "enableTrace": true,
@@ -2662,11 +2662,11 @@ var pxtTargetBundle = {
2662
2662
  },
2663
2663
  "uploadDocs": true,
2664
2664
  "versions": {
2665
- "branch": "v4.1.10",
2666
- "tag": "v4.1.10",
2667
- "commits": "https://github.com/microsoft/pxt-microbit/commits/dcef12a9373de4e6e2a3467db29c870c1a06e98a",
2668
- "target": "4.1.10",
2669
- "pxt": "7.4.12"
2665
+ "branch": "v4.1.13",
2666
+ "tag": "v4.1.13",
2667
+ "commits": "https://github.com/microsoft/pxt-microbit/commits/a1dddba89ab269628ec39fe4963e6c8e2d4f09a3",
2668
+ "target": "4.1.13",
2669
+ "pxt": "7.5.3"
2670
2670
  },
2671
2671
  "blocksprj": {
2672
2672
  "id": "blocksprj",
@@ -2730,7 +2730,7 @@ var pxtTargetBundle = {
2730
2730
  "core.cpp": "#include \"pxtbase.h\"\n#include <limits.h>\n#include <stdlib.h>\n\nusing namespace std;\n\n#define p10(v) __builtin_powi(10, v)\n\n// try not to create cons-strings shorter than this\n#define SHORT_CONCAT_STRING 50\n\nnamespace pxt {\n\nPXT_DEF_STRING(emptyString, \"\")\n\nstatic HandlerBinding *handlerBindings;\n\nHandlerBinding *nextBinding(HandlerBinding *curr, int source, int value) {\n for (auto p = curr; p; p = p->next) {\n // DEVICE_ID_ANY == DEVICE_EXT_ANY == 0\n if ((p->source == source || p->source == 0) &&\n (value == -1 || p->value == value || p->value == 0)) {\n return p;\n }\n }\n return 0;\n}\n\nHandlerBinding *findBinding(int source, int value) {\n return nextBinding(handlerBindings, source, value);\n}\n\nvoid setBinding(int source, int value, Action act) {\n HandlerBinding *curr = NULL;\n for (auto p = handlerBindings; p; p = p->next) {\n if ((p->source == source) && (p->value == value)) {\n curr = p;\n break;\n }\n }\n if (curr) {\n curr->action = act;\n return;\n }\n curr = new (app_alloc(sizeof(HandlerBinding))) HandlerBinding();\n curr->next = handlerBindings;\n curr->source = source;\n curr->value = value;\n curr->action = act;\n registerGC(&curr->action);\n handlerBindings = curr;\n}\n\nvoid coreReset() {\n // these are allocated on GC heap, so they will go away together with the reset\n handlerBindings = NULL;\n}\n\nstruct EmptyBufferLayout {\n const void *vtable;\n // data needs to be word-aligned, so we use 32 bits for length\n int length;\n uint8_t data[1];\n};\n\nstatic const EmptyBufferLayout emptyBuffer[1] = {{&pxt::buffer_vt, 0, {0}}};\n\n#if PXT_UTF8\nint utf8Len(const char *data, int size) {\n int len = 0;\n for (int i = 0; i < size; ++i) {\n char c = data[i];\n len++;\n if ((c & 0x80) == 0x00) {\n // skip\n } else if ((c & 0xe0) == 0xc0) {\n i++;\n } else if ((c & 0xf0) == 0xe0) {\n i += 2;\n } else {\n // error; just skip\n }\n }\n return len;\n}\n\nconst char *utf8Skip(const char *data, int size, int skip) {\n int len = 0;\n for (int i = 0; i <= size; ++i) {\n char c = data[i];\n len++;\n if (len > skip)\n return data + i;\n if ((c & 0x80) == 0x00) {\n // skip\n } else if ((c & 0xe0) == 0xc0) {\n i++;\n } else if ((c & 0xf0) == 0xe0) {\n i += 2;\n } else {\n // error; just skip over\n }\n }\n return NULL;\n}\n\nstatic char *write3byte(char *dst, uint32_t charCode) {\n if (dst) {\n *dst++ = 0xe0 | (charCode >> 12);\n *dst++ = 0x80 | (0x3f & (charCode >> 6));\n *dst++ = 0x80 | (0x3f & (charCode >> 0));\n }\n return dst;\n}\n\nstatic char *write2byte(char *dst, uint32_t charCode) {\n if (dst) {\n *dst++ = 0xc0 | (charCode >> 6);\n *dst++ = 0x80 | (0x3f & charCode);\n }\n return dst;\n}\n\nstatic int utf8canon(char *dst, const char *data, int size) {\n int outsz = 0;\n for (int i = 0; i < size;) {\n uint8_t c = data[i];\n uint32_t charCode = c;\n if ((c & 0x80) == 0x00) {\n charCode = c;\n i++;\n } else if ((c & 0xe0) == 0xc0 && i + 1 < size && (data[i + 1] & 0xc0) == 0x80) {\n charCode = ((c & 0x1f) << 6) | (data[i + 1] & 0x3f);\n if (charCode < 0x80)\n goto error;\n else\n i += 2;\n } else if ((c & 0xf0) == 0xe0 && i + 2 < size && (data[i + 1] & 0xc0) == 0x80 &&\n (data[i + 2] & 0xc0) == 0x80) {\n charCode = ((c & 0x0f) << 12) | (data[i + 1] & 0x3f) << 6 | (data[i + 2] & 0x3f);\n // don't exclude surrogate pairs, since we're generating them\n if (charCode < 0x800 /*|| (0xd800 <= charCode && charCode <= 0xdfff)*/)\n goto error;\n else\n i += 3;\n } else if ((c & 0xf8) == 0xf0 && i + 3 < size && (data[i + 1] & 0xc0) == 0x80 &&\n (data[i + 2] & 0xc0) == 0x80 && (data[i + 3] & 0xc0) == 0x80) {\n charCode = ((c & 0x07) << 18) | (data[i + 1] & 0x3f) << 12 | (data[i + 2] & 0x3f) << 6 |\n (data[i + 3] & 0x3f);\n if (charCode < 0x10000 || charCode > 0x10ffff)\n goto error;\n else\n i += 4;\n } else {\n goto error;\n }\n\n if (charCode < 0x80) {\n outsz += 1;\n if (dst)\n *dst++ = charCode;\n } else if (charCode < 0x800) {\n outsz += 2;\n dst = write2byte(dst, charCode);\n } else if (charCode < 0x10000) {\n outsz += 3;\n dst = write3byte(dst, charCode);\n } else {\n outsz += 6; // a surrogate pair\n charCode -= 0x10000;\n dst = write3byte(dst, 0xd800 + (charCode >> 10));\n dst = write3byte(dst, 0xdc00 + (charCode & 0x3ff));\n }\n\n continue;\n\n error:\n i++;\n outsz += 2;\n dst = write2byte(dst, c);\n }\n return outsz;\n}\n\nstatic int utf8CharCode(const char *data) {\n unsigned char c = *data;\n if ((c & 0x80) == 0) {\n return c;\n } else if ((c & 0xe0) == 0xc0) {\n return ((c & 0x1f) << 6) | (data[1] & 0x3f);\n } else if ((c & 0xf0) == 0xe0) {\n return ((c & 0x0f) << 12) | (data[1] & 0x3f) << 6 | (data[2] & 0x3f);\n } else {\n return c; // error\n }\n}\n\nstatic bool isUTF8(const char *data, int len) {\n for (int i = 0; i < len; ++i) {\n if (data[i] & 0x80)\n return true;\n }\n return false;\n}\n\nstatic void setupSkipList(String r, const char *data, int packed) {\n char *dst = (char *)(packed ? PXT_SKIP_DATA_PACK(r) : PXT_SKIP_DATA_IND(r));\n auto len = r->skip.size;\n if (data)\n memcpy(dst, data, len);\n #pragma GCC diagnostic push\n #pragma GCC diagnostic ignored \"-Wstringop-overflow\"\n dst[len] = 0;\n #pragma GCC diagnostic pop\n const char *ptr = dst;\n auto skipEntries = PXT_NUM_SKIP_ENTRIES(r);\n auto lst = packed ? r->skip_pack.list : r->skip.list;\n for (int i = 0; i < skipEntries; ++i) {\n ptr = utf8Skip(ptr, (int)(len - (ptr - dst)), PXT_STRING_SKIP_INCR);\n if (!ptr)\n oops(80);\n lst[i] = ptr - dst;\n }\n}\n#endif\n\nString mkStringCore(const char *data, int len) {\n if (len < 0)\n len = (int)strlen(data);\n if (len == 0)\n return (String)emptyString;\n\n auto vt = &string_inline_ascii_vt;\n String r;\n\n#if PXT_UTF8\n if (data && isUTF8(data, len)) {\n vt = len >= PXT_STRING_MIN_SKIP ? &string_skiplist16_packed_vt : &string_inline_utf8_vt;\n }\n if (vt == &string_skiplist16_packed_vt) {\n int ulen = utf8Len(data, len);\n r = new (gcAllocate(sizeof(void *) + 2 + 2 + (ulen / PXT_STRING_SKIP_INCR) * 2 + len + 1))\n BoxedString(vt);\n r->skip_pack.size = len;\n r->skip_pack.length = ulen;\n setupSkipList(r, data, 1);\n } else\n#endif\n {\n // for ASCII and UTF8 the layout is the same\n r = new (gcAllocate(sizeof(void *) + 2 + len + 1)) BoxedString(vt);\n r->ascii.length = len;\n if (data)\n memcpy(r->ascii.data, data, len);\n r->ascii.data[len] = 0;\n }\n\n MEMDBG(\"mkString: len=%d => %p\", len, r);\n return r;\n}\n\nString mkString(const char *data, int len) {\n#if PXT_UTF8\n if (len < 0)\n len = (int)strlen(data);\n if (len == 0)\n return (String)emptyString;\n\n int sz = utf8canon(NULL, data, len);\n if (sz == len)\n return mkStringCore(data, len);\n // this could be optimized, but it only kicks in when the string isn't valid utf8\n // (or we need to introduce surrogate pairs) which is unlikely to be performance critical\n char *tmp = (char *)app_alloc(sz);\n utf8canon(tmp, data, len);\n auto r = mkStringCore(tmp, sz);\n app_free(tmp);\n return r;\n#else\n return mkStringCore(data, len);\n#endif\n}\n\n#if PXT_UTF8\n// This converts surrogate pairs, which are encoded as 2 characters of 3 bytes each\n// into a proper 4 byte utf-8 character.\nuint32_t toRealUTF8(String str, uint8_t *dst) {\n auto src = str->getUTF8Data();\n auto len = str->getUTF8Size();\n auto dlen = 0;\n\n for (unsigned i = 0; i < len; ++i) {\n if ((uint8_t)src[i] == 0xED && i + 5 < len) {\n auto c0 = utf8CharCode(src + i);\n auto c1 = utf8CharCode(src + i + 3);\n if (0xd800 <= c0 && c0 < 0xdc00 && 0xdc00 <= c1 && c1 < 0xe000) {\n i += 5;\n auto charCode = ((c0 - 0xd800) << 10) + (c1 - 0xdc00) + 0x10000;\n if (dst) {\n dst[dlen] = 0xf0 | (charCode >> 18);\n dst[dlen + 1] = 0x80 | (0x3f & (charCode >> 12));\n dst[dlen + 2] = 0x80 | (0x3f & (charCode >> 6));\n dst[dlen + 3] = 0x80 | (0x3f & (charCode >> 0));\n }\n dlen += 4;\n }\n } else {\n if (dst)\n dst[dlen] = src[i];\n dlen++;\n }\n }\n return dlen;\n}\n#endif\n\nBuffer mkBuffer(const void *data, int len) {\n if (len <= 0)\n return (Buffer)emptyBuffer;\n Buffer r = new (gcAllocate(sizeof(BoxedBuffer) + len)) BoxedBuffer();\n r->length = len;\n if (data)\n memcpy(r->data, data, len);\n else\n memset(r->data, 0, len);\n MEMDBG(\"mkBuffer: len=%d => %p\", len, r);\n return r;\n}\n\nstatic unsigned random_value = 0xC0DA1;\n\n//%\nvoid seedRandom(unsigned seed) {\n random_value = seed;\n}\n\n//% expose\nvoid seedAddRandom(unsigned seed) {\n random_value ^= 0xCA2557CB * seed;\n}\n\nunsigned getRandom(unsigned max) {\n unsigned m, result;\n\n do {\n m = (unsigned)max;\n result = 0;\n\n do {\n // Cycle the LFSR (Linear Feedback Shift Register).\n // We use an optimal sequence with a period of 2^32-1, as defined by Bruce Schneier here\n // (a true legend in the field!),\n // For those interested, it's documented in his paper:\n // \"Pseudo-Random Sequence Generator for 32-Bit CPUs: A fast, machine-independent\n // generator for 32-bit Microprocessors\"\n // https://www.schneier.com/paper-pseudorandom-sequence.html\n unsigned r = random_value;\n\n r = ((((r >> 31) ^ (r >> 6) ^ (r >> 4) ^ (r >> 2) ^ (r >> 1) ^ r) & 1) << 31) |\n (r >> 1);\n\n random_value = r;\n\n result = ((result << 1) | (r & 0x00000001));\n } while (m >>= 1);\n } while (result > (unsigned)max);\n\n return result;\n}\n\nTNumber BoxedString::charCodeAt(int pos) {\n#if PXT_UTF8\n auto ptr = this->getUTF8DataAt(pos);\n if (!ptr)\n return TAG_NAN;\n auto code = utf8CharCode(ptr);\n if (!code && ptr == this->getUTF8Data() + this->getUTF8Size())\n return TAG_NAN;\n return fromInt(code);\n#else\n if (0 <= pos && pos < this->ascii.length) {\n return fromInt(this->ascii.data[pos]);\n } else {\n return TAG_NAN;\n }\n#endif\n}\n\nPXT_DEF_STRING(sTrue, \"true\")\nPXT_DEF_STRING(sFalse, \"false\")\nPXT_DEF_STRING(sUndefined, \"undefined\")\nPXT_DEF_STRING(sNull, \"null\")\nPXT_DEF_STRING(sObject, \"[Object]\")\nPXT_DEF_STRING(sFunction, \"[Function]\")\nPXT_DEF_STRING(sNaN, \"NaN\")\nPXT_DEF_STRING(sInf, \"Infinity\")\nPXT_DEF_STRING(sMInf, \"-Infinity\")\n} // namespace pxt\n\n#ifndef X86_64\n\nnamespace String_ {\n\n//%\nString mkEmpty() {\n return (String)emptyString;\n}\n\n// TODO support var-args somehow?\n\n//%\nString fromCharCode(int code) {\n#if PXT_UTF8\n char buf[3];\n int len;\n code &= 0xffff; // JS semantics\n if (code < 0x80) {\n buf[0] = code;\n len = 1;\n } else if (code < 0x800) {\n buf[0] = 0xc0 | (code >> 6);\n buf[1] = 0x80 | ((code >> 0) & 0x3f);\n len = 2;\n } else {\n buf[0] = 0xe0 | (code >> 12);\n buf[1] = 0x80 | ((code >> 6) & 0x3f);\n buf[2] = 0x80 | ((code >> 0) & 0x3f);\n len = 3;\n }\n return mkStringCore(buf, len);\n#else\n char buf[] = {(char)code, 0};\n return mkStringCore(buf, 1);\n#endif\n}\n\n//%\nTNumber charCodeAt(String s, int pos) {\n if (!s)\n return TAG_NAN;\n return s->charCodeAt(pos);\n}\n\n//%\nString charAt(String s, int pos) {\n auto v = charCodeAt(s, pos);\n if (v == TAG_NAN)\n return mkEmpty();\n if (!isInt(v))\n oops(81);\n return fromCharCode(numValue(v));\n}\n\n#define IS_CONS(s) ((s)->vtable == &string_cons_vt)\n#define IS_EMPTY(s) ((s) == (String)emptyString)\n\n//%\nString concat(String s, String other) {\n if (!s)\n s = (String)sNull;\n if (!other)\n other = (String)sNull;\n if (IS_EMPTY(s))\n return other;\n if (IS_EMPTY(other))\n return s;\n\n uint32_t lenA, lenB;\n\n#if PXT_UTF8\n if (IS_CONS(s)) {\n // (s->cons.left + s->cons.right) + other = s->cons.left + (s->cons.right + other)\n if (IS_CONS(other) || IS_CONS(s->cons.right))\n goto mkCons;\n auto lenAR = s->cons.right->getUTF8Size();\n lenB = other->getUTF8Size(); // de-consify other\n if (lenAR + lenB > SHORT_CONCAT_STRING)\n goto mkCons;\n // if (s->cons.right + other) is short enough, use associativity\n // to construct a shallower tree; this should keep the live set reasonable\n // when someone decides to construct a long string by concatenating\n // single characters\n\n // allocate [r] first, and keep it alive\n String r = new (gcAllocate(3 * sizeof(void *))) BoxedString(&string_cons_vt);\n registerGCObj(r);\n r->cons.left = s->cons.left;\n // this concat() might trigger GC\n r->cons.right = concat(s->cons.right, other);\n unregisterGCObj(r);\n return r;\n }\n#endif\n\n lenA = s->getUTF8Size();\n lenB = other->getUTF8Size();\n#if PXT_UTF8\n if (lenA + lenB > SHORT_CONCAT_STRING)\n goto mkCons;\n#endif\n String r;\n {\n auto dataA = s->getUTF8Data();\n auto dataB = other->getUTF8Data();\n r = mkStringCore(NULL, lenA + lenB);\n auto dst = (char *)r->getUTF8Data();\n memcpy(dst, dataA, lenA);\n memcpy(dst + lenA, dataB, lenB);\n#if PXT_UTF8\n if (isUTF8(dst, lenA + lenB))\n r->vtable = &string_inline_utf8_vt;\n#endif\n return r;\n }\n\n#if PXT_UTF8\nmkCons:\n r = new (gcAllocate(3 * sizeof(void *))) BoxedString(&string_cons_vt);\n r->cons.left = s;\n r->cons.right = other;\n return r;\n#endif\n}\n\nint compare(String a, String b) {\n if (a == b)\n return 0;\n\n auto lenA = a->getUTF8Size();\n auto lenB = b->getUTF8Size();\n auto dataA = a->getUTF8Data();\n auto dataB = b->getUTF8Data();\n auto len = lenA < lenB ? lenA : lenB;\n\n // this also works for UTF8, provided canonical encoding\n // which is guaranteed by the constructor\n for (unsigned i = 0; i <= len; ++i) {\n unsigned char cA = dataA[i];\n unsigned char cB = dataB[i];\n if (cA == cB)\n continue;\n return cA < cB ? -1 : 1;\n }\n return 0;\n}\n\n//%\nint length(String s) {\n return s->getLength();\n}\n\n#define isspace(c) ((c) == ' ')\n#define iswhitespace(c) \\\n ((c) == 0x09 || (c) == 0x0B || (c) == 0x0C || (c) == 0x20 || (uint8_t)(c) == 0xA0 || \\\n (c) == 0x0A || (c) == 0x0D)\n\nNUMBER mystrtod(const char *p, char **endp) {\n while (iswhitespace(*p))\n p++;\n NUMBER m = 1;\n NUMBER v = 0;\n int dot = 0;\n int hasDigit = 0;\n if (*p == '+')\n p++;\n if (*p == '-') {\n m = -1;\n p++;\n }\n\n while (*p) {\n int c = *p - '0';\n if (0 <= c && c <= 9) {\n v *= 10;\n v += c;\n if (dot)\n m /= 10;\n hasDigit = 1;\n } else if (!dot && *p == '.') {\n dot = 1;\n } else if (!hasDigit) {\n return NAN;\n } else {\n break;\n }\n p++;\n }\n\n v *= m;\n\n if (*p == 'e' || *p == 'E') {\n p++;\n int pw = (int)strtol(p, endp, 10);\n v *= p10(pw);\n } else {\n *endp = (char *)p;\n }\n\n return v;\n}\n\n//%\nTNumber toNumber(String s) {\n // JSCHECK\n char *endptr;\n auto data = s->getUTF8Data();\n NUMBER v = mystrtod(data, &endptr);\n if (v == 0.0 || v == -0.0) {\n // nothing\n } else if (!isnormal(v))\n v = NAN;\n return fromDouble(v);\n}\n\n//%\nString substr(String s, int start, int length) {\n if (length <= 0)\n return mkEmpty();\n auto slen = (int)s->getLength();\n if (start < 0)\n start = pxt::max(slen + start, 0);\n length = pxt::min(length, slen - start);\n if (length <= 0)\n return mkEmpty();\n auto p = s->getUTF8DataAt(start);\n#if PXT_UTF8\n auto ep = s->getUTF8DataAt(start + length);\n if (ep == NULL)\n oops(82);\n return mkStringCore(p, (int)(ep - p));\n#else\n return mkStringCore(p, length);\n#endif\n}\n\n//%\nint indexOf(String s, String searchString, int start) {\n if (!s || !searchString)\n return -1;\n\n if (start < 0)\n start = 0;\n\n auto dataA0 = s->getUTF8Data();\n auto dataA = s->getUTF8DataAt(start);\n auto offset = dataA - dataA0;\n auto lenA = s->getUTF8Size() - offset;\n auto lenB = searchString->getUTF8Size();\n\n if (dataA == NULL || lenB > lenA)\n return -1;\n\n auto dataB = searchString->getUTF8Data();\n auto firstB = dataB[0];\n while (lenA >= lenB) {\n if (*dataA == firstB && !memcmp(dataA, dataB, lenB))\n#if PXT_UTF8\n return utf8Len(dataA0, (int)(dataA - dataA0));\n#else\n return dataA - dataA0;\n#endif\n dataA++;\n lenA--;\n }\n return -1;\n}\n\n//%\nint includes(String s, String searchString, int start) {\n return -1 != indexOf(s, searchString, start);\n}\n\n} // namespace String_\n\nnamespace Boolean_ {\n//%\nbool bang(bool v) {\n return v == 0;\n}\n} // namespace Boolean_\n\nnamespace pxt {\n\n// ES5 9.5, 9.6\nunsigned toUInt(TNumber v) {\n if (isInt(v))\n return numValue(v);\n if (isSpecial(v)) {\n if ((intptr_t)v >> 6)\n return 1;\n else\n return 0;\n }\n if (!v)\n return 0;\n\n NUMBER num = toDouble(v);\n if (!isnormal(num))\n return 0;\n#ifdef PXT_USE_FLOAT\n float rem = fmodf(truncf(num), 4294967296.0);\n#else\n double rem = fmod(trunc(num), 4294967296.0);\n#endif\n if (rem < 0.0)\n rem += 4294967296.0;\n return (unsigned)rem;\n}\nint toInt(TNumber v) {\n return (int)toUInt(v);\n}\n\nNUMBER toDouble(TNumber v) {\n if (v == TAG_NAN || v == TAG_UNDEFINED)\n return NAN;\n if (isTagged(v))\n return toInt(v);\n\n#ifdef PXT64\n if (isDouble(v))\n return doubleVal(v);\n#endif\n\n ValType t = valType(v);\n\n#ifndef PXT64\n if (t == ValType::Number) {\n BoxedNumber *p = (BoxedNumber *)v;\n return p->num;\n }\n#endif\n\n if (t == ValType::String) {\n // TODO avoid allocation\n auto tmp = String_::toNumber((String)v);\n auto r = toDouble(tmp);\n return r;\n } else {\n return NAN;\n }\n}\n\nfloat toFloat(TNumber v) {\n if (v == TAG_NAN || v == TAG_UNDEFINED)\n return NAN;\n // optimize for the int case - this will avoid software conversion when FPU is present\n if (isTagged(v))\n return toInt(v);\n return (float)toDouble(v);\n}\n\n#if !defined(PXT_HARD_FLOAT) && !defined(PXT_USE_FLOAT)\nunion NumberConv {\n double v;\n struct {\n uint32_t word0;\n uint32_t word1;\n };\n};\n\nstatic inline TValue doubleToInt(double x) {\n NumberConv cnv;\n cnv.v = x;\n\n if (cnv.word1 == 0 && cnv.word0 == 0)\n return TAG_NUMBER(0);\n\n auto ex = (int)((cnv.word1 << 1) >> 21) - 1023;\n\n // DMESG(\"v=%d/1000 %p %p %d\", (int)(x * 1000), cnv.word0, cnv.word1, ex);\n\n if (ex < 0 || ex > 29) {\n // the 'MININT' case\n if (ex == 30 && cnv.word0 == 0 && cnv.word1 == 0xC1D00000)\n return (TValue)(0x80000001);\n return NULL;\n }\n\n int32_t r;\n\n if (ex <= 20) {\n if (cnv.word0)\n return TAG_UNDEFINED;\n if (cnv.word1 << (ex + 12))\n return TAG_UNDEFINED;\n r = ((cnv.word1 << 11) | 0x80000000) >> (20 - ex + 11);\n } else {\n if (cnv.word0 << (ex - 20))\n return TAG_UNDEFINED;\n r = ((cnv.word1 << 11) | 0x80000000) >> (20 - ex + 11);\n r |= cnv.word0 >> (32 - (ex - 20));\n }\n\n if (cnv.word1 >> 31)\n return TAG_NUMBER(-r);\n else\n return TAG_NUMBER(r);\n}\n#else\nstatic inline TValue doubleToInt(NUMBER r) {\n#ifdef PXT64\n if ((int)r == r)\n return TAG_NUMBER((int)r);\n#else\n int ri = ((int)r) << 1;\n if ((ri >> 1) == r)\n return (TNumber)(uintptr_t)(ri | 1);\n#endif\n return TAG_UNDEFINED;\n}\n#endif\n\nTNumber fromDouble(NUMBER r) {\n#ifndef PXT_BOX_DEBUG\n auto i = doubleToInt(r);\n if (i)\n return i;\n#endif\n if (isnan(r))\n return TAG_NAN;\n#ifdef PXT64\n return tvalueFromDouble(r);\n#else\n BoxedNumber *p = NEW_GC(BoxedNumber);\n p->num = r;\n MEMDBG(\"mkNum: %d/1000 => %p\", (int)(r * 1000), p);\n return (TNumber)p;\n#endif\n}\n\nTNumber fromFloat(float r) {\n // TODO optimize\n return fromDouble(r);\n}\n\nTNumber fromInt(int v) {\n if (canBeTagged(v))\n return TAG_NUMBER(v);\n return fromDouble(v);\n}\n\nTNumber fromUInt(unsigned v) {\n#ifndef PXT_BOX_DEBUG\n if (v <= 0x3fffffff)\n return TAG_NUMBER(v);\n#endif\n return fromDouble(v);\n}\n\nTValue fromBool(bool v) {\n if (v)\n return TAG_TRUE;\n else\n return TAG_FALSE;\n}\n\nTNumber eqFixup(TNumber v) {\n if (v == TAG_NULL)\n return TAG_UNDEFINED;\n if (v == TAG_TRUE)\n return TAG_NUMBER(1);\n if (v == TAG_FALSE)\n return TAG_NUMBER(0);\n return v;\n}\n\nstatic inline bool eq_core(TValue a, TValue b, ValType ta) {\n#ifndef PXT_BOX_DEBUG\n auto aa = (intptr_t)a;\n auto bb = (intptr_t)b;\n\n // if at least one of the values is tagged, they are not equal\n if ((aa | bb) & 3)\n return false;\n#endif\n\n if (ta == ValType::String)\n return String_::compare((String)a, (String)b) == 0;\n else if (ta == ValType::Number)\n return toDouble(a) == toDouble(b);\n else\n return a == b;\n}\n\nbool eqq_bool(TValue a, TValue b) {\n if (a == TAG_NAN || b == TAG_NAN)\n return false;\n\n if (a == b)\n return true;\n\n if (bothNumbers(a, b))\n return false;\n\n ValType ta = valType(a);\n ValType tb = valType(b);\n\n if (ta != tb)\n return false;\n\n return eq_core(a, b, ta);\n}\n\nbool eq_bool(TValue a, TValue b) {\n if (a == TAG_NAN || b == TAG_NAN)\n return false;\n\n if (eqFixup(a) == eqFixup(b))\n return true;\n\n if (bothNumbers(a, b))\n return false;\n\n ValType ta = valType(a);\n ValType tb = valType(b);\n\n if ((ta == ValType::String && tb == ValType::Number) ||\n (tb == ValType::String && ta == ValType::Number))\n return toDouble(a) == toDouble(b);\n\n if (ta == ValType::Boolean) {\n a = eqFixup(a);\n ta = ValType::Number;\n }\n if (tb == ValType::Boolean) {\n b = eqFixup(b);\n tb = ValType::Number;\n }\n\n if (ta != tb)\n return false;\n\n return eq_core(a, b, ta);\n}\n\n// TODO move to assembly\n//%\nbool switch_eq(TValue a, TValue b) {\n if (eq_bool(a, b)) {\n return true;\n }\n return false;\n}\n\n} // namespace pxt\n\n#define NUMOP(op) return fromDouble(toDouble(a) op toDouble(b));\n#define BITOP(op) return fromInt(toInt(a) op toInt(b));\nnamespace numops {\n\nint toBool(TValue v) {\n if (isTagged(v)) {\n if (v == TAG_FALSE || v == TAG_UNDEFINED || v == TAG_NAN || v == TAG_NULL ||\n v == TAG_NUMBER(0))\n return 0;\n else\n return 1;\n }\n\n ValType t = valType(v);\n if (t == ValType::String) {\n String s = (String)v;\n if (IS_EMPTY(s))\n return 0;\n } else if (t == ValType::Number) {\n auto x = toDouble(v);\n if (isnan(x) || x == 0.0 || x == -0.0)\n return 0;\n else\n return 1;\n }\n\n return 1;\n}\n\nint toBoolDecr(TValue v) {\n if (v == TAG_TRUE)\n return 1;\n if (v == TAG_FALSE)\n return 0;\n return toBool(v);\n}\n\n// The integer, non-overflow case for add/sub/bit opts is handled in assembly\n\n#ifdef PXT_VM\n#define NUMOP2(op) \\\n if (bothNumbers(a, b)) { \\\n auto tmp = (int64_t)numValue(a) op(int64_t) numValue(b); \\\n if ((int)tmp == tmp) \\\n return TAG_NUMBER((int)tmp); \\\n } \\\n NUMOP(op)\n#else\n#define NUMOP2(op) NUMOP(op)\n#endif\n\n//%\nTNumber adds(TNumber a, TNumber b){NUMOP2(+)}\n\n//%\nTNumber subs(TNumber a, TNumber b){NUMOP2(-)}\n\n//%\nTNumber muls(TNumber a, TNumber b) {\n if (bothNumbers(a, b)) {\n#ifdef PXT64\n auto tmp = (int64_t)numValue(a) * (int64_t)numValue(b);\n if ((int)tmp == tmp)\n return TAG_NUMBER((int)tmp);\n#else\n int aa = (int)a;\n int bb = (int)b;\n // if both operands fit 15 bits, the result will not overflow int\n if ((aa >> 15 == 0 || aa >> 15 == -1) && (bb >> 15 == 0 || bb >> 15 == -1)) {\n // it may overflow 31 bit int though - use fromInt to convert properly\n return fromInt((aa >> 1) * (bb >> 1));\n }\n#endif\n }\n NUMOP(*)\n}\n\n//%\nTNumber div(TNumber a, TNumber b) {\n if (b == TAG_NUMBER(1))\n return a;\n NUMOP(/)\n}\n\n//%\nTNumber mod(TNumber a, TNumber b) {\n if (isInt(a) && isInt(b) && numValue(b))\n BITOP(%)\n return fromDouble(fmod(toDouble(a), toDouble(b)));\n}\n\n//%\nTNumber lsls(TNumber a, TNumber b) {\n return fromInt(toInt(a) << (toInt(b) & 0x1f));\n}\n\n//%\nTNumber lsrs(TNumber a, TNumber b) {\n return fromUInt(toUInt(a) >> (toUInt(b) & 0x1f));\n}\n\n//%\nTNumber asrs(TNumber a, TNumber b) {\n return fromInt(toInt(a) >> (toInt(b) & 0x1f));\n}\n\n//%\nTNumber eors(TNumber a, TNumber b){BITOP(^)}\n\n//%\nTNumber orrs(TNumber a, TNumber b){BITOP(|)}\n\n//%\nTNumber bnot(TNumber a) {\n return fromInt(~toInt(a));\n}\n\n//%\nTNumber ands(TNumber a, TNumber b) {\n BITOP(&)\n}\n\n#ifdef PXT64\n#define CMPOP_RAW(op, t, f) \\\n if (bothNumbers(a, b)) \\\n return numValue(a) op numValue(b) ? t : f; \\\n int cmp = valCompare(a, b); \\\n return cmp != -2 && cmp op 0 ? t : f;\n#else\n#define CMPOP_RAW(op, t, f) \\\n if (bothNumbers(a, b)) \\\n return (intptr_t)a op((intptr_t)b) ? t : f; \\\n int cmp = valCompare(a, b); \\\n return cmp != -2 && cmp op 0 ? t : f;\n#endif\n\n#define CMPOP(op) CMPOP_RAW(op, TAG_TRUE, TAG_FALSE)\n\n// 7.2.13 Abstract Relational Comparison\nstatic int valCompare(TValue a, TValue b) {\n if (a == TAG_NAN || b == TAG_NAN)\n return -2;\n\n ValType ta = valType(a);\n ValType tb = valType(b);\n\n if (ta == ValType::String && tb == ValType::String)\n return String_::compare((String)a, (String)b);\n\n if (a == b)\n return 0;\n\n auto da = toDouble(a);\n auto db = toDouble(b);\n\n if (isnan(da) || isnan(db))\n return -2;\n\n if (da < db)\n return -1;\n else if (da > db)\n return 1;\n else\n return 0;\n}\n\n//%\nbool lt_bool(TNumber a, TNumber b){CMPOP_RAW(<, true, false)}\n\n//%\nTNumber le(TNumber a, TNumber b){CMPOP(<=)}\n\n//%\nTNumber lt(TNumber a, TNumber b){CMPOP(<)}\n\n//%\nTNumber ge(TNumber a, TNumber b){CMPOP(>=)}\n\n//%\nTNumber gt(TNumber a, TNumber b){CMPOP(>)}\n\n//%\nTNumber eq(TNumber a, TNumber b) {\n return pxt::eq_bool(a, b) ? TAG_TRUE : TAG_FALSE;\n}\n\n//%\nTNumber neq(TNumber a, TNumber b) {\n return !pxt::eq_bool(a, b) ? TAG_TRUE : TAG_FALSE;\n}\n\n//%\nTNumber eqq(TNumber a, TNumber b) {\n return pxt::eqq_bool(a, b) ? TAG_TRUE : TAG_FALSE;\n}\n\n//%\nTNumber neqq(TNumber a, TNumber b) {\n return !pxt::eqq_bool(a, b) ? TAG_TRUE : TAG_FALSE;\n}\n\n// How many significant digits mycvt() should output.\n// This cannot be more than 15, as this is the most that can be accurately represented\n// in 64 bit double. Otherwise this code may crash.\n#define DIGITS 15\n\nstatic const uint64_t pows[] = {\n 1LL, 10LL, 100LL, 1000LL, 10000LL,\n 100000LL, 1000000LL, 10000000LL, 100000000LL, 1000000000LL,\n 10000000000LL, 100000000000LL, 1000000000000LL, 10000000000000LL, 100000000000000LL,\n};\n\n// The basic idea is we convert d to a 64 bit integer with DIGITS\n// digits, and then print it out, putting dot in the right place.\n\nvoid mycvt(NUMBER d, char *buf) {\n if (d < 0) {\n *buf++ = '-';\n d = -d;\n }\n\n if (!d) {\n *buf++ = '0';\n *buf++ = 0;\n return;\n }\n\n int pw = (int)log10(d);\n int e = 1;\n\n // if outside 1e-6 -- 1e21 range, we use the e-notation\n if (d < 1e-6 || d > 1e21) {\n // normalize number to 1.XYZ, save e, and reset pw\n if (pw < 0)\n d *= p10(-pw);\n else\n d /= p10(pw);\n e = pw;\n pw = 0;\n }\n\n int trailingZ = 0;\n int dotAfter = pw + 1; // at which position the dot should be in the number\n\n uint64_t dd;\n\n // normalize number to be integer with exactly DIGITS digits\n if (pw >= DIGITS) {\n // if the number is larger than DIGITS, we need trailing zeroes\n trailingZ = pw - DIGITS + 1;\n dd = (uint64_t)(d / p10(trailingZ) + 0.5);\n } else {\n dd = (uint64_t)(d * p10(DIGITS - pw - 1) + 0.5);\n }\n\n // if number is less than 1, we need 0.00...00 at the beginning\n if (dotAfter < 1) {\n *buf++ = '0';\n *buf++ = '.';\n int n = -dotAfter;\n while (n--)\n *buf++ = '0';\n }\n\n // now print out the actual number\n for (int i = DIGITS - 1; i >= 0; i--) {\n uint64_t q = pows[i];\n // this may be faster than fp-division and fmod(); or maybe not\n // anyways, it works\n int k = '0';\n while (dd >= q) {\n dd -= q;\n k++;\n }\n *buf++ = k;\n // if we're after dot, and what's left is zeroes, stop\n if (dd == 0 && (DIGITS - i) >= dotAfter)\n break;\n // print the dot, if we arrived at it\n if ((DIGITS - i) == dotAfter)\n *buf++ = '.';\n }\n\n // print out remaining trailing zeroes if any\n while (trailingZ-- > 0)\n *buf++ = '0';\n\n // if we used e-notation, handle that\n if (e != 1) {\n *buf++ = 'e';\n if (e > 0)\n *buf++ = '+';\n itoa(e, buf);\n } else {\n *buf = 0;\n }\n}\n\n#if 0\n//%\nTValue floatAsInt(TValue x) {\n return doubleToInt(toDouble(x));\n}\n\n//% shim=numops::floatAsInt\nfunction floatAsInt(v: number): number { return 0 }\n\nfunction testInt(i: number) {\n if (floatAsInt(i) != i)\n control.panic(101)\n if (floatAsInt(i + 0.5) != null)\n control.panic(102)\n if (floatAsInt(i + 0.00001) != null)\n control.panic(103)\n}\n\nfunction testFloat(i: number) {\n if (floatAsInt(i) != null)\n control.panic(104)\n}\n\nfunction testFloatAsInt() {\n for (let i = 0; i < 0xffff; ++i) {\n testInt(i)\n testInt(-i)\n testInt(i * 10000)\n testInt(i << 12)\n testInt(i + 0x3fff0001)\n testInt(-i - 0x3fff0002)\n testFloat(i + 0x3fffffff + 1)\n testFloat((i + 10000) * 1000000)\n }\n}\n#endif\n\nString toString(TValue v) {\n ValType t = valType(v);\n\n if (t == ValType::String) {\n return (String)v;\n } else if (t == ValType::Number) {\n char buf[64];\n\n if (isInt(v)) {\n itoa(numValue(v), buf);\n return mkStringCore(buf);\n }\n\n if (v == TAG_NAN)\n return (String)(void *)sNaN;\n\n auto x = toDouble(v);\n\n#ifdef PXT_BOX_DEBUG\n if (x == (int)x) {\n itoa((int)x, buf);\n return mkStringCore(buf);\n }\n#endif\n\n if (isinf(x)) {\n if (x < 0)\n return (String)(void *)sMInf;\n else\n return (String)(void *)sInf;\n } else if (isnan(x)) {\n return (String)(void *)sNaN;\n }\n mycvt(x, buf);\n\n return mkStringCore(buf);\n } else if (t == ValType::Function) {\n return (String)(void *)sFunction;\n } else {\n if (v == TAG_UNDEFINED)\n return (String)(void *)sUndefined;\n else if (v == TAG_FALSE)\n return (String)(void *)sFalse;\n else if (v == TAG_NAN)\n return (String)(void *)sNaN;\n else if (v == TAG_TRUE)\n return (String)(void *)sTrue;\n else if (v == TAG_NULL)\n return (String)(void *)sNull;\n return (String)(void *)sObject;\n }\n}\n\n} // namespace numops\n\nnamespace Math_ {\n//%\nTNumber pow(TNumber x, TNumber y) {\n#ifdef PXT_POWI\n // regular pow() from math.h is 4k of code\n return fromDouble(__builtin_powi(toDouble(x), toInt(y)));\n#else\n return fromDouble(::pow(toDouble(x), toDouble(y)));\n#endif\n}\n\nNUMBER randomDouble() {\n return getRandom(UINT_MAX) / ((NUMBER)UINT_MAX + 1) +\n getRandom(0xffffff) / ((NUMBER)UINT_MAX * 0xffffff);\n}\n\n//%\nTNumber random() {\n return fromDouble(randomDouble());\n}\n\n//%\nTNumber randomRange(TNumber min, TNumber max) {\n if (isInt(min) && isInt(max)) {\n int mini = numValue(min);\n int maxi = numValue(max);\n if (mini > maxi) {\n int temp = mini;\n mini = maxi;\n maxi = temp;\n }\n if (maxi == mini)\n return fromInt(mini);\n else\n return fromInt(mini + getRandom(maxi - mini));\n } else {\n auto mind = toDouble(min);\n auto maxd = toDouble(max);\n if (mind > maxd) {\n auto temp = mind;\n mind = maxd;\n maxd = temp;\n }\n if (maxd == mind)\n return fromDouble(mind);\n else {\n return fromDouble(mind + randomDouble() * (maxd - mind));\n }\n }\n}\n\n#define SINGLE(op) return fromDouble(::op(toDouble(x)));\n\n//%\nTNumber log(TNumber x){SINGLE(log)}\n\n//%\nTNumber log10(TNumber x){SINGLE(log10)}\n\n//%\nTNumber floor(TNumber x){SINGLE(floor)}\n\n//%\nTNumber ceil(TNumber x){SINGLE(ceil)}\n\n//%\nTNumber trunc(TNumber x){SINGLE(trunc)}\n\n//%\nTNumber round(TNumber x) {\n // In C++, round(-1.5) == -2, while in JS, round(-1.5) == -1. Align to the JS convention for\n // consistency between simulator and device. The following does rounding with ties (x.5) going\n // towards positive infinity.\n return fromDouble(::floor(toDouble(x) + 0.5));\n}\n\n//%\nint imul(int x, int y) {\n return x * y;\n}\n\n//%\nint idiv(int x, int y) {\n return x / y;\n}\n} // namespace Math_\n\nnamespace Array_ {\nRefCollection *mk() {\n auto r = NEW_GC(RefCollection);\n MEMDBG(\"mkColl: => %p\", r);\n return r;\n}\nint length(RefCollection *c) {\n return c->length();\n}\nvoid setLength(RefCollection *c, int newLength) {\n c->setLength(newLength);\n}\nvoid push(RefCollection *c, TValue x) {\n c->head.push(x);\n}\nTValue pop(RefCollection *c) {\n return c->head.pop();\n}\nTValue getAt(RefCollection *c, int x) {\n return c->head.get(x);\n}\nvoid setAt(RefCollection *c, int x, TValue y) {\n c->head.set(x, y);\n}\nTValue removeAt(RefCollection *c, int x) {\n return c->head.remove(x);\n}\nvoid insertAt(RefCollection *c, int x, TValue value) {\n c->head.insert(x, value);\n}\nint indexOf(RefCollection *c, TValue x, int start) {\n auto data = c->head.getData();\n auto len = c->head.getLength();\n for (unsigned i = 0; i < len; i++) {\n if (pxt::eq_bool(data[i], x)) {\n return (int)i;\n }\n }\n return -1;\n}\nbool removeElement(RefCollection *c, TValue x) {\n int idx = indexOf(c, x, 0);\n if (idx >= 0) {\n decr(removeAt(c, idx));\n return 1;\n }\n return 0;\n}\n} // namespace Array_\n\nnamespace pxt {\nint debugFlags;\n\n//%\nvoid *ptrOfLiteral(int offset);\n\n#ifdef PXT_VM\nunsigned programSize() {\n return 0;\n}\n#else\n//%\nunsigned programSize() {\n return bytecode[17] * 8;\n}\n#endif\n\nvoid deepSleep() __attribute__((weak));\n//%\nvoid deepSleep() {}\n\nint *getBootloaderConfigData() __attribute__((weak));\nint *getBootloaderConfigData() {\n return NULL;\n}\n\n//%\nint getConfig(int key, int defl) {\n#ifdef PXT_VM\n if (!vmImg)\n return defl;\n int *cfgData = vmImg->configData;\n#else\n int *cfgData = bytecode ? *(int **)&bytecode[18] : NULL;\n#endif\n\n if (cfgData) {\n for (int i = 0;; i += 2) {\n if (cfgData[i] == key)\n return cfgData[i + 1];\n if (cfgData[i] == 0)\n break;\n }\n }\n\n cfgData = getBootloaderConfigData();\n\n if (cfgData) {\n for (int i = 0;; i += 2) {\n if (cfgData[i] == key)\n return cfgData[i + 1];\n if (cfgData[i] == 0)\n break;\n }\n }\n\n return defl;\n}\n\n} // namespace pxt\n\nnamespace pxtrt {\n//%\nTValue ldlocRef(RefRefLocal *r) {\n return r->v;\n}\n\n//%\nvoid stlocRef(RefRefLocal *r, TValue v) {\n r->v = v;\n}\n\n//%\nRefRefLocal *mklocRef() {\n auto r = NEW_GC(RefRefLocal);\n MEMDBG(\"mklocRef: => %p\", r);\n return r;\n}\n\n// Store a captured local in a closure. It returns the action, so it can be chained.\n//%\nRefAction *stclo(RefAction *a, int idx, TValue v) {\n // DBG(\"STCLO \"); a->print(); DBG(\"@%d = %p\\n\", idx, (void*)v);\n a->stCore(idx, v);\n return a;\n}\n\n//%\nvoid panic(int code) {\n soft_panic(code);\n}\n\n//%\nString emptyToNull(String s) {\n if (!s || IS_EMPTY(s))\n return NULL;\n return s;\n}\n\n//%\nint ptrToBool(TValue p) {\n if (p) {\n decr(p);\n return 1;\n } else {\n return 0;\n }\n}\n\nRefMap *mkMap() {\n auto r = NEW_GC(RefMap);\n MEMDBG(\"mkMap: => %p\", r);\n return r;\n}\n\nTValue mapGetByString(RefMap *map, String key) {\n int i = map->findIdx(key);\n if (i < 0) {\n return 0;\n }\n return map->values.get(i);\n}\n\n#ifdef PXT_VM\n#define IFACE_MEMBER_NAMES vmImg->ifaceMemberNames\n#else\n#define IFACE_MEMBER_NAMES *(uintptr_t **)&bytecode[22]\n#endif\n\nint lookupMapKey(String key) {\n auto arr = IFACE_MEMBER_NAMES;\n auto len = *arr++;\n int l = 1U; // skip index 0 - it's invalid\n int r = (int)len - 1;\n auto ikey = (uintptr_t)key;\n if (arr[l] <= ikey && ikey <= arr[r]) {\n while (l <= r) {\n auto m = (l + r) >> 1;\n if (arr[m] == ikey)\n return m;\n else if (arr[m] < ikey)\n l = m + 1;\n else\n r = m - 1;\n }\n } else {\n while (l <= r) {\n int m = (l + r) >> 1;\n auto cmp = String_::compare((String)arr[m], key);\n if (cmp == 0)\n return m;\n else if (cmp < 0)\n l = m + 1;\n else\n r = m - 1;\n }\n }\n return 0;\n}\n\nTValue mapGet(RefMap *map, unsigned key) {\n auto arr = (String *)IFACE_MEMBER_NAMES;\n auto r = mapGetByString(map, arr[key + 1]);\n map->unref();\n return r;\n}\n\nvoid mapSetByString(RefMap *map, String key, TValue val) {\n int i = map->findIdx(key);\n if (i < 0) {\n map->keys.push((TValue)key);\n map->values.push(val);\n } else {\n map->values.set(i, val);\n }\n}\n\nvoid mapSet(RefMap *map, unsigned key, TValue val) {\n auto arr = (String *)IFACE_MEMBER_NAMES;\n mapSetByString(map, arr[key + 1], val);\n decr(val);\n map->unref();\n}\n\n//\n// Debugger\n//\n\n// This is only to be called once at the beginning of lambda function\n//%\nvoid *getGlobalsPtr() {\n#ifdef DEVICE_GROUP_ID_USER\n fiber_set_group(DEVICE_GROUP_ID_USER);\n#endif\n\n return globals;\n}\n\n//%\nvoid runtimeWarning(String s) {\n // noop for now\n}\n} // namespace pxtrt\n#endif\n\nnamespace pxt {\n\nvoid doNothing() {}\n\n//%\nValType valType(TValue v) {\n if (isTagged(v)) {\n if (!v)\n return ValType::Undefined;\n\n if (isInt(v) || v == TAG_NAN)\n return ValType::Number;\n if (v == TAG_TRUE || v == TAG_FALSE)\n return ValType::Boolean;\n else if (v == TAG_NULL)\n return ValType::Object;\n else {\n oops(1);\n return ValType::Object;\n }\n#ifdef PXT64\n } else if (isDouble(v)) {\n return ValType::Number;\n#endif\n } else {\n auto vt = getVTable((RefObject *)v);\n if (vt->magic == VTABLE_MAGIC)\n return vt->objectType;\n else\n return ValType::Object;\n }\n}\n\nPXT_DEF_STRING(sObjectTp, \"object\")\nPXT_DEF_STRING(sBooleanTp, \"boolean\")\nPXT_DEF_STRING(sStringTp, \"string\")\nPXT_DEF_STRING(sNumberTp, \"number\")\nPXT_DEF_STRING(sFunctionTp, \"function\")\nPXT_DEF_STRING(sUndefinedTp, \"undefined\")\n\n//% expose\nString typeOf(TValue v) {\n switch (valType(v)) {\n case ValType::Undefined:\n return (String)sUndefinedTp;\n case ValType::Boolean:\n return (String)sBooleanTp;\n case ValType::Number:\n return (String)sNumberTp;\n case ValType::String:\n return (String)sStringTp;\n case ValType::Object:\n return (String)sObjectTp;\n case ValType::Function:\n return (String)sFunctionTp;\n default:\n oops(2);\n return 0;\n }\n}\n\n// Maybe in future we will want separate print methods; for now ignore\nvoid anyPrint(TValue v) {\n if (valType(v) == ValType::Object) {\n if (isRefCounted(v)) {\n auto o = (RefObject *)v;\n auto vt = getVTable(o);\n auto meth = ((RefObjectMethod)vt->methods[1]);\n if ((void *)meth == (void *)&anyPrint)\n DMESG(\"[RefObject vt=%p cl=%d sz=%d]\", o->vtable, vt->classNo, vt->numbytes);\n else\n meth(o);\n } else {\n DMESG(\"[Native %p]\", v);\n }\n } else {\n#ifndef X86_64\n String s = numops::toString(v);\n DMESG(\"[%s %p = %s]\", pxt::typeOf(v)->getUTF8Data(), v, s->getUTF8Data());\n decr((TValue)s);\n#endif\n }\n}\n\nstatic void dtorDoNothing() {}\n\n#define PRIM_VTABLE(name, objectTp, tp, szexpr) \\\n static uint32_t name##_size(tp *p) { return TOWORDS(sizeof(tp) + szexpr); } \\\n DEF_VTABLE(name##_vt, tp, objectTp, (void *)&dtorDoNothing, (void *)&anyPrint, 0, \\\n (void *)&name##_size)\n\n#define NOOP ((void)0)\n\n#define STRING_VT(name, fix, scan, gcsize, data, utfsize, length, dataAt) \\\n static uint32_t name##_gcsize(BoxedString *p) { return TOWORDS(sizeof(void *) + (gcsize)); } \\\n static void name##_gcscan(BoxedString *p) { scan; } \\\n static const char *name##_data(BoxedString *p) { \\\n fix; \\\n return data; \\\n } \\\n static uint32_t name##_utfsize(BoxedString *p) { \\\n fix; \\\n return utfsize; \\\n } \\\n static uint32_t name##_length(BoxedString *p) { \\\n fix; \\\n return length; \\\n } \\\n static const char *name##_dataAt(BoxedString *p, uint32_t idx) { \\\n fix; \\\n return dataAt; \\\n } \\\n DEF_VTABLE(name##_vt, BoxedString, ValType::String, (void *)&dtorDoNothing, (void *)&anyPrint, \\\n (void *)&name##_gcscan, (void *)&name##_gcsize, (void *)&name##_data, \\\n (void *)&name##_utfsize, (void *)&name##_length, (void *)&name##_dataAt)\n\nvoid gcMarkArray(void *data);\nvoid gcScan(TValue v);\n\n#if PXT_UTF8\nstatic const char *skipLookup(BoxedString *p, uint32_t idx, int packed) {\n if (idx > p->skip.length)\n return NULL;\n auto ent = idx / PXT_STRING_SKIP_INCR;\n auto data = packed ? PXT_SKIP_DATA_PACK(p) : PXT_SKIP_DATA_IND(p);\n auto size = p->skip.size;\n if (ent) {\n auto off = packed ? p->skip_pack.list[ent - 1] : p->skip.list[ent - 1];\n data += off;\n size -= off;\n idx &= PXT_STRING_SKIP_INCR - 1;\n }\n return utf8Skip(data, size, idx);\n}\n\nextern LLSegment workQueue;\n\nstatic uint32_t fixSize(BoxedString *p, uint32_t *len) {\n uint32_t tlen = 0;\n uint32_t sz = 0;\n if (workQueue.getLength())\n oops(81);\n workQueue.push((TValue)p);\n while (workQueue.getLength()) {\n p = (BoxedString *)workQueue.pop();\n if (IS_CONS(p)) {\n workQueue.push((TValue)p->cons.right);\n workQueue.push((TValue)p->cons.left);\n } else {\n tlen += p->getLength();\n sz += p->getUTF8Size();\n }\n }\n *len = tlen;\n return sz;\n}\n\nstatic void fixCopy(BoxedString *p, char *dst) {\n if (workQueue.getLength())\n oops(81);\n\n workQueue.push((TValue)p);\n while (workQueue.getLength()) {\n p = (BoxedString *)workQueue.pop();\n if (IS_CONS(p)) {\n workQueue.push((TValue)p->cons.right);\n workQueue.push((TValue)p->cons.left);\n } else {\n auto sz = p->getUTF8Size();\n memcpy(dst, p->getUTF8Data(), sz);\n dst += sz;\n }\n }\n}\n\n// switches CONS representation into skip list representation\n// does not switch representation of CONS' children\nstatic void fixCons(BoxedString *r) {\n uint32_t length = 0;\n auto sz = fixSize(r, &length);\n auto numSkips = length / PXT_STRING_SKIP_INCR;\n // allocate first, while [r] still holds references to its children\n // because allocation might trigger GC\n auto data = (uint16_t *)gcAllocateArray(numSkips * 2 + sz + 1);\n // copy, while [r] is still cons\n fixCopy(r, (char *)(data + numSkips));\n // now, set [r] up properly\n r->vtable = &string_skiplist16_vt;\n r->skip.size = sz;\n r->skip.length = length;\n r->skip.list = data;\n setupSkipList(r, NULL, 0);\n}\n#endif\n\nSTRING_VT(string_inline_ascii, NOOP, NOOP, 2 + p->ascii.length + 1, p->ascii.data, p->ascii.length,\n p->ascii.length, idx <= p->ascii.length ? p->ascii.data + idx : NULL)\n#if PXT_UTF8\nSTRING_VT(string_inline_utf8, NOOP, NOOP, 2 + p->utf8.size + 1, p->utf8.data, p->utf8.size,\n utf8Len(p->utf8.data, p->utf8.size), utf8Skip(p->utf8.data, p->utf8.size, idx))\nSTRING_VT(string_skiplist16, NOOP, if (p->skip.list) gcMarkArray(p->skip.list), 2 * sizeof(void *),\n PXT_SKIP_DATA_IND(p), p->skip.size, p->skip.length, skipLookup(p, idx, 0))\nSTRING_VT(string_skiplist16_packed, NOOP, NOOP,\n 2 + 2 + PXT_NUM_SKIP_ENTRIES(p) * 2 + p->skip.size + 1, PXT_SKIP_DATA_PACK(p),\n p->skip.size, p->skip.length, skipLookup(p, idx, 1))\nSTRING_VT(string_cons, fixCons(p), (gcScan((TValue)p->cons.left), gcScan((TValue)p->cons.right)),\n 2 * sizeof(void *), PXT_SKIP_DATA_IND(p), p->skip.size, p->skip.length,\n skipLookup(p, idx, 0))\n#endif\n\nPRIM_VTABLE(number, ValType::Number, BoxedNumber, 0)\nPRIM_VTABLE(buffer, ValType::Object, BoxedBuffer, p->length)\n// PRIM_VTABLE(action, ValType::Function, RefAction, )\n\nvoid failedCast(TValue v, void *addr) {\n DMESG(\"failed type check for %p @%p\", v, addr);\n auto vt = getAnyVTable(v);\n if (vt) {\n DMESG(\"VT %p - objtype %d classNo %d\", vt, vt->objectType, vt->classNo);\n }\n\n int code;\n if (v == TAG_NULL)\n code = PANIC_CAST_FROM_NULL;\n else\n code = PANIC_CAST_FIRST + (int)valType(v);\n soft_panic(code);\n}\n\nvoid missingProperty(TValue v) {\n DMESG(\"missing property on %p\", v);\n soft_panic(PANIC_MISSING_PROPERTY);\n}\n\n#ifdef PXT_PROFILE\nstruct PerfCounter *perfCounters;\n\nstruct PerfCounterInfo {\n uint32_t numPerfCounters;\n char *perfCounterNames[0];\n};\n\n#define PERF_INFO ((PerfCounterInfo *)(((uintptr_t *)bytecode)[13]))\n\nvoid initPerfCounters() {\n auto n = PERF_INFO->numPerfCounters;\n perfCounters = new PerfCounter[n];\n memset(perfCounters, 0, n * sizeof(PerfCounter));\n}\n\nvoid dumpPerfCounters() {\n auto info = PERF_INFO;\n DMESG(\"calls,us,name\");\n for (uint32_t i = 0; i < info->numPerfCounters; ++i) {\n auto c = &perfCounters[i];\n DMESG(\"%d,%d,%s\", c->numstops, c->value, info->perfCounterNames[i]);\n }\n}\n\nvoid startPerfCounter(PerfCounters n) {\n if (!perfCounters)\n return;\n auto c = &perfCounters[(uint32_t)n];\n if (c->start)\n oops(50);\n c->start = PERF_NOW();\n}\n\nvoid stopPerfCounter(PerfCounters n) {\n if (!perfCounters)\n return;\n auto c = &perfCounters[(uint32_t)n];\n if (!c->start)\n oops(51);\n c->value += PERF_NOW() - c->start;\n c->start = 0;\n c->numstops++;\n}\n#endif\n\n// Exceptions\n\n#ifndef PXT_EXN_CTX\n#define PXT_EXN_CTX() getThreadContext()\n#endif\n\ntypedef void (*RestoreStateType)(TryFrame *, ThreadContext *);\n#ifndef pxt_restore_exception_state\n#define pxt_restore_exception_state ((RestoreStateType)(((uintptr_t *)bytecode)[14]))\n#endif\n\n//%\nTryFrame *beginTry() {\n auto ctx = PXT_EXN_CTX();\n auto frame = (TryFrame *)app_alloc(sizeof(TryFrame));\n frame->parent = ctx->tryFrame;\n ctx->tryFrame = frame;\n return frame;\n}\n\n//% expose\nvoid endTry() {\n auto ctx = PXT_EXN_CTX();\n auto f = ctx->tryFrame;\n if (!f)\n oops(51);\n ctx->tryFrame = f->parent;\n app_free(f);\n}\n\n//% expose\nvoid throwValue(TValue v) {\n auto ctx = PXT_EXN_CTX();\n auto f = ctx->tryFrame;\n if (!f) {\n DMESG(\"unhandled exception, value:\");\n anyPrint(v);\n soft_panic(PANIC_UNHANDLED_EXCEPTION);\n }\n ctx->tryFrame = f->parent;\n TryFrame copy = *f;\n app_free(f);\n ctx->thrownValue = v;\n pxt_restore_exception_state(&copy, ctx);\n}\n\n//% expose\nTValue getThrownValue() {\n auto ctx = PXT_EXN_CTX();\n auto v = ctx->thrownValue;\n ctx->thrownValue = TAG_NON_VALUE;\n if (v == TAG_NON_VALUE)\n oops(51);\n return v;\n}\n\n//% expose\nvoid endFinally() {\n auto ctx = PXT_EXN_CTX();\n if (ctx->thrownValue == TAG_NON_VALUE)\n return;\n throwValue(getThrownValue());\n}\n\n// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function\nuint32_t hash_fnv1(const void *data, unsigned len) {\n const uint8_t *d = (const uint8_t *)data;\n uint32_t h = 0x811c9dc5;\n while (len--)\n h = (h * 0x1000193) ^ *d++;\n return h;\n}\n\n// redefined in melody.cpp\n__attribute__((weak)) int redirectSamples(int16_t *dst, int numsamples, int samplerate) {\n return 0;\n}\n\n} // namespace pxt\n",
2731
2731
  "dal.d.ts": "// Auto-generated. Do not edit.\ndeclare const enum DAL {\n // /libraries/codal-core/inc/core/CodalComponent.h\n DEVICE_ID_BUTTON_A = 1,\n DEVICE_ID_BUTTON_B = 2,\n DEVICE_ID_BUTTON_AB = 3,\n DEVICE_ID_BUTTON_RESET = 4,\n DEVICE_ID_ACCELEROMETER = 5,\n DEVICE_ID_COMPASS = 6,\n DEVICE_ID_DISPLAY = 7,\n DEVICE_ID_THERMOMETER = 8,\n DEVICE_ID_RADIO = 9,\n DEVICE_ID_RADIO_DATA_READY = 10,\n DEVICE_ID_MULTIBUTTON_ATTACH = 11,\n DEVICE_ID_SERIAL = 12,\n DEVICE_ID_GESTURE = 13,\n DEVICE_ID_SYSTEM_TIMER = 14,\n DEVICE_ID_SCHEDULER = 15,\n DEVICE_ID_COMPONENT = 16,\n DEVICE_ID_LIGHT_SENSOR = 17,\n DEVICE_ID_TOUCH_SENSOR = 18,\n DEVICE_ID_SYSTEM_DAC = 19,\n DEVICE_ID_SYSTEM_MICROPHONE = 20,\n DEVICE_ID_SYSTEM_LEVEL_DETECTOR = 21,\n DEVICE_ID_SYSTEM_LEVEL_DETECTOR_SPL = 22,\n DEVICE_ID_MSC = 23,\n DEVICE_ID_SPI = 24,\n DEVICE_ID_DISTANCE = 25,\n DEVICE_ID_GYROSCOPE = 26,\n DEVICE_ID_HUMIDITY = 27,\n DEVICE_ID_PRESSURE = 28,\n DEVICE_ID_SINGLE_WIRE_SERIAL = 29,\n DEVICE_ID_JACDAC = 30,\n DEVICE_ID_JACDAC_PHYS = 31,\n DEVICE_ID_JACDAC_CONTROL_SERVICE = 32,\n DEVICE_ID_JACDAC_CONFIGURATION_SERVICE = 33,\n DEVICE_ID_SYSTEM_ADC = 34,\n DEVICE_ID_PULSE_IN = 35,\n DEVICE_ID_USB = 36,\n DEVICE_ID_IO_P0 = 100,\n DEVICE_ID_MESSAGE_BUS_LISTENER = 1021,\n DEVICE_ID_NOTIFY_ONE = 1022,\n DEVICE_ID_NOTIFY = 1023,\n DEVICE_ID_BUTTON_UP = 2000,\n DEVICE_ID_BUTTON_DOWN = 2001,\n DEVICE_ID_BUTTON_LEFT = 2002,\n DEVICE_ID_BUTTON_RIGHT = 2003,\n DEVICE_ID_JD_DYNAMIC_ID = 3000,\n DEVICE_COMPONENT_RUNNING = 4096,\n DEVICE_COMPONENT_STATUS_SYSTEM_TICK = 8192,\n DEVICE_COMPONENT_STATUS_IDLE_TICK = 16384,\n DEVICE_COMPONENT_LISTENERS_CONFIGURED = 1,\n DEVICE_COMPONENT_EVT_SYSTEM_TICK = 1,\n // /libraries/codal-core/inc/core/CodalFiber.h\n DEVICE_SCHEDULER_RUNNING = 1,\n DEVICE_SCHEDULER_IDLE = 2,\n DEVICE_FIBER_FLAG_FOB = 1,\n DEVICE_FIBER_FLAG_PARENT = 2,\n DEVICE_FIBER_FLAG_CHILD = 4,\n DEVICE_FIBER_FLAG_DO_NOT_PAGE = 8,\n DEVICE_SCHEDULER_EVT_TICK = 1,\n DEVICE_SCHEDULER_EVT_IDLE = 2,\n DEVICE_GET_FIBER_LIST_AVAILABLE = 1,\n // /libraries/codal-core/inc/core/CodalListener.h\n MESSAGE_BUS_LISTENER_PARAMETERISED = 1,\n MESSAGE_BUS_LISTENER_METHOD = 2,\n MESSAGE_BUS_LISTENER_BUSY = 4,\n MESSAGE_BUS_LISTENER_REENTRANT = 8,\n MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY = 16,\n MESSAGE_BUS_LISTENER_DROP_IF_BUSY = 32,\n MESSAGE_BUS_LISTENER_NONBLOCKING = 64,\n MESSAGE_BUS_LISTENER_URGENT = 128,\n MESSAGE_BUS_LISTENER_DELETING = 32768,\n MESSAGE_BUS_LISTENER_IMMEDIATE = 192,\n // /libraries/codal-core/inc/core/ErrorNo.h\n DEVICE_OK = 0,\n DEVICE_INVALID_PARAMETER = -1001,\n DEVICE_NOT_SUPPORTED = -1002,\n DEVICE_CALIBRATION_IN_PROGRESS = -1003,\n DEVICE_CALIBRATION_REQUIRED = -1004,\n DEVICE_NO_RESOURCES = -1005,\n DEVICE_BUSY = -1006,\n DEVICE_CANCELLED = -1007,\n DEVICE_I2C_ERROR = -1010,\n DEVICE_SERIAL_IN_USE = -1011,\n DEVICE_NO_DATA = -1012,\n DEVICE_NOT_IMPLEMENTED = -1013,\n DEVICE_SPI_ERROR = -1014,\n DEVICE_INVALID_STATE = -1015,\n DEVICE_OOM = 20,\n DEVICE_HEAP_ERROR = 30,\n DEVICE_NULL_DEREFERENCE = 40,\n DEVICE_USB_ERROR = 50,\n DEVICE_JACDAC_ERROR = 60,\n DEVICE_HARDWARE_CONFIGURATION_ERROR = 90,\n // /libraries/codal-core/inc/core/NotifyEvents.h\n DISPLAY_EVT_FREE = 1,\n CODAL_SERIAL_EVT_TX_EMPTY = 2,\n BLE_EVT_SERIAL_TX_EMPTY = 3,\n ARCADE_PLAYER_JOIN_RESULT = 4,\n DEVICE_NOTIFY_USER_EVENT_BASE = 1024,\n // /libraries/codal-core/inc/driver-models/AbstractButton.h\n DEVICE_BUTTON_EVT_DOWN = 1,\n DEVICE_BUTTON_EVT_UP = 2,\n DEVICE_BUTTON_EVT_CLICK = 3,\n DEVICE_BUTTON_EVT_LONG_CLICK = 4,\n DEVICE_BUTTON_EVT_HOLD = 5,\n DEVICE_BUTTON_EVT_DOUBLE_CLICK = 6,\n DEVICE_BUTTON_LONG_CLICK_TIME = 1000,\n DEVICE_BUTTON_HOLD_TIME = 1500,\n DEVICE_BUTTON_STATE = 1,\n DEVICE_BUTTON_STATE_HOLD_TRIGGERED = 2,\n DEVICE_BUTTON_STATE_CLICK = 4,\n DEVICE_BUTTON_STATE_LONG_CLICK = 8,\n DEVICE_BUTTON_SIGMA_MIN = 0,\n DEVICE_BUTTON_SIGMA_MAX = 12,\n DEVICE_BUTTON_SIGMA_THRESH_HI = 8,\n DEVICE_BUTTON_SIGMA_THRESH_LO = 2,\n DEVICE_BUTTON_DOUBLE_CLICK_THRESH = 50,\n DEVICE_BUTTON_SIMPLE_EVENTS = 0,\n DEVICE_BUTTON_ALL_EVENTS = 1,\n ACTIVE_LOW = 0,\n ACTIVE_HIGH = 1,\n // /libraries/codal-core/inc/driver-models/Accelerometer.h\n ACCELEROMETER_IMU_DATA_VALID = 2,\n ACCELEROMETER_EVT_DATA_UPDATE = 1,\n ACCELEROMETER_EVT_NONE = 0,\n ACCELEROMETER_EVT_TILT_UP = 1,\n ACCELEROMETER_EVT_TILT_DOWN = 2,\n ACCELEROMETER_EVT_TILT_LEFT = 3,\n ACCELEROMETER_EVT_TILT_RIGHT = 4,\n ACCELEROMETER_EVT_FACE_UP = 5,\n ACCELEROMETER_EVT_FACE_DOWN = 6,\n ACCELEROMETER_EVT_FREEFALL = 7,\n ACCELEROMETER_EVT_3G = 8,\n ACCELEROMETER_EVT_6G = 9,\n ACCELEROMETER_EVT_8G = 10,\n ACCELEROMETER_EVT_SHAKE = 11,\n ACCELEROMETER_EVT_2G = 12,\n ACCELEROMETER_REST_TOLERANCE = 200,\n ACCELEROMETER_TILT_TOLERANCE = 200,\n ACCELEROMETER_FREEFALL_TOLERANCE = 400,\n ACCELEROMETER_SHAKE_TOLERANCE = 400,\n ACCELEROMETER_2G_TOLERANCE = 2048,\n ACCELEROMETER_3G_TOLERANCE = 3072,\n ACCELEROMETER_6G_TOLERANCE = 6144,\n ACCELEROMETER_8G_TOLERANCE = 8192,\n ACCELEROMETER_GESTURE_DAMPING = 5,\n ACCELEROMETER_SHAKE_DAMPING = 10,\n ACCELEROMETER_SHAKE_RTX = 30,\n ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,\n // /libraries/codal-core/inc/driver-models/Compass.h\n COMPASS_STATUS_RUNNING = 1,\n COMPASS_STATUS_CALIBRATED = 2,\n COMPASS_STATUS_CALIBRATING = 4,\n COMPASS_STATUS_ADDED_TO_IDLE = 8,\n COMPASS_EVT_DATA_UPDATE = 1,\n COMPASS_EVT_CONFIG_NEEDED = 2,\n COMPASS_EVT_CALIBRATE = 3,\n COMPASS_EVT_CALIBRATION_NEEDED = 4,\n // /libraries/codal-core/inc/driver-models/Gyroscope.h\n GYROSCOPE_IMU_DATA_VALID = 2,\n GYROSCOPE_EVT_DATA_UPDATE = 1,\n // /libraries/codal-core/inc/driver-models/LowLevelTimer.h\n TimerModeTimer = 0,\n TimerModeCounter = 1,\n TimerModeAlternateFunction = 2,\n BitMode8 = 0,\n BitMode16 = 1,\n BitMode24 = 2,\n BitMode32 = 3,\n // /libraries/codal-core/inc/driver-models/Pin.h\n IO_STATUS_DIGITAL_IN = 1,\n IO_STATUS_DIGITAL_OUT = 2,\n IO_STATUS_ANALOG_IN = 4,\n IO_STATUS_ANALOG_OUT = 8,\n IO_STATUS_TOUCH_IN = 16,\n IO_STATUS_EVENT_ON_EDGE = 32,\n IO_STATUS_EVENT_PULSE_ON_EDGE = 64,\n IO_STATUS_INTERRUPT_ON_EDGE = 128,\n IO_STATUS_ACTIVE_HI = 256,\n DEVICE_PIN_MAX_OUTPUT = 1023,\n DEVICE_PIN_MAX_SERVO_RANGE = 180,\n DEVICE_PIN_DEFAULT_SERVO_RANGE = 2000,\n DEVICE_PIN_DEFAULT_SERVO_CENTER = 1500,\n DEVICE_PIN_EVENT_NONE = 0,\n DEVICE_PIN_INTERRUPT_ON_EDGE = 1,\n DEVICE_PIN_EVENT_ON_EDGE = 2,\n DEVICE_PIN_EVENT_ON_PULSE = 3,\n DEVICE_PIN_EVENT_ON_TOUCH = 4,\n DEVICE_PIN_EVT_RISE = 2,\n DEVICE_PIN_EVT_FALL = 3,\n DEVICE_PIN_EVT_PULSE_HI = 4,\n DEVICE_PIN_EVT_PULSE_LO = 5,\n PIN_CAPABILITY_DIGITAL = 1,\n PIN_CAPABILITY_ANALOG = 2,\n PIN_CAPABILITY_AD = 3,\n PIN_CAPABILITY_ALL = 3,\n None = 0,\n Down = 1,\n Up = 2,\n // /libraries/codal-core/inc/driver-models/Radio.h\n RADIO_EVT_DATA_READY = 2,\n // /libraries/codal-core/inc/driver-models/SPIFlash.h\n SPIFLASH_PAGE_SIZE = 256,\n SPIFLASH_SMALL_ROW_PAGES = 16,\n SPIFLASH_BIG_ROW_PAGES = 256,\n // /libraries/codal-core/inc/driver-models/Sensor.h\n SENSOR_THRESHOLD_LOW = 1,\n SENSOR_THRESHOLD_HIGH = 2,\n SENSOR_UPDATE_NEEDED = 3,\n SENSOR_INITIALISED = 1,\n SENSOR_HIGH_THRESHOLD_PASSED = 2,\n SENSOR_LOW_THRESHOLD_PASSED = 4,\n SENSOR_LOW_THRESHOLD_ENABLED = 8,\n SENSOR_HIGH_THRESHOLD_ENABLED = 16,\n SENSOR_DEFAULT_SENSITIVITY = 868,\n SENSOR_DEFAULT_SAMPLE_PERIOD = 500,\n // /libraries/codal-core/inc/driver-models/Serial.h\n CODAL_SERIAL_DEFAULT_BAUD_RATE = 115200,\n CODAL_SERIAL_DEFAULT_BUFFER_SIZE = 20,\n CODAL_SERIAL_EVT_DELIM_MATCH = 1,\n CODAL_SERIAL_EVT_HEAD_MATCH = 2,\n CODAL_SERIAL_EVT_RX_FULL = 3,\n CODAL_SERIAL_EVT_DATA_RECEIVED = 4,\n CODAL_SERIAL_STATUS_RX_IN_USE = 1,\n CODAL_SERIAL_STATUS_TX_IN_USE = 2,\n CODAL_SERIAL_STATUS_RX_BUFF_INIT = 4,\n CODAL_SERIAL_STATUS_TX_BUFF_INIT = 8,\n CODAL_SERIAL_STATUS_RXD = 16,\n ASYNC = 0,\n SYNC_SPINWAIT = 1,\n SYNC_SLEEP = 2,\n RxInterrupt = 0,\n TxInterrupt = 1,\n // /libraries/codal-core/inc/driver-models/SingleWireSerial.h\n SWS_EVT_DATA_RECEIVED = 1,\n SWS_EVT_DATA_SENT = 2,\n SWS_EVT_ERROR = 3,\n SWS_EVT_DATA_DROPPED = 4,\n SingleWireRx = 0,\n SingleWireTx = 1,\n SingleWireDisconnected = 2,\n // /libraries/codal-core/inc/driver-models/Timer.h\n CODAL_TIMER_DEFAULT_EVENT_LIST_SIZE = 10,\n // /libraries/codal-core/inc/drivers/AnalogSensor.h\n ANALOG_THRESHOLD_LOW = 1,\n ANALOG_THRESHOLD_HIGH = 2,\n ANALOG_SENSOR_UPDATE_NEEDED = 3,\n ANALOG_SENSOR_INITIALISED = 1,\n ANALOG_SENSOR_HIGH_THRESHOLD_PASSED = 2,\n ANALOG_SENSOR_LOW_THRESHOLD_PASSED = 4,\n ANALOG_SENSOR_LOW_THRESHOLD_ENABLED = 8,\n ANALOG_SENSOR_HIGH_THRESHOLD_ENABLED = 16,\n // /libraries/codal-core/inc/drivers/AnimatedDisplay.h\n DISPLAY_EVT_ANIMATION_COMPLETE = 1,\n DISPLAY_DEFAULT_AUTOCLEAR = 1,\n DISPLAY_SPACING = 1,\n DISPLAY_ANIMATE_DEFAULT_POS = -255,\n DISPLAY_DEFAULT_SCROLL_SPEED = 120,\n DISPLAY_DEFAULT_SCROLL_STRIDE = -1,\n DISPLAY_DEFAULT_PRINT_SPEED = 400,\n ANIMATION_MODE_NONE = 0,\n ANIMATION_MODE_STOPPED = 1,\n ANIMATION_MODE_SCROLL_TEXT = 2,\n ANIMATION_MODE_PRINT_TEXT = 3,\n ANIMATION_MODE_SCROLL_IMAGE = 4,\n ANIMATION_MODE_ANIMATE_IMAGE = 5,\n ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR = 6,\n ANIMATION_MODE_PRINT_CHARACTER = 7,\n // /libraries/codal-core/inc/drivers/FAT.h\n FAT_RESERVED_SECTORS = 1,\n FAT_ROOT_DIR_SECTORS = 4,\n // /libraries/codal-core/inc/drivers/HID.h\n HID_REQUEST_GET_REPORT = 1,\n HID_REQUEST_GET_IDLE = 2,\n HID_REQUEST_GET_PROTOCOL = 3,\n HID_REQUEST_SET_REPORT = 9,\n HID_REQUEST_SET_IDLE = 10,\n HID_REQUEST_SET_PROTOCOL = 11,\n // /libraries/codal-core/inc/drivers/HIDKeyboard.h\n HID_KEYBOARD_NUM_REPORTS = 3,\n HID_KEYBOARD_REPORT_GENERIC = 1,\n HID_KEYBOARD_REPORT_CONSUMER = 2,\n HID_KEYBOARD_KEYSTATE_SIZE_GENERIC = 8,\n HID_KEYBOARD_KEYSTATE_SIZE_CONSUMER = 2,\n HID_KEYBOARD_MODIFIER_OFFSET = 2,\n HID_KEYBOARD_DELAY_DEFAULT = 10,\n PressKey = 0,\n ReleaseKey = 1,\n // /libraries/codal-core/inc/drivers/KeyMap.h\n KEYMAP_ALL_KEYS_UP_Val = 1,\n KEYMAP_ALL_KEYS_UP_POS = 28,\n KEYMAP_NORMAL_KEY_Val = 0,\n KEYMAP_MODIFIER_KEY_Val = 1,\n KEYMAP_MODIFIER_POS = 29,\n KEYMAP_MEDIA_KEY_Val = 1,\n KEYMAP_MEDIA_POS = 30,\n KEYMAP_KEY_UP_Val = 0,\n KEYMAP_KEY_DOWN_Val = 1,\n KEYMAP_KEY_DOWN_POS = 31,\n // /libraries/codal-core/inc/drivers/KeyValueStorage.h\n DEVICE_KEY_VALUE_STORE_OFFSET = -4,\n KEY_VALUE_STORAGE_MAGIC = 789921,\n KEY_VALUE_STORAGE_BLOCK_SIZE = 48,\n KEY_VALUE_STORAGE_KEY_SIZE = 16,\n KEY_VALUE_STORAGE_SCRATCH_WORD_SIZE = 64,\n KEY_VALUE_STORAGE_MAX_PAIRS = 5,\n // /libraries/codal-core/inc/drivers/LEDMatrix.h\n LED_MATRIX_GREYSCALE_BIT_DEPTH = 8,\n LED_MATRIX_EVT_LIGHT_SENSE = 2,\n LED_MATRIX_EVT_FRAME_TIMEOUT = 3,\n LED_MATRIX_MINIMUM_BRIGHTNESS = 1,\n LED_MATRIX_MAXIMUM_BRIGHTNESS = 255,\n LED_MATRIX_DEFAULT_BRIGHTNESS = 255,\n DISPLAY_MODE_BLACK_AND_WHITE = 0,\n DISPLAY_MODE_GREYSCALE = 1,\n DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE = 2,\n DISPLAY_MODE_GREYSCALE_LIGHT_SENSE = 3,\n MATRIX_DISPLAY_ROTATION_0 = 0,\n MATRIX_DISPLAY_ROTATION_90 = 1,\n MATRIX_DISPLAY_ROTATION_180 = 2,\n MATRIX_DISPLAY_ROTATION_270 = 3,\n NO_CONN = 0,\n // /libraries/codal-core/inc/drivers/MAG3110.h\n MAG3110_DEFAULT_ADDR = 29,\n MAG3110_SAMPLE_RATES = 11,\n MAG3110_WHOAMI_VAL = 196,\n // /libraries/codal-core/inc/drivers/MultiButton.h\n MULTI_BUTTON_STATE_1 = 1,\n MULTI_BUTTON_STATE_2 = 2,\n MULTI_BUTTON_HOLD_TRIGGERED_1 = 4,\n MULTI_BUTTON_HOLD_TRIGGERED_2 = 8,\n MULTI_BUTTON_SUPRESSED_1 = 16,\n MULTI_BUTTON_SUPRESSED_2 = 32,\n MULTI_BUTTON_ATTACHED = 64,\n // /libraries/codal-core/inc/drivers/PulseIn.h\n DEVICE_EVT_PULSE_IN_TIMEOUT = 10000,\n // /libraries/codal-core/inc/drivers/ST7735.h\n MADCTL_MY = 128,\n MADCTL_MX = 64,\n MADCTL_MV = 32,\n MADCTL_ML = 16,\n MADCTL_RGB = 0,\n MADCTL_BGR = 8,\n MADCTL_MH = 4,\n // /libraries/codal-core/inc/drivers/TouchButton.h\n TOUCH_BUTTON_CALIBRATION_LINEAR_OFFSET = 2,\n TOUCH_BUTTON_CALIBRATION_PERCENTAGE_OFFSET = 5,\n TOUCH_BUTTON_SENSITIVITY = 10,\n TOUCH_BUTTON_CALIBRATION_PERIOD = 10,\n TOUCH_BUTTON_CALIBRATING = 16,\n // /libraries/codal-core/inc/drivers/TouchSensor.h\n TOUCH_SENSOR_MAX_BUTTONS = 10,\n TOUCH_SENSOR_SAMPLE_PERIOD = 50,\n TOUCH_SENSE_SAMPLE_MAX = 1000,\n TOUCH_SENSOR_UPDATE_NEEDED = 1,\n // /libraries/codal-core/inc/drivers/USB_HID_Keys.h\n KEY_MOD_LCTRL = 1,\n KEY_MOD_LSHIFT = 2,\n KEY_MOD_LALT = 4,\n KEY_MOD_LMETA = 8,\n KEY_MOD_RCTRL = 16,\n KEY_MOD_RSHIFT = 32,\n KEY_MOD_RALT = 64,\n KEY_MOD_RMETA = 128,\n KEY_NONE = 0,\n KEY_ERR_OVF = 1,\n KEY_A = 4,\n KEY_B = 5,\n KEY_C = 6,\n KEY_D = 7,\n KEY_E = 8,\n KEY_F = 9,\n KEY_G = 10,\n KEY_H = 11,\n KEY_I = 12,\n KEY_J = 13,\n KEY_K = 14,\n KEY_L = 15,\n KEY_M = 16,\n KEY_N = 17,\n KEY_O = 18,\n KEY_P = 19,\n KEY_Q = 20,\n KEY_R = 21,\n KEY_S = 22,\n KEY_T = 23,\n KEY_U = 24,\n KEY_V = 25,\n KEY_W = 26,\n KEY_X = 27,\n KEY_Y = 28,\n KEY_Z = 29,\n KEY_1 = 30,\n KEY_2 = 31,\n KEY_3 = 32,\n KEY_4 = 33,\n KEY_5 = 34,\n KEY_6 = 35,\n KEY_7 = 36,\n KEY_8 = 37,\n KEY_9 = 38,\n KEY_0 = 39,\n KEY_ENTER = 40,\n KEY_ESC = 41,\n KEY_BACKSPACE = 42,\n KEY_TAB = 43,\n KEY_SPACE = 44,\n KEY_MINUS = 45,\n KEY_EQUAL = 46,\n KEY_LEFTBRACE = 47,\n KEY_RIGHTBRACE = 48,\n KEY_BACKSLASH = 49,\n KEY_HASHTILDE = 50,\n KEY_SEMICOLON = 51,\n KEY_APOSTROPHE = 52,\n KEY_GRAVE = 53,\n KEY_COMMA = 54,\n KEY_DOT = 55,\n KEY_SLASH = 56,\n KEY_CAPSLOCK = 57,\n KEY_F1 = 58,\n KEY_F2 = 59,\n KEY_F3 = 60,\n KEY_F4 = 61,\n KEY_F5 = 62,\n KEY_F6 = 63,\n KEY_F7 = 64,\n KEY_F8 = 65,\n KEY_F9 = 66,\n KEY_F10 = 67,\n KEY_F11 = 68,\n KEY_F12 = 69,\n KEY_SYSRQ = 70,\n KEY_SCROLLLOCK = 71,\n KEY_PAUSE = 72,\n KEY_INSERT = 73,\n KEY_HOME = 74,\n KEY_PAGEUP = 75,\n KEY_DELETE = 76,\n KEY_END = 77,\n KEY_PAGEDOWN = 78,\n KEY_RIGHT = 79,\n KEY_LEFT = 80,\n KEY_DOWN = 81,\n KEY_UP = 82,\n KEY_NUMLOCK = 83,\n KEY_KPSLASH = 84,\n KEY_KPASTERISK = 85,\n KEY_KPMINUS = 86,\n KEY_KPPLUS = 87,\n KEY_KPENTER = 88,\n KEY_KP1 = 89,\n KEY_KP2 = 90,\n KEY_KP3 = 91,\n KEY_KP4 = 92,\n KEY_KP5 = 93,\n KEY_KP6 = 94,\n KEY_KP7 = 95,\n KEY_KP8 = 96,\n KEY_KP9 = 97,\n KEY_KP0 = 98,\n KEY_KPDOT = 99,\n KEY_102ND = 100,\n KEY_COMPOSE = 101,\n KEY_POWER = 102,\n KEY_KPEQUAL = 103,\n KEY_F13 = 104,\n KEY_F14 = 105,\n KEY_F15 = 106,\n KEY_F16 = 107,\n KEY_F17 = 108,\n KEY_F18 = 109,\n KEY_F19 = 110,\n KEY_F20 = 111,\n KEY_F21 = 112,\n KEY_F22 = 113,\n KEY_F23 = 114,\n KEY_F24 = 115,\n KEY_OPEN = 116,\n KEY_HELP = 117,\n KEY_PROPS = 118,\n KEY_FRONT = 119,\n KEY_STOP = 120,\n KEY_AGAIN = 121,\n KEY_UNDO = 122,\n KEY_CUT = 123,\n KEY_COPY = 124,\n KEY_PASTE = 125,\n KEY_FIND = 126,\n KEY_MUTE = 127,\n KEY_VOLUMEUP = 128,\n KEY_VOLUMEDOWN = 129,\n KEY_KPCOMMA = 133,\n KEY_RO = 135,\n KEY_KATAKANAHIRAGANA = 136,\n KEY_YEN = 137,\n KEY_HENKAN = 138,\n KEY_MUHENKAN = 139,\n KEY_KPJPCOMMA = 140,\n KEY_HANGEUL = 144,\n KEY_HANJA = 145,\n KEY_KATAKANA = 146,\n KEY_HIRAGANA = 147,\n KEY_ZENKAKUHANKAKU = 148,\n KEY_KPLEFTPAREN = 182,\n KEY_KPRIGHTPAREN = 183,\n KEY_LEFTCTRL = 224,\n KEY_LEFTSHIFT = 225,\n KEY_LEFTALT = 226,\n KEY_LEFTMETA = 227,\n KEY_RIGHTCTRL = 228,\n KEY_RIGHTSHIFT = 229,\n KEY_RIGHTALT = 230,\n KEY_RIGHTMETA = 231,\n KEY_MEDIA_PLAYPAUSE = 232,\n KEY_MEDIA_STOPCD = 233,\n KEY_MEDIA_PREVIOUSSONG = 234,\n KEY_MEDIA_NEXTSONG = 235,\n KEY_MEDIA_EJECTCD = 236,\n KEY_MEDIA_VOLUMEUP = 237,\n KEY_MEDIA_VOLUMEDOWN = 238,\n KEY_MEDIA_MUTE = 239,\n KEY_MEDIA_WWW = 240,\n KEY_MEDIA_BACK = 241,\n KEY_MEDIA_FORWARD = 242,\n KEY_MEDIA_STOP = 243,\n KEY_MEDIA_FIND = 244,\n KEY_MEDIA_SCROLLUP = 245,\n KEY_MEDIA_SCROLLDOWN = 246,\n KEY_MEDIA_EDIT = 247,\n KEY_MEDIA_SLEEP = 248,\n KEY_MEDIA_COFFEE = 249,\n KEY_MEDIA_REFRESH = 250,\n KEY_MEDIA_CALC = 251,\n // /libraries/codal-core/inc/drivers/uf2format.h\n UF2FORMAT_H = 1,\n APP_START_ADDRESS = 8192,\n UF2_FLAG_NOFLASH = 1,\n // /libraries/codal-core/inc/streams/DataStream.h\n DATASTREAM_MAXIMUM_BUFFERS = 1,\n DATASTREAM_FORMAT_UNKNOWN = 0,\n DATASTREAM_FORMAT_8BIT_UNSIGNED = 1,\n DATASTREAM_FORMAT_8BIT_SIGNED = 2,\n DATASTREAM_FORMAT_16BIT_UNSIGNED = 3,\n DATASTREAM_FORMAT_16BIT_SIGNED = 4,\n DATASTREAM_FORMAT_24BIT_UNSIGNED = 5,\n DATASTREAM_FORMAT_24BIT_SIGNED = 6,\n DATASTREAM_FORMAT_32BIT_UNSIGNED = 7,\n DATASTREAM_FORMAT_32BIT_SIGNED = 8,\n // /libraries/codal-core/inc/streams/LevelDetector.h\n LEVEL_THRESHOLD_LOW = 1,\n LEVEL_THRESHOLD_HIGH = 2,\n LEVEL_DETECTOR_INITIALISED = 1,\n LEVEL_DETECTOR_HIGH_THRESHOLD_PASSED = 2,\n LEVEL_DETECTOR_LOW_THRESHOLD_PASSED = 4,\n LEVEL_DETECTOR_DEFAULT_WINDOW_SIZE = 128,\n // /libraries/codal-core/inc/streams/LevelDetectorSPL.h\n LEVEL_DETECTOR_SPL_INITIALISED = 1,\n LEVEL_DETECTOR_SPL_HIGH_THRESHOLD_PASSED = 2,\n LEVEL_DETECTOR_SPL_LOW_THRESHOLD_PASSED = 4,\n LEVEL_DETECTOR_SPL_DEFAULT_WINDOW_SIZE = 128,\n // /libraries/codal-core/inc/streams/MemorySource.h\n MEMORY_SOURCE_DEFAULT_MAX_BUFFER = 256,\n // /libraries/codal-core/inc/streams/Synthesizer.h\n SYNTHESIZER_SAMPLE_RATE = 44100,\n TONE_WIDTH = 1024,\n // /libraries/codal-core/inc/types/BitmapFont.h\n BITMAP_FONT_WIDTH = 5,\n BITMAP_FONT_HEIGHT = 5,\n BITMAP_FONT_ASCII_START = 32,\n BITMAP_FONT_ASCII_END = 126,\n // /libraries/codal-core/inc/types/CoordinateSystem.h\n COORDINATE_SPACE_ROTATED_0 = 0,\n COORDINATE_SPACE_ROTATED_90 = 1,\n COORDINATE_SPACE_ROTATED_180 = 2,\n COORDINATE_SPACE_ROTATED_270 = 3,\n RAW = 0,\n SIMPLE_CARTESIAN = 1,\n NORTH_EAST_DOWN = 2,\n EAST_NORTH_UP = 3,\n NORTH_EAST_UP = 3,\n // /libraries/codal-core/inc/types/Event.h\n DEVICE_ID_ANY = 0,\n DEVICE_EVT_ANY = 0,\n CREATE_ONLY = 0,\n CREATE_AND_FIRE = 1,\n DEVICE_EVENT_DEFAULT_LAUNCH_MODE = 1,\n // /libraries/codal-core/inc/types/ManagedBuffer.h\n Zero = 1,\n // /libraries/codal-microbit-v2/inc/FSCache.h\n FSCACHE_FLAG_PINNED = 1,\n CODAL_FS_CACHE_VALIDATE = 1,\n CODAL_FS_DEFAULT_CACHE_SZE = 4,\n // /libraries/codal-microbit-v2/inc/MicroBitBLEServices.h\n MICROBIT_BLE_SERVICES_MAX = 20,\n MICROBIT_BLE_SERVICES_OBSERVER_PRIO = 2,\n // /libraries/codal-microbit-v2/inc/MicroBitDevice.h\n MICROBIT_NAME_LENGTH = 5,\n MICROBIT_NAME_CODE_LETTERS = 5,\n // /libraries/codal-microbit-v2/inc/MicroBitFile.h\n READ = 1,\n WRITE = 2,\n READ_AND_WRITE = 3,\n CREATE = 4,\n // /libraries/codal-microbit-v2/inc/MicroBitFileSystem.h\n MBFS_FILENAME_LENGTH = 16,\n MB_READ = 1,\n MB_WRITE = 2,\n MB_CREAT = 4,\n MB_APPEND = 8,\n MB_SEEK_SET = 1,\n MB_SEEK_END = 2,\n MB_SEEK_CUR = 4,\n MBFS_STATUS_INITIALISED = 1,\n MBFS_UNUSED = 65535,\n MBFS_EOF = 61439,\n MBFS_DELETED = 0,\n MBFS_DIRECTORY_ENTRY_FREE = 32768,\n MBFS_DIRECTORY_ENTRY_VALID = 16384,\n MBFS_DIRECTORY_ENTRY_DIRECTORY = 8192,\n MBFS_DIRECTORY_ENTRY_NEW = 65535,\n MBFS_DIRECTORY_ENTRY_DELETED = 0,\n MBFS_BLOCK_TYPE_FILE = 1,\n MBFS_BLOCK_TYPE_DIRECTORY = 2,\n MBFS_BLOCK_TYPE_FILETABLE = 3,\n // /libraries/codal-microbit-v2/inc/MicroBitLog.h\n CONFIG_MICROBIT_LOG_JOURNAL_PAGES = 4,\n CONFIG_MICROBIT_LOG_CACHE_BLOCK_SIZE = 256,\n MICROBIT_LOG_JOURNAL_ENTRY_SIZE = 8,\n MICROBIT_LOG_STATUS_INITIALIZED = 1,\n MICROBIT_LOG_STATUS_ROW_STARTED = 2,\n MICROBIT_LOG_STATUS_FULL = 4,\n MICROBIT_LOG_EVT_LOG_FULL = 1,\n Milliseconds = 1,\n Seconds = 10,\n Minutes = 600,\n Hours = 36000,\n Days = 864000,\n // /libraries/codal-microbit-v2/inc/MicroBitMemoryMap.h\n NUMBER_OF_REGIONS = 3,\n REGION_SD = 0,\n REGION_CODAL = 1,\n REGION_MAKECODE = 2,\n REGION_PYTHON = 3,\n // /libraries/codal-microbit-v2/inc/MicroBitPowerManager.h\n MICROBIT_UIPM_MAX_BUFFER_SIZE = 8,\n MICROBIT_UIPM_MAX_RETRIES = 5,\n MICROBIT_USB_INTERFACE_IRQ_THRESHOLD = 3,\n MICROBIT_UIPM_COMMAND_READ_REQUEST = 16,\n MICROBIT_UIPM_COMMAND_READ_RESPONSE = 17,\n MICROBIT_UIPM_COMMAND_WRITE_REQUEST = 18,\n MICROBIT_UIPM_COMMAND_WRITE_RESPONSE = 19,\n MICROBIT_UIPM_COMMAND_ERROR_RESPONSE = 32,\n MICROBIT_UIPM_PROPERTY_BOARD_REVISION = 1,\n MICROBIT_UIPM_PROPERTY_I2C_VERSION = 2,\n MICROBIT_UIPM_PROPERTY_DAPLINK_VERSION = 3,\n MICROBIT_UIPM_PROPERTY_POWER_SOURCE = 4,\n MICROBIT_UIPM_PROPERTY_POWER_CONSUMPTION = 5,\n MICROBIT_UIPM_PROPERTY_USB_STATE = 6,\n MICROBIT_UIPM_PROPERTY_KL27_POWER_MODE = 7,\n MICROBIT_UIPM_PROPERTY_KL27_POWER_LED_STATE = 8,\n MICROBIT_UIPM_PROPERTY_KL27_USER_EVENT = 9,\n MICROBIT_UIPM_EVENT_WAKE_RESET = 1,\n MICROBIT_UIPM_EVENT_WAKE_USB_INSERTION = 2,\n MICROBIT_UIPM_EVENT_RESET_LONG_PRESS = 3,\n MICROBIT_UIPM_SUCCESS = 48,\n MICROBIT_UIPM_INCOMPLETE_CMD = 49,\n MICROBIT_UIPM_UNKNOWN_CMD = 50,\n MICROBIT_UIPM_FORBIDDEN = 51,\n MICROBIT_UIPM_NOT_RECOGNISED = 52,\n MICROBIT_UIPM_BAD_LENGTH = 53,\n MICROBIT_UIPM_READ_FORBIDDEN = 54,\n MICROBIT_UIPM_WRITE_FORBIDDEN = 55,\n MICROBIT_UIPM_WRITE_FAIL = 56,\n MICROBIT_UIPM_I2C_FAIL = 57,\n MICROBIT_USB_INTERFACE_POWER_MODE_VLPS = 6,\n MICROBIT_USB_INTERFACE_POWER_MODE_VLLS0 = 8,\n MICROBIT_USB_INTERFACE_AWAITING_RESPONSE = 1,\n MICROBIT_USB_INTERFACE_VERSION_LOADED = 2,\n // /libraries/codal-microbit-v2/inc/MicroBitRadio.h\n MICROBIT_RADIO_STATUS_INITIALISED = 1,\n MICROBIT_RADIO_BASE_ADDRESS = 1969383796,\n MICROBIT_RADIO_DEFAULT_GROUP = 0,\n MICROBIT_RADIO_DEFAULT_TX_POWER = 7,\n MICROBIT_RADIO_DEFAULT_FREQUENCY = 7,\n MICROBIT_RADIO_MAX_PACKET_SIZE = 32,\n MICROBIT_RADIO_HEADER_SIZE = 4,\n MICROBIT_RADIO_MAXIMUM_RX_BUFFERS = 4,\n MICROBIT_RADIO_POWER_LEVELS = 10,\n MICROBIT_RADIO_PROTOCOL_DATAGRAM = 1,\n MICROBIT_RADIO_PROTOCOL_EVENTBUS = 2,\n MICROBIT_RADIO_EVT_DATAGRAM = 1,\n // /libraries/codal-microbit-v2/inc/MicroBitThermometer.h\n MICROBIT_THERMOMETER_PERIOD = 1000,\n MICROBIT_THERMOMETER_EVT_UPDATE = 1,\n // /libraries/codal-microbit-v2/inc/MicroBitUSBFlashManager.h\n MICROBIT_USB_FLASH_MAX_RETRIES = 20,\n MICROBIT_USB_FLASH_FILENAME_CMD = 1,\n MICROBIT_USB_FLASH_FILESIZE_CMD = 2,\n MICROBIT_USB_FLASH_VISIBILITY_CMD = 3,\n MICROBIT_USB_FLASH_WRITE_CONFIG_CMD = 4,\n MICROBIT_USB_FLASH_ERASE_CONFIG_CMD = 5,\n MICROBIT_USB_FLASH_DISK_SIZE_CMD = 6,\n MICROBIT_USB_FLASH_SECTOR_SIZE_CMD = 7,\n MICROBIT_USB_FLASH_REMOUNT_CMD = 8,\n MICROBIT_USB_FLASH_STATUS_CMD = 9,\n MICROBIT_USB_FLASH_READ_CMD = 10,\n MICROBIT_USB_FLASH_WRITE_CMD = 11,\n MICROBIT_USB_FLASH_ERASE_CMD = 12,\n MICROBIT_USB_FLASH_AWAITING_RESPONSE = 1,\n MICROBIT_USB_FLASH_GEOMETRY_LOADED = 2,\n MICROBIT_USB_FLASH_CONFIG_LOADED = 4,\n // /libraries/codal-microbit-v2/inc/Mixer2.h\n CONFIG_MIXER_BUFFER_SIZE = 512,\n CONFIG_MIXER_INTERNAL_RANGE = 1023,\n CONFIG_MIXER_DEFAULT_SAMPLERATE = 44100,\n DEVICE_ID_MIXER = 3030,\n DEVICE_MIXER_EVT_SILENCE = 1,\n DEVICE_MIXER_EVT_SOUND = 2,\n // /libraries/codal-microbit-v2/inc/NRF52LedMatrix.h\n NRF52_LED_MATRIX_CLOCK_FREQUENCY = 16000000,\n NRF52_LED_MATRIX_FREQUENCY = 60,\n NRF52_LED_MATRIX_MAXIMUM_COLUMNS = 5,\n NRF52_LED_MATRIX_LIGHTSENSE_STROBES = 4,\n NRF52_LEDMATRIX_GPIOTE_CHANNEL_BASE = 1,\n NRF52_LEDMATRIX_PPI_CHANNEL_BASE = 3,\n NRF52_LEDMATRIX_STATUS_RESET = 1,\n // /libraries/codal-microbit-v2/inc/SoundEmojiSynthesizer.h\n EMOJI_SYNTHESIZER_SAMPLE_RATE = 44100,\n EMOJI_SYNTHESIZER_TONE_WIDTH = 1024,\n EMOJI_SYNTHESIZER_BUFFER_SIZE = 512,\n EMOJI_SYNTHESIZER_TONE_EFFECT_PARAMETERS = 2,\n EMOJI_SYNTHESIZER_TONE_EFFECTS = 3,\n EMOJI_SYNTHESIZER_STATUS_ACTIVE = 1,\n EMOJI_SYNTHESIZER_STATUS_OUTPUT_SILENCE_AS_EMPTY = 2,\n EMOJI_SYNTHESIZER_STATUS_STOPPING = 4,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_0 = 3010,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_1 = 3011,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_2 = 3012,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_3 = 3013,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_4 = 3014,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_5 = 3015,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_6 = 3016,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_7 = 3017,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_8 = 3018,\n DEVICE_ID_SOUND_EMOJI_SYNTHESIZER_9 = 3019,\n DEVICE_SOUND_EMOJI_SYNTHESIZER_EVT_DONE = 1,\n // /libraries/codal-microbit-v2/inc/SoundOutputPin.h\n CONFIG_SOUND_OUTPUT_PIN_PERIOD = 50,\n CONFIG_SOUND_OUTPUT_PIN_SILENCE_GATE = 100,\n SOUND_OUTPUT_PIN_STATUS_ACTIVE = 1,\n // /libraries/codal-microbit-v2/inc/bluetooth/ExternalEvents.h\n MICROBIT_ID_BLE = 1000,\n MICROBIT_ID_BLE_UART = 1200,\n MICROBIT_BLE_EVT_CONNECTED = 1,\n MICROBIT_BLE_EVT_DISCONNECTED = 2,\n // /libraries/codal-microbit-v2/inc/bluetooth/MESEvents.h\n MES_REMOTE_CONTROL_ID = 1001,\n MES_REMOTE_CONTROL_EVT_PLAY = 1,\n MES_REMOTE_CONTROL_EVT_PAUSE = 2,\n MES_REMOTE_CONTROL_EVT_STOP = 3,\n MES_REMOTE_CONTROL_EVT_NEXTTRACK = 4,\n MES_REMOTE_CONTROL_EVT_PREVTRACK = 5,\n MES_REMOTE_CONTROL_EVT_FORWARD = 6,\n MES_REMOTE_CONTROL_EVT_REWIND = 7,\n MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8,\n MES_REMOTE_CONTROL_EVT_VOLUMEDOWN = 9,\n MES_CAMERA_ID = 1002,\n MES_CAMERA_EVT_LAUNCH_PHOTO_MODE = 1,\n MES_CAMERA_EVT_LAUNCH_VIDEO_MODE = 2,\n MES_CAMERA_EVT_TAKE_PHOTO = 3,\n MES_CAMERA_EVT_START_VIDEO_CAPTURE = 4,\n MES_CAMERA_EVT_STOP_VIDEO_CAPTURE = 5,\n MES_CAMERA_EVT_STOP_PHOTO_MODE = 6,\n MES_CAMERA_EVT_STOP_VIDEO_MODE = 7,\n MES_CAMERA_EVT_TOGGLE_FRONT_REAR = 8,\n MES_ALERTS_ID = 1004,\n MES_ALERT_EVT_DISPLAY_TOAST = 1,\n MES_ALERT_EVT_VIBRATE = 2,\n MES_ALERT_EVT_PLAY_SOUND = 3,\n MES_ALERT_EVT_PLAY_RINGTONE = 4,\n MES_ALERT_EVT_FIND_MY_PHONE = 5,\n MES_ALERT_EVT_ALARM1 = 6,\n MES_ALERT_EVT_ALARM2 = 7,\n MES_ALERT_EVT_ALARM3 = 8,\n MES_ALERT_EVT_ALARM4 = 9,\n MES_ALERT_EVT_ALARM5 = 10,\n MES_ALERT_EVT_ALARM6 = 11,\n MES_SIGNAL_STRENGTH_ID = 1101,\n MES_SIGNAL_STRENGTH_EVT_NO_BAR = 1,\n MES_SIGNAL_STRENGTH_EVT_ONE_BAR = 2,\n MES_SIGNAL_STRENGTH_EVT_TWO_BAR = 3,\n MES_SIGNAL_STRENGTH_EVT_THREE_BAR = 4,\n MES_SIGNAL_STRENGTH_EVT_FOUR_BAR = 5,\n MES_DEVICE_INFO_ID = 1103,\n MES_DEVICE_ORIENTATION_LANDSCAPE = 1,\n MES_DEVICE_ORIENTATION_PORTRAIT = 2,\n MES_DEVICE_GESTURE_NONE = 3,\n MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4,\n MES_DEVICE_DISPLAY_OFF = 5,\n MES_DEVICE_DISPLAY_ON = 6,\n MES_DEVICE_INCOMING_CALL = 7,\n MES_DEVICE_INCOMING_MESSAGE = 8,\n MES_DPAD_CONTROLLER_ID = 1104,\n MES_DPAD_BUTTON_A_DOWN = 1,\n MES_DPAD_BUTTON_A_UP = 2,\n MES_DPAD_BUTTON_B_DOWN = 3,\n MES_DPAD_BUTTON_B_UP = 4,\n MES_DPAD_BUTTON_C_DOWN = 5,\n MES_DPAD_BUTTON_C_UP = 6,\n MES_DPAD_BUTTON_D_DOWN = 7,\n MES_DPAD_BUTTON_D_UP = 8,\n MES_DPAD_BUTTON_1_DOWN = 9,\n MES_DPAD_BUTTON_1_UP = 10,\n MES_DPAD_BUTTON_2_DOWN = 11,\n MES_DPAD_BUTTON_2_UP = 12,\n MES_DPAD_BUTTON_3_DOWN = 13,\n MES_DPAD_BUTTON_3_UP = 14,\n MES_DPAD_BUTTON_4_DOWN = 15,\n MES_DPAD_BUTTON_4_UP = 16,\n MES_BROADCAST_GENERAL_ID = 2000,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitBLEManager.h\n MICROBIT_BLE_PAIR_REQUEST = 1,\n MICROBIT_BLE_PAIR_COMPLETE = 2,\n MICROBIT_BLE_PAIR_PASSCODE = 4,\n MICROBIT_BLE_PAIR_SUCCESSFUL = 8,\n MICROBIT_BLE_PAIRING_TIMEOUT = 90,\n MICROBIT_BLE_POWER_LEVELS = 8,\n MICROBIT_BLE_MAXIMUM_BONDS = 4,\n MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL = 400,\n MICROBIT_BLE_EDDYSTONE_DEFAULT_POWER = 240,\n MICROBIT_BLE_STATUS_DISCONNECT = 4,\n MICROBIT_BLE_STATUS_SHUTDOWN = 8,\n MICROBIT_MODE_PAIRING = 0,\n MICROBIT_MODE_APPLICATION = 1,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitBLETypes.h\n MICROBIT_DMESG_LEVEL_OFF = 0,\n MICROBIT_DMESG_LEVEL_ERROR = 1,\n MICROBIT_DMESG_LEVEL_WARNING = 2,\n MICROBIT_DMESG_LEVEL_INFO = 3,\n MICROBIT_DMESG_LEVEL_DEBUG = 4,\n MICROBIT_DMESG_LEVEL = 0,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitIOPinService.h\n MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19,\n MICROBIT_IO_PIN_SERVICE_DATA_SIZE = 10,\n MICROBIT_PWM_PIN_SERVICE_DATA_SIZE = 2,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitLEDService.h\n MICROBIT_BLE_MAXIMUM_SCROLLTEXT = 20,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitMagnetometerService.h\n COMPASS_CALIBRATION_STATUS_UNKNOWN = 0,\n COMPASS_CALIBRATION_REQUESTED = 1,\n COMPASS_CALIBRATION_COMPLETED_OK = 2,\n COMPASS_CALIBRATION_COMPLETED_ERR = 3,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitPartialFlashingService.h\n PARTIAL_FLASHING_VERSION = 1,\n REGION_INFO = 0,\n FLASH_DATA = 1,\n END_OF_TRANSMISSION = 2,\n MICROBIT_STATUS = 238,\n MICROBIT_RESET = 255,\n // /libraries/codal-microbit-v2/inc/bluetooth/MicroBitUARTService.h\n MICROBIT_UART_S_DEFAULT_BUF_SIZE = 20,\n MICROBIT_UART_S_EVT_DELIM_MATCH = 1,\n MICROBIT_UART_S_EVT_HEAD_MATCH = 2,\n MICROBIT_UART_S_EVT_RX_FULL = 3,\n // /libraries/codal-microbit-v2/inc/compat/MicroBitCompat.h\n MICROBIT_BUSY = -1006,\n MICROBIT_CANCELLED = -1007,\n MICROBIT_CALIBRATION_IN_PROGRESS = -1003,\n MICROBIT_CALIBRATION_REQUIRED = -1004,\n MICROBIT_HEAP_ERROR = 30,\n MICROBIT_I2C_ERROR = -1010,\n MICROBIT_INVALID_PARAMETER = -1001,\n MICROBIT_NO_DATA = -1012,\n MICROBIT_NO_RESOURCES = -1005,\n MICROBIT_NOT_SUPPORTED = -1002,\n MICROBIT_NULL_DEREFERENCE = 40,\n MICROBIT_OK = 0,\n MICROBIT_OOM = 20,\n MICROBIT_SERIAL_IN_USE = -1011,\n MICROBIT_ACCELEROMETER_3G_TOLERANCE = 3072,\n MICROBIT_ACCELEROMETER_6G_TOLERANCE = 6144,\n MICROBIT_ACCELEROMETER_8G_TOLERANCE = 8192,\n MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE = 400,\n MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 5,\n MICROBIT_ACCELEROMETER_REST_TOLERANCE = 200,\n MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,\n MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10,\n MICROBIT_ACCELEROMETER_SHAKE_RTX = 30,\n MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE = 400,\n MICROBIT_ACCELEROMETER_TILT_TOLERANCE = 200,\n MICROBIT_COMPONENT_RUNNING = 4096,\n MICROBIT_DEFAULT_PRINT_SPEED = 400,\n MICROBIT_DEFAULT_SCROLL_SPEED = 120,\n MICROBIT_DEFAULT_SCROLL_STRIDE = -1,\n MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR = 1,\n MICROBIT_DISPLAY_DEFAULT_BRIGHTNESS = 255,\n MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH = 8,\n MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS = 255,\n MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS = 1,\n MICROBIT_DISPLAY_ROTATION_0 = 0,\n MICROBIT_DISPLAY_ROTATION_180 = 2,\n MICROBIT_DISPLAY_ROTATION_270 = 3,\n MICROBIT_DISPLAY_ROTATION_90 = 1,\n MICROBIT_EVENT_DEFAULT_LAUNCH_MODE = 1,\n MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS = -255,\n MICROBIT_FONT_ASCII_END = 126,\n MICROBIT_FONT_ASCII_START = 32,\n MICROBIT_FONT_HEIGHT = 5,\n MICROBIT_FONT_WIDTH = 5,\n MICROBIT_I2C_MAX_RETRIES = 1,\n MICROBIT_PIN_DEFAULT_SERVO_CENTER = 1500,\n MICROBIT_PIN_DEFAULT_SERVO_RANGE = 2000,\n MICROBIT_PIN_EVENT_NONE = 0,\n MICROBIT_PIN_EVENT_ON_EDGE = 2,\n MICROBIT_PIN_EVENT_ON_PULSE = 3,\n MICROBIT_PIN_EVENT_ON_TOUCH = 4,\n MICROBIT_PIN_EVT_FALL = 3,\n MICROBIT_PIN_EVT_PULSE_HI = 4,\n MICROBIT_PIN_EVT_PULSE_LO = 5,\n MICROBIT_PIN_EVT_RISE = 2,\n MICROBIT_PIN_MAX_OUTPUT = 1023,\n MICROBIT_PIN_MAX_SERVO_RANGE = 180,\n MICROBIT_UART_S_EVT_TX_EMPTY = 3,\n MICROBIT_ACCELEROMETER_EVT_3G = 8,\n MICROBIT_ACCELEROMETER_EVT_6G = 9,\n MICROBIT_ACCELEROMETER_EVT_8G = 10,\n MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1,\n MICROBIT_ACCELEROMETER_EVT_FACE_DOWN = 6,\n MICROBIT_ACCELEROMETER_EVT_FACE_UP = 5,\n MICROBIT_ACCELEROMETER_EVT_FREEFALL = 7,\n MICROBIT_ACCELEROMETER_EVT_NONE = 0,\n MICROBIT_ACCELEROMETER_EVT_SHAKE = 11,\n MICROBIT_ACCELEROMETER_EVT_TILT_DOWN = 2,\n MICROBIT_ACCELEROMETER_EVT_TILT_LEFT = 3,\n MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT = 4,\n MICROBIT_ACCELEROMETER_EVT_TILT_UP = 1,\n MICROBIT_BUTTON_ALL_EVENTS = 1,\n MICROBIT_BUTTON_SIMPLE_EVENTS = 0,\n MICROBIT_BUTTON_EVT_CLICK = 3,\n MICROBIT_BUTTON_EVT_DOUBLE_CLICK = 6,\n MICROBIT_BUTTON_EVT_DOWN = 1,\n MICROBIT_BUTTON_EVT_HOLD = 5,\n MICROBIT_BUTTON_EVT_LONG_CLICK = 4,\n MICROBIT_BUTTON_EVT_UP = 2,\n MICROBIT_COMPASS_EVT_CALIBRATE = 3,\n MICROBIT_COMPASS_EVT_CONFIG_NEEDED = 2,\n MICROBIT_COMPASS_EVT_DATA_UPDATE = 1,\n MICROBIT_COMPASS_EVT_CALIBRATION_NEEDED = 4,\n MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE = 1,\n MICROBIT_DISPLAY_EVT_FREE = 1,\n MICROBIT_SERIAL_EVT_DELIM_MATCH = 1,\n MICROBIT_SERIAL_EVT_HEAD_MATCH = 2,\n MICROBIT_SERIAL_EVT_RX_FULL = 3,\n MICROBIT_SERIAL_EVT_TX_EMPTY = 2,\n MICROBIT_ID_ANY = 0,\n MICROBIT_EVT_ANY = 0,\n MICROBIT_ID_ACCELEROMETER = 5,\n MICROBIT_ID_BUTTON_A = 1,\n MICROBIT_ID_BUTTON_B = 2,\n MICROBIT_ID_BUTTON_AB = 3,\n MICROBIT_ID_BUTTON_RESET = 4,\n MICROBIT_ID_COMPASS = 6,\n MICROBIT_ID_DISPLAY = 7,\n MICROBIT_ID_GESTURE = 13,\n MICROBIT_ID_IO_P0 = 100,\n MICROBIT_ID_IO_P1 = 101,\n MICROBIT_ID_IO_P2 = 102,\n MICROBIT_ID_IO_P3 = 103,\n MICROBIT_ID_IO_P4 = 104,\n MICROBIT_ID_IO_P5 = 105,\n MICROBIT_ID_IO_P6 = 106,\n MICROBIT_ID_IO_P7 = 107,\n MICROBIT_ID_IO_P8 = 108,\n MICROBIT_ID_IO_P9 = 109,\n MICROBIT_ID_IO_P10 = 110,\n MICROBIT_ID_IO_P11 = 111,\n MICROBIT_ID_IO_P12 = 112,\n MICROBIT_ID_IO_P13 = 113,\n MICROBIT_ID_IO_P14 = 114,\n MICROBIT_ID_IO_P15 = 115,\n MICROBIT_ID_IO_P16 = 116,\n MICROBIT_ID_IO_P19 = 119,\n MICROBIT_ID_IO_P20 = 120,\n MICROBIT_ID_LOGO = 121,\n MICROBIT_ID_MESSAGE_BUS_LISTENER = 1021,\n MICROBIT_ID_MULTIBUTTON_ATTACH = 11,\n MICROBIT_ID_NOTIFY = 1023,\n MICROBIT_ID_NOTIFY_ONE = 1022,\n MICROBIT_ID_RADIO = 9,\n MICROBIT_ID_RADIO_DATA_READY = 10,\n MICROBIT_ID_SERIAL = 12,\n MICROBIT_ID_THERMOMETER = 8,\n MICROBIT_ID_PARTIAL_FLASHING = 36,\n MICROBIT_ID_POWER_MANAGER = 37,\n MICROBIT_ID_USB_FLASH_MANAGER = 38,\n MICROBIT_ID_VIRTUAL_SPEAKER_PIN = 39,\n MICROBIT_ID_MBED_INTERRUPT_IN = 40,\n MICROBIT_ID_MBED_PWM = 41,\n MICROBIT_ID_MBED_TIMEOUT = 42,\n MICROBIT_ID_MBED_TICKER = 43,\n MICROBIT_ID_LOG = 44,\n MICROBIT_NESTED_HEAP_SIZE = 0,\n MICROBIT_SCHEDULER_RUNNING = 1,\n MICROBIT_SERIAL_DEFAULT_BAUD_RATE = 115200,\n MICROBIT_SERIAL_DEFAULT_BUFFER_SIZE = 20,\n MICROBIT_ACCEL_ADDED_TO_IDLE = 8,\n MICROBIT_COMPASS_STATUS_ADDED_TO_IDLE = 8,\n // /libraries/codal-microbit-v2/model/MicroBit.h\n DEVICE_INITIALIZED = 1,\n MICROBIT_UBIT_FACE_TOUCH_BUTTON = 1,\n KL27_POWER_ON_DELAY = 1000,\n CONFIG_MICROBIT_ERASE_USER_DATA_ON_REFLASH = 1,\n DEVICE_ID_MICROPHONE = 3001,\n // /libraries/codal-microbit-v2/model/MicroBitIO.h\n MICROBIT_PIN_BUTTON_RESET = -1,\n ID_PIN_P0 = 100,\n ID_PIN_P1 = 101,\n ID_PIN_P2 = 102,\n ID_PIN_P3 = 103,\n ID_PIN_P4 = 104,\n ID_PIN_P5 = 105,\n ID_PIN_P6 = 106,\n ID_PIN_P7 = 107,\n ID_PIN_P8 = 108,\n ID_PIN_P9 = 109,\n ID_PIN_P10 = 110,\n ID_PIN_P11 = 111,\n ID_PIN_P12 = 112,\n ID_PIN_P13 = 113,\n ID_PIN_P14 = 114,\n ID_PIN_P15 = 115,\n ID_PIN_P16 = 116,\n ID_PIN_P17 = 117,\n ID_PIN_P18 = 118,\n ID_PIN_P19 = 119,\n ID_PIN_P20 = 120,\n ID_PIN_LOGO = 121,\n ID_PIN_SPEAKER = 122,\n ID_PIN_RUNMIC = 123,\n ID_PIN_SDA = 124,\n ID_PIN_SCL = 125,\n ID_PIN_ROW1 = 126,\n ID_PIN_ROW2 = 127,\n ID_PIN_ROW3 = 128,\n ID_PIN_ROW4 = 129,\n ID_PIN_ROW5 = 130,\n ID_PIN_USBTX = 131,\n ID_PIN_USBRX = 132,\n ID_PIN_IRQ1 = 133,\n ID_PIN_MIC = 134,\n ID_PIN_P35 = 135,\n ID_PIN_P36 = 136,\n ID_PIN_P37 = 137,\n ID_PIN_P38 = 138,\n ID_PIN_P39 = 139,\n ID_PIN_P40 = 140,\n ID_PIN_P41 = 141,\n ID_PIN_P42 = 142,\n ID_PIN_P43 = 143,\n ID_PIN_P44 = 144,\n ID_PIN_P45 = 145,\n ID_PIN_P46 = 146,\n ID_PIN_P47 = 147,\n IO_SAVED_STATUS_OUTPUT_NA = 0,\n IO_SAVED_STATUS_OUTPUT_LO = 1,\n IO_SAVED_STATUS_OUTPUT_HI = 2,\n IO_SAVED_STATUS_DETECT_LOW_ENABLED = 4,\n IO_SAVED_STATUS_DETECT_HIGH_ENABLED = 8,\n // /pxtapp/configkeys.h\n CFG_PIN_NAME_MSK = 65535,\n CFG_PIN_CONFIG_MSK = 4294901760,\n CFG_PIN_CONFIG_ACTIVE_LO = 65536,\n CFG_MAGIC0 = 513675505,\n CFG_MAGIC1 = 539130489,\n CFG_PIN_ACCELEROMETER_INT = 1,\n CFG_PIN_ACCELEROMETER_SCL = 2,\n CFG_PIN_ACCELEROMETER_SDA = 3,\n CFG_PIN_BTN_A = 4,\n CFG_PIN_BTN_B = 5,\n CFG_PIN_BTN_SLIDE = 6,\n CFG_PIN_DOTSTAR_CLOCK = 7,\n CFG_PIN_DOTSTAR_DATA = 8,\n CFG_PIN_FLASH_CS = 9,\n CFG_PIN_FLASH_MISO = 10,\n CFG_PIN_FLASH_MOSI = 11,\n CFG_PIN_FLASH_SCK = 12,\n CFG_PIN_LED = 13,\n CFG_PIN_LIGHT = 14,\n CFG_PIN_MICROPHONE = 15,\n CFG_PIN_MIC_CLOCK = 16,\n CFG_PIN_MIC_DATA = 17,\n CFG_PIN_MISO = 18,\n CFG_PIN_MOSI = 19,\n CFG_PIN_NEOPIXEL = 20,\n CFG_PIN_RX = 21,\n CFG_PIN_RXLED = 22,\n CFG_PIN_SCK = 23,\n CFG_PIN_SCL = 24,\n CFG_PIN_SDA = 25,\n CFG_PIN_SPEAKER_AMP = 26,\n CFG_PIN_TEMPERATURE = 27,\n CFG_PIN_TX = 28,\n CFG_PIN_TXLED = 29,\n CFG_PIN_IR_OUT = 30,\n CFG_PIN_IR_IN = 31,\n CFG_PIN_DISPLAY_SCK = 32,\n CFG_PIN_DISPLAY_MISO = 33,\n CFG_PIN_DISPLAY_MOSI = 34,\n CFG_PIN_DISPLAY_CS = 35,\n CFG_PIN_DISPLAY_DC = 36,\n CFG_DISPLAY_WIDTH = 37,\n CFG_DISPLAY_HEIGHT = 38,\n CFG_DISPLAY_CFG0 = 39,\n CFG_DISPLAY_CFG1 = 40,\n CFG_DISPLAY_CFG2 = 41,\n CFG_DISPLAY_CFG3 = 42,\n CFG_PIN_DISPLAY_RST = 43,\n CFG_PIN_DISPLAY_BL = 44,\n CFG_PIN_SERVO_1 = 45,\n CFG_PIN_SERVO_2 = 46,\n CFG_PIN_BTN_LEFT = 47,\n CFG_PIN_BTN_RIGHT = 48,\n CFG_PIN_BTN_UP = 49,\n CFG_PIN_BTN_DOWN = 50,\n CFG_PIN_BTN_MENU = 51,\n CFG_PIN_LED_R = 52,\n CFG_PIN_LED_G = 53,\n CFG_PIN_LED_B = 54,\n CFG_PIN_LED1 = 55,\n CFG_PIN_LED2 = 56,\n CFG_PIN_LED3 = 57,\n CFG_PIN_LED4 = 58,\n CFG_SPEAKER_VOLUME = 59,\n CFG_PIN_JACK_TX = 60,\n CFG_PIN_JACK_SENSE = 61,\n CFG_PIN_JACK_HPEN = 62,\n CFG_PIN_JACK_BZEN = 63,\n CFG_PIN_JACK_PWREN = 64,\n CFG_PIN_JACK_SND = 65,\n CFG_PIN_JACK_BUSLED = 66,\n CFG_PIN_JACK_COMMLED = 67,\n CFG_PIN_BTN_SOFT_RESET = 69,\n CFG_ACCELEROMETER_TYPE = 70,\n CFG_PIN_BTNMX_LATCH = 71,\n CFG_PIN_BTNMX_CLOCK = 72,\n CFG_PIN_BTNMX_DATA = 73,\n CFG_PIN_BTN_MENU2 = 74,\n CFG_PIN_BATTSENSE = 75,\n CFG_PIN_VIBRATION = 76,\n CFG_PIN_PWREN = 77,\n CFG_DISPLAY_TYPE = 78,\n CFG_PIN_ROTARY_ENCODER_A = 79,\n CFG_PIN_ROTARY_ENCODER_B = 80,\n CFG_ACCELEROMETER_SPACE = 81,\n CFG_PIN_WIFI_MOSI = 82,\n CFG_PIN_WIFI_MISO = 83,\n CFG_PIN_WIFI_SCK = 84,\n CFG_PIN_WIFI_TX = 85,\n CFG_PIN_WIFI_RX = 86,\n CFG_PIN_WIFI_CS = 87,\n CFG_PIN_WIFI_BUSY = 88,\n CFG_PIN_WIFI_RESET = 89,\n CFG_PIN_WIFI_GPIO0 = 90,\n CFG_PIN_WIFI_AT_TX = 91,\n CFG_PIN_WIFI_AT_RX = 92,\n CFG_PIN_USB_POWER = 93,\n ACCELEROMETER_TYPE_LIS3DH = 50,\n ACCELEROMETER_TYPE_LIS3DH_ALT = 48,\n ACCELEROMETER_TYPE_MMA8453 = 56,\n ACCELEROMETER_TYPE_FXOS8700 = 60,\n ACCELEROMETER_TYPE_MMA8653 = 58,\n ACCELEROMETER_TYPE_MSA300 = 76,\n ACCELEROMETER_TYPE_MPU6050 = 104,\n DISPLAY_TYPE_ST7735 = 7735,\n DISPLAY_TYPE_ILI9341 = 9341,\n DISPLAY_TYPE_SMART = 4242,\n CFG_PIN_A0 = 100,\n CFG_PIN_A1 = 101,\n CFG_PIN_A2 = 102,\n CFG_PIN_A3 = 103,\n CFG_PIN_A4 = 104,\n CFG_PIN_A5 = 105,\n CFG_PIN_A6 = 106,\n CFG_PIN_A7 = 107,\n CFG_PIN_A8 = 108,\n CFG_PIN_A9 = 109,\n CFG_PIN_A10 = 110,\n CFG_PIN_A11 = 111,\n CFG_PIN_A12 = 112,\n CFG_PIN_A13 = 113,\n CFG_PIN_A14 = 114,\n CFG_PIN_A15 = 115,\n CFG_PIN_A16 = 116,\n CFG_PIN_A17 = 117,\n CFG_PIN_A18 = 118,\n CFG_PIN_A19 = 119,\n CFG_PIN_A20 = 120,\n CFG_PIN_A21 = 121,\n CFG_PIN_A22 = 122,\n CFG_PIN_A23 = 123,\n CFG_PIN_A24 = 124,\n CFG_PIN_A25 = 125,\n CFG_PIN_A26 = 126,\n CFG_PIN_A27 = 127,\n CFG_PIN_A28 = 128,\n CFG_PIN_A29 = 129,\n CFG_PIN_A30 = 130,\n CFG_PIN_A31 = 131,\n CFG_PIN_D0 = 150,\n CFG_PIN_D1 = 151,\n CFG_PIN_D2 = 152,\n CFG_PIN_D3 = 153,\n CFG_PIN_D4 = 154,\n CFG_PIN_D5 = 155,\n CFG_PIN_D6 = 156,\n CFG_PIN_D7 = 157,\n CFG_PIN_D8 = 158,\n CFG_PIN_D9 = 159,\n CFG_PIN_D10 = 160,\n CFG_PIN_D11 = 161,\n CFG_PIN_D12 = 162,\n CFG_PIN_D13 = 163,\n CFG_PIN_D14 = 164,\n CFG_PIN_D15 = 165,\n CFG_PIN_D16 = 166,\n CFG_PIN_D17 = 167,\n CFG_PIN_D18 = 168,\n CFG_PIN_D19 = 169,\n CFG_PIN_D20 = 170,\n CFG_PIN_D21 = 171,\n CFG_PIN_D22 = 172,\n CFG_PIN_D23 = 173,\n CFG_PIN_D24 = 174,\n CFG_PIN_D25 = 175,\n CFG_PIN_D26 = 176,\n CFG_PIN_D27 = 177,\n CFG_PIN_D28 = 178,\n CFG_PIN_D29 = 179,\n CFG_PIN_D30 = 180,\n CFG_PIN_D31 = 181,\n CFG_NUM_NEOPIXELS = 200,\n CFG_NUM_DOTSTARS = 201,\n CFG_DEFAULT_BUTTON_MODE = 202,\n CFG_SWD_ENABLED = 203,\n CFG_FLASH_BYTES = 204,\n CFG_RAM_BYTES = 205,\n CFG_SYSTEM_HEAP_BYTES = 206,\n CFG_LOW_MEM_SIMULATION_KB = 207,\n CFG_BOOTLOADER_BOARD_ID = 208,\n CFG_UF2_FAMILY = 209,\n CFG_PINS_PORT_SIZE = 210,\n CFG_BOOTLOADER_PROTECTION = 211,\n CFG_POWER_DEEPSLEEP_TIMEOUT = 212,\n CFG_ANALOG_BUTTON_THRESHOLD = 213,\n CFG_CPU_MHZ = 214,\n CFG_CONTROLLER_LIGHT_MAX_BRIGHTNESS = 215,\n CFG_ANALOG_JOYSTICK_MIN = 216,\n CFG_ANALOG_JOYSTICK_MAX = 217,\n CFG_TIMERS_TO_USE = 218,\n CFG_PIN_ONBOARD_DOTSTAR_CLOCK = 219,\n CFG_PIN_ONBOARD_DOTSTAR_DATA = 220,\n CFG_NUM_ONBOARD_DOTSTARS = 221,\n CFG_PIN_ONBOARD_NEOPIXEL = 222,\n CFG_NUM_ONBOARD_NEOPIXELS = 223,\n CFG_MATRIX_KEYPAD_MESSAGE_ID = 239,\n CFG_NUM_MATRIX_KEYPAD_ROWS = 240,\n CFG_PIN_MATRIX_KEYPAD_ROW0 = 241,\n CFG_PIN_MATRIX_KEYPAD_ROW1 = 242,\n CFG_PIN_MATRIX_KEYPAD_ROW2 = 243,\n CFG_PIN_MATRIX_KEYPAD_ROW3 = 244,\n CFG_PIN_MATRIX_KEYPAD_ROW4 = 245,\n CFG_PIN_MATRIX_KEYPAD_ROW5 = 246,\n CFG_PIN_MATRIX_KEYPAD_ROW6 = 247,\n CFG_PIN_MATRIX_KEYPAD_ROW7 = 248,\n CFG_NUM_MATRIX_KEYPAD_COLS = 250,\n CFG_PIN_MATRIX_KEYPAD_COL0 = 251,\n CFG_PIN_MATRIX_KEYPAD_COL1 = 252,\n CFG_PIN_MATRIX_KEYPAD_COL2 = 253,\n CFG_PIN_MATRIX_KEYPAD_COL3 = 254,\n CFG_PIN_MATRIX_KEYPAD_COL4 = 255,\n CFG_PIN_MATRIX_KEYPAD_COL5 = 256,\n CFG_PIN_MATRIX_KEYPAD_COL6 = 257,\n CFG_PIN_MATRIX_KEYPAD_COL7 = 258,\n CFG_PIN_B0 = 300,\n CFG_PIN_B1 = 301,\n CFG_PIN_B2 = 302,\n CFG_PIN_B3 = 303,\n CFG_PIN_B4 = 304,\n CFG_PIN_B5 = 305,\n CFG_PIN_B6 = 306,\n CFG_PIN_B7 = 307,\n CFG_PIN_B8 = 308,\n CFG_PIN_B9 = 309,\n CFG_PIN_B10 = 310,\n CFG_PIN_B11 = 311,\n CFG_PIN_B12 = 312,\n CFG_PIN_B13 = 313,\n CFG_PIN_B14 = 314,\n CFG_PIN_B15 = 315,\n CFG_PIN_B16 = 316,\n CFG_PIN_B17 = 317,\n CFG_PIN_B18 = 318,\n CFG_PIN_B19 = 319,\n CFG_PIN_B20 = 320,\n CFG_PIN_B21 = 321,\n CFG_PIN_B22 = 322,\n CFG_PIN_B23 = 323,\n CFG_PIN_B24 = 324,\n CFG_PIN_B25 = 325,\n CFG_PIN_B26 = 326,\n CFG_PIN_B27 = 327,\n CFG_PIN_B28 = 328,\n CFG_PIN_B29 = 329,\n CFG_PIN_B30 = 330,\n CFG_PIN_B31 = 331,\n CFG_PIN_C0 = 350,\n CFG_PIN_C1 = 351,\n CFG_PIN_C2 = 352,\n CFG_PIN_C3 = 353,\n CFG_PIN_C4 = 354,\n CFG_PIN_C5 = 355,\n CFG_PIN_C6 = 356,\n CFG_PIN_C7 = 357,\n CFG_PIN_C8 = 358,\n CFG_PIN_C9 = 359,\n CFG_PIN_C10 = 360,\n CFG_PIN_C11 = 361,\n CFG_PIN_C12 = 362,\n CFG_PIN_C13 = 363,\n CFG_PIN_C14 = 364,\n CFG_PIN_C15 = 365,\n CFG_PIN_C16 = 366,\n CFG_PIN_C17 = 367,\n CFG_PIN_C18 = 368,\n CFG_PIN_C19 = 369,\n CFG_PIN_C20 = 370,\n CFG_PIN_C21 = 371,\n CFG_PIN_C22 = 372,\n CFG_PIN_C23 = 373,\n CFG_PIN_C24 = 374,\n CFG_PIN_C25 = 375,\n CFG_PIN_C26 = 376,\n CFG_PIN_C27 = 377,\n CFG_PIN_C28 = 378,\n CFG_PIN_C29 = 379,\n CFG_PIN_C30 = 380,\n CFG_PIN_C31 = 381,\n CFG_PIN_P0 = 400,\n CFG_PIN_P1 = 401,\n CFG_PIN_P2 = 402,\n CFG_PIN_P3 = 403,\n CFG_PIN_P4 = 404,\n CFG_PIN_P5 = 405,\n CFG_PIN_P6 = 406,\n CFG_PIN_P7 = 407,\n CFG_PIN_P8 = 408,\n CFG_PIN_P9 = 409,\n CFG_PIN_P10 = 410,\n CFG_PIN_P11 = 411,\n CFG_PIN_P12 = 412,\n CFG_PIN_P13 = 413,\n CFG_PIN_P14 = 414,\n CFG_PIN_P15 = 415,\n CFG_PIN_P16 = 416,\n CFG_PIN_P17 = 417,\n CFG_PIN_P18 = 418,\n CFG_PIN_P19 = 419,\n CFG_PIN_P20 = 420,\n CFG_PIN_P21 = 421,\n CFG_PIN_P22 = 422,\n CFG_PIN_P23 = 423,\n CFG_PIN_P24 = 424,\n CFG_PIN_P25 = 425,\n CFG_PIN_P26 = 426,\n CFG_PIN_P27 = 427,\n CFG_PIN_P28 = 428,\n CFG_PIN_P29 = 429,\n CFG_PIN_P30 = 430,\n CFG_PIN_P31 = 431,\n CFG_PIN_LORA_MISO = 1001,\n CFG_PIN_LORA_MOSI = 1002,\n CFG_PIN_LORA_SCK = 1003,\n CFG_PIN_LORA_CS = 1004,\n CFG_PIN_LORA_BOOT = 1005,\n CFG_PIN_LORA_RESET = 1006,\n CFG_PIN_IRRXLED = 1007,\n CFG_PIN_IRTXLED = 1008,\n CFG_PIN_LCD_RESET = 1009,\n CFG_PIN_LCD_ENABLE = 1010,\n CFG_PIN_LCD_DATALINE4 = 1011,\n CFG_PIN_LCD_DATALINE5 = 1012,\n CFG_PIN_LCD_DATALINE6 = 1013,\n CFG_PIN_LCD_DATALINE7 = 1014,\n CFG_NUM_LCD_COLUMNS = 1015,\n CFG_NUM_LCD_ROWS = 1016,\n CFG_PIN_RCC0 = 1017,\n CFG_PIN_RCC1 = 1018,\n CFG_PIN_RCC2 = 1019,\n CFG_PIN_RCC3 = 1020,\n CFG_PIN_RCC4 = 1021,\n CFG_PIN_RCC5 = 1022,\n CFG_PIN_RCC6 = 1023,\n CFG_PIN_RCC7 = 1024,\n CFG_PIN_SERVO0 = 1025,\n CFG_PIN_SERVO1 = 1026,\n CFG_PIN_SERVO2 = 1027,\n CFG_PIN_SERVO3 = 1028,\n CFG_PIN_SERVO4 = 1029,\n CFG_PIN_SERVO5 = 1030,\n CFG_PIN_SERVO6 = 1031,\n CFG_PIN_SERVO7 = 1032,\n CFG_PIN_SERVO8 = 1033,\n CFG_PIN_PI_TX = 1034,\n CFG_PIN_PI_RX = 1035,\n CFG_PIN_GPS_SDA = 1036,\n CFG_PIN_GPS_SCL = 1037,\n CFG_PIN_GPS_TX = 1038,\n CFG_PIN_GPS_RX = 1039,\n CFG_PIN_GROVE0 = 1040,\n CFG_PIN_GROVE1 = 1041,\n CFG_PIN_SS = 1042,\n CFG_PIN_D33 = 183,\n CFG_PIN_D34 = 184,\n CFG_PIN_D35 = 185,\n CFG_PIN_D36 = 186,\n CFG_PIN_D37 = 187,\n CFG_PIN_D38 = 188,\n CFG_PIN_D39 = 189,\n CFG_PIN_D40 = 190,\n CFG_PIN_D41 = 191,\n CFG_PIN_D42 = 192,\n CFG_PIN_D43 = 193,\n CFG_PIN_D44 = 194,\n CFG_PIN_D45 = 195,\n CFG_PIN_D46 = 196,\n CFG_PIN_D47 = 197,\n CFG_PIN_D48 = 198,\n CFG_PIN_D49 = 199,\n CFG_PIN_D50 = 259,\n CFG_PIN_D51 = 260,\n CFG_PIN_D52 = 261,\n CFG_PIN_D53 = 262,\n CFG_PIN_TX1 = 263,\n CFG_PIN_TX2 = 264,\n CFG_PIN_TX3 = 265,\n CFG_PIN_RX1 = 266,\n CFG_PIN_RX2 = 267,\n CFG_PIN_RX3 = 268,\n CFG_PIN_SCL1 = 269,\n CFG_PIN_SDA1 = 270,\n CFG_PIN_PCC_D0 = 271,\n CFG_PIN_PCC_D1 = 272,\n CFG_PIN_PCC_D2 = 273,\n CFG_PIN_PCC_D3 = 274,\n CFG_PIN_PCC_D4 = 275,\n CFG_PIN_PCC_D5 = 276,\n CFG_PIN_PCC_D6 = 277,\n CFG_PIN_PCC_D7 = 278,\n CFG_PIN_PCC_D8 = 279,\n CFG_PIN_PCC_D9 = 280,\n CFG_PIN_PCC_D10 = 281,\n CFG_PIN_PCC_D11 = 282,\n CFG_PIN_PCC_D12 = 283,\n CFG_PIN_PCC_D13 = 284,\n CFG_PIN_CC_DEN1 = 285,\n CFG_PIN_CC_DEN2 = 286,\n CFG_PIN_CC_CLK = 287,\n CFG_PIN_XCC_CLK = 288,\n CFG_PIN_JDPWR_PRE_SENSE = 1100,\n CFG_PIN_JDPWR_GND_SENSE = 1101,\n CFG_PIN_JDPWR_PULSE = 1102,\n CFG_PIN_JDPWR_OVERLOAD_LED = 1103,\n CFG_PIN_JDPWR_ENABLE = 1104,\n CFG_PIN_JDPWR_FAULT = 1105,\n // /pxtapp/platform.h\n PXT_MICROBIT_TAGGED_INT = 1,\n PXT_POWI = 1,\n // /pxtapp/pxtbase.h\n PXT_UTF8 = 0,\n PXT32 = 1,\n PXT64 = 1,\n PXT_REFCNT_FLASH = 65534,\n VTABLE_MAGIC = 249,\n Undefined = 0,\n Boolean = 1,\n Number = 2,\n String = 3,\n Object = 4,\n Function = 5,\n BoxedString = 1,\n BoxedNumber = 2,\n BoxedBuffer = 3,\n RefAction = 4,\n RefImage = 5,\n RefCollection = 6,\n RefRefLocal = 7,\n RefMap = 8,\n RefMImage = 9,\n MMap = 10,\n User0 = 16,\n PXT_VM_HEAP_ALLOC_BITS = 20,\n IMAGE_HEADER_MAGIC = 135,\n Int8LE = 1,\n UInt8LE = 2,\n Int16LE = 3,\n UInt16LE = 4,\n Int32LE = 5,\n Int8BE = 6,\n UInt8BE = 7,\n Int16BE = 8,\n UInt16BE = 9,\n Int32BE = 10,\n UInt32LE = 11,\n UInt32BE = 12,\n Float32LE = 13,\n Float64LE = 14,\n Float32BE = 15,\n Float64BE = 16,\n NUM_TRY_FRAME_REGS = 3,\n GC = 0,\n // /pxtapp/pxtcore.h\n GC_MAX_ALLOC_SIZE = 9000,\n NON_GC_HEAP_RESERVATION = 1024,\n GC_BLOCK_SIZE = 256,\n}\n",
2732
2732
  "enums.d.ts": "// Auto-generated. Do not edit.\n\n\n declare const enum NumberFormat {\n Int8LE = 1,\n UInt8LE = 2,\n Int16LE = 3,\n UInt16LE = 4,\n Int32LE = 5,\n Int8BE = 6,\n UInt8BE = 7,\n Int16BE = 8,\n UInt16BE = 9,\n Int32BE = 10,\n\n UInt32LE = 11,\n UInt32BE = 12,\n Float32LE = 13,\n Float64LE = 14,\n Float32BE = 15,\n Float64BE = 16,\n }\n\n\n declare const enum PerfCounters {\n GC = 0,\n }\ndeclare namespace images {\n}\ndeclare namespace basic {\n}\n\n\n declare const enum Button {\n A = 1, // MICROBIT_ID_BUTTON_A\n B = 2, // MICROBIT_ID_BUTTON_B\n //% block=\"A+B\"\n AB = 3, // MICROBIT_ID_BUTTON_AB\n }\n\n\n declare const enum Dimension {\n //% block=x\n X = 0,\n //% block=y\n Y = 1,\n //% block=z\n Z = 2,\n //% block=strength\n Strength = 3,\n }\n\n\n declare const enum Rotation {\n //% block=pitch\n Pitch = 0,\n //% block=roll\n Roll = 1,\n }\n\n\n declare const enum TouchPin {\n P0 = 100, // MICROBIT_ID_IO_P0\n P1 = 101, // MICROBIT_ID_IO_P1\n P2 = 102, // MICROBIT_ID_IO_P2\n }\n\n\n declare const enum AcceleratorRange {\n /**\n * The accelerator measures forces up to 1 gravity\n */\n //% block=\"1g\"\n OneG = 1,\n /**\n * The accelerator measures forces up to 2 gravity\n */\n //% block=\"2g\"\n TwoG = 2,\n /**\n * The accelerator measures forces up to 4 gravity\n */\n //% block=\"4g\"\n FourG = 4,\n /**\n * The accelerator measures forces up to 8 gravity\n */\n //% block=\"8g\"\n EightG = 8,\n }\n\n\n declare const enum Gesture {\n /**\n * Raised when shaken\n */\n //% block=shake\n //% jres=gestures.shake\n Shake = 11, // MICROBIT_ACCELEROMETER_EVT_SHAKE\n /**\n * Raised when the logo is upward and the screen is vertical\n */\n //% block=\"logo up\"\n //% jres=gestures.tiltforward\n LogoUp = 1, // MICROBIT_ACCELEROMETER_EVT_TILT_UP\n /**\n * Raised when the logo is downward and the screen is vertical\n */\n //% block=\"logo down\"\n //% jres=gestures.tiltbackwards\n LogoDown = 2, // MICROBIT_ACCELEROMETER_EVT_TILT_DOWN\n /**\n * Raised when the screen is pointing up and the board is horizontal\n */\n //% block=\"screen up\"\n //% jres=gestures.frontsideup\n ScreenUp = 5, // MICROBIT_ACCELEROMETER_EVT_FACE_UP\n /**\n * Raised when the screen is pointing down and the board is horizontal\n */\n //% block=\"screen down\"\n //% jres=gestures.backsideup\n ScreenDown = 6, // MICROBIT_ACCELEROMETER_EVT_FACE_DOWN\n /**\n * Raised when the screen is pointing left\n */\n //% block=\"tilt left\"\n //% jres=gestures.tiltleft\n TiltLeft = 3, // MICROBIT_ACCELEROMETER_EVT_TILT_LEFT\n /**\n * Raised when the screen is pointing right\n */\n //% block=\"tilt right\"\n //% jres=gestures.tiltright\n TiltRight = 4, // MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT\n /**\n * Raised when the board is falling!\n */\n //% block=\"free fall\"\n //% jres=gestures.freefall\n FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL\n /**\n * Raised when a 3G shock is detected\n */\n //% block=\"3g\"\n //% jres=gestures.impact3g\n ThreeG = 8, // MICROBIT_ACCELEROMETER_EVT_3G\n /**\n * Raised when a 6G shock is detected\n */\n //% block=\"6g\"\n //% jres=gestures.impact6g\n SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G\n /**\n * Raised when a 8G shock is detected\n */\n //% block=\"8g\"\n //% jres=gestures.impact8g\n EightG = 10, // MICROBIT_ACCELEROMETER_EVT_8G\n }\n\n\n declare const enum MesDpadButtonInfo {\n //% block=\"A down\"\n ADown = 1, // MES_DPAD_BUTTON_A_DOWN\n //% block=\"A up\"\n AUp = 2, // MES_DPAD_BUTTON_A_UP\n //% block=\"B down\"\n BDown = 3, // MES_DPAD_BUTTON_B_DOWN\n //% block=\"B up\"\n BUp = 4, // MES_DPAD_BUTTON_B_UP\n //% block=\"C down\"\n CDown = 5, // MES_DPAD_BUTTON_C_DOWN\n //% block=\"C up\"\n CUp = 6, // MES_DPAD_BUTTON_C_UP\n //% block=\"D down\"\n DDown = 7, // MES_DPAD_BUTTON_D_DOWN\n //% block=\"D up\"\n DUp = 8, // MES_DPAD_BUTTON_D_UP\n //% block=\"1 down\"\n _1Down = 9, // MES_DPAD_BUTTON_1_DOWN\n //% block=\"1 up\"\n _1Up = 10, // MES_DPAD_BUTTON_1_UP\n //% block=\"2 down\"\n _2Down = 11, // MES_DPAD_BUTTON_2_DOWN\n //% block=\"2 up\"\n _2Up = 12, // MES_DPAD_BUTTON_2_UP\n //% block=\"3 down\"\n _3Down = 13, // MES_DPAD_BUTTON_3_DOWN\n //% block=\"3 up\"\n _3Up = 14, // MES_DPAD_BUTTON_3_UP\n //% block=\"4 down\"\n _4Down = 15, // MES_DPAD_BUTTON_4_DOWN\n //% block=\"4 up\"\n _4Up = 16, // MES_DPAD_BUTTON_4_UP\n }\ndeclare namespace input {\n}\n\n\n /**\n * How to create the event.\n */\n\n declare const enum EventCreationMode {\n /**\n * MicroBitEvent is initialised, and no further processing takes place.\n */\n CreateOnly = 0, // CREATE_ONLY\n /**\n * MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).\n */\n CreateAndFire = 1, // CREATE_AND_FIRE\n }\n\n\n declare const enum EventBusSource {\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_BUTTON_A = 1, // MICROBIT_ID_BUTTON_A\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_BUTTON_B = 2, // MICROBIT_ID_BUTTON_B\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_BUTTON_AB = 3, // MICROBIT_ID_BUTTON_AB\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_RADIO = 9, // MICROBIT_ID_RADIO\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_GESTURE = 13, // MICROBIT_ID_GESTURE\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_ACCELEROMETER = 5, // MICROBIT_ID_ACCELEROMETER\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P0 = 100, // MICROBIT_ID_IO_P0\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P1 = 101, // MICROBIT_ID_IO_P1\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P2 = 102, // MICROBIT_ID_IO_P2\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P3 = 103, // MICROBIT_ID_IO_P3\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P4 = 104, // MICROBIT_ID_IO_P4\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P5 = 105, // MICROBIT_ID_IO_P5\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P6 = 106, // MICROBIT_ID_IO_P6\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P7 = 107, // MICROBIT_ID_IO_P7\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P8 = 108, // MICROBIT_ID_IO_P8\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P9 = 109, // MICROBIT_ID_IO_P9\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P10 = 110, // MICROBIT_ID_IO_P10\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P11 = 111, // MICROBIT_ID_IO_P11\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P12 = 112, // MICROBIT_ID_IO_P12\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P13 = 113, // MICROBIT_ID_IO_P13\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P14 = 114, // MICROBIT_ID_IO_P14\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P15 = 115, // MICROBIT_ID_IO_P15\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P16 = 116, // MICROBIT_ID_IO_P16\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P19 = 119, // MICROBIT_ID_IO_P19\n //% blockIdentity=\"control.eventSourceId\"\n MICROBIT_ID_IO_P20 = 120, // MICROBIT_ID_IO_P20\n //% blockIdentity=\"control.eventSourceId\"\n MES_DEVICE_INFO_ID = 1103, // MES_DEVICE_INFO_ID\n //% blockIdentity=\"control.eventSourceId\"\n MES_SIGNAL_STRENGTH_ID = 1101, // MES_SIGNAL_STRENGTH_ID\n //% blockIdentity=\"control.eventSourceId\"\n MES_DPAD_CONTROLLER_ID = 1104, // MES_DPAD_CONTROLLER_ID\n //% blockIdentity=\"control.eventSourceId\"\n MES_BROADCAST_GENERAL_ID = 2000, // MES_BROADCAST_GENERAL_ID\n }\n\n\n declare const enum EventBusValue {\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_EVT_ANY = 0, // MICROBIT_EVT_ANY\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_BUTTON_EVT_DOWN = 1, // MICROBIT_BUTTON_EVT_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_BUTTON_EVT_UP = 2, // MICROBIT_BUTTON_EVT_UP\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_BUTTON_EVT_CLICK = 3, // MICROBIT_BUTTON_EVT_CLICK\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_RADIO_EVT_DATAGRAM = 1, // MICROBIT_RADIO_EVT_DATAGRAM\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1, // MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_PIN_EVT_RISE = 2, // MICROBIT_PIN_EVT_RISE\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_PIN_EVT_FALL = 3, // MICROBIT_PIN_EVT_FALL\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_PIN_EVT_PULSE_HI = 4, // MICROBIT_PIN_EVT_PULSE_HI\n //% blockIdentity=\"control.eventValueId\"\n MICROBIT_PIN_EVT_PULSE_LO = 5, // MICROBIT_PIN_EVT_PULSE_LO\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM1 = 6, // MES_ALERT_EVT_ALARM1\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM2 = 7, // MES_ALERT_EVT_ALARM2\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM3 = 8, // MES_ALERT_EVT_ALARM3\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM4 = 9, // MES_ALERT_EVT_ALARM4\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM5 = 10, // MES_ALERT_EVT_ALARM5\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_ALARM6 = 11, // MES_ALERT_EVT_ALARM6\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_DISPLAY_TOAST = 1, // MES_ALERT_EVT_DISPLAY_TOAST\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_FIND_MY_PHONE = 5, // MES_ALERT_EVT_FIND_MY_PHONE\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_PLAY_RINGTONE = 4, // MES_ALERT_EVT_PLAY_RINGTONE\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_PLAY_SOUND = 3, // MES_ALERT_EVT_PLAY_SOUND\n //% blockIdentity=\"control.eventValueId\"\n MES_ALERT_EVT_VIBRATE = 2, // MES_ALERT_EVT_VIBRATE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_LAUNCH_PHOTO_MODE = 1, // MES_CAMERA_EVT_LAUNCH_PHOTO_MODE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_LAUNCH_VIDEO_MODE = 2, // MES_CAMERA_EVT_LAUNCH_VIDEO_MODE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_START_VIDEO_CAPTURE = 4, // MES_CAMERA_EVT_START_VIDEO_CAPTURE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_STOP_PHOTO_MODE = 6, // MES_CAMERA_EVT_STOP_PHOTO_MODE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_STOP_VIDEO_CAPTURE = 5, // MES_CAMERA_EVT_STOP_VIDEO_CAPTURE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_STOP_VIDEO_MODE = 7, // MES_CAMERA_EVT_STOP_VIDEO_MODE\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_TAKE_PHOTO = 3, // MES_CAMERA_EVT_TAKE_PHOTO\n //% blockIdentity=\"control.eventValueId\"\n MES_CAMERA_EVT_TOGGLE_FRONT_REAR = 8, // MES_CAMERA_EVT_TOGGLE_FRONT_REAR\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_DISPLAY_OFF = 5, // MES_DEVICE_DISPLAY_OFF\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_DISPLAY_ON = 6, // MES_DEVICE_DISPLAY_ON\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4, // MES_DEVICE_GESTURE_DEVICE_SHAKEN\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_INCOMING_CALL = 7, // MES_DEVICE_INCOMING_CALL\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_INCOMING_MESSAGE = 8, // MES_DEVICE_INCOMING_MESSAGE\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_ORIENTATION_LANDSCAPE = 1, // MES_DEVICE_ORIENTATION_LANDSCAPE\n //% blockIdentity=\"control.eventValueId\"\n MES_DEVICE_ORIENTATION_PORTRAIT = 2, // MES_DEVICE_ORIENTATION_PORTRAIT\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_1_DOWN = 9, // MES_DPAD_BUTTON_1_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_1_UP = 10, // MES_DPAD_BUTTON_1_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_2_DOWN = 11, // MES_DPAD_BUTTON_2_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_2_UP = 12, // MES_DPAD_BUTTON_2_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_3_DOWN = 13, // MES_DPAD_BUTTON_3_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_3_UP = 14, // MES_DPAD_BUTTON_3_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_4_DOWN = 15, // MES_DPAD_BUTTON_4_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_4_UP = 16, // MES_DPAD_BUTTON_4_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_A_DOWN = 1, // MES_DPAD_BUTTON_A_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_A_UP = 2, // MES_DPAD_BUTTON_A_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_B_DOWN = 3, // MES_DPAD_BUTTON_B_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_B_UP = 4, // MES_DPAD_BUTTON_B_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_C_DOWN = 5, // MES_DPAD_BUTTON_C_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_C_UP = 6, // MES_DPAD_BUTTON_C_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_D_DOWN = 7, // MES_DPAD_BUTTON_D_DOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_DPAD_BUTTON_D_UP = 8, // MES_DPAD_BUTTON_D_UP\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_FORWARD = 6, // MES_REMOTE_CONTROL_EVT_FORWARD\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_NEXTTRACK = 4, // MES_REMOTE_CONTROL_EVT_NEXTTRACK\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_PAUSE = 2, // MES_REMOTE_CONTROL_EVT_PAUSE\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_PLAY = 1, // MES_REMOTE_CONTROL_EVT_PLAY\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_PREVTRACK = 5, // MES_REMOTE_CONTROL_EVT_PREVTRACK\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_REWIND = 7, // MES_REMOTE_CONTROL_EVT_REWIND\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_STOP = 3, // MES_REMOTE_CONTROL_EVT_STOP\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_VOLUMEDOWN = 9, // MES_REMOTE_CONTROL_EVT_VOLUMEDOWN\n //% blockIdentity=\"control.eventValueId\"\n MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP\n }\n\n\n declare const enum EventFlags {\n //%\n QueueIfBusy = 16, // MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY\n //%\n DropIfBusy = 32, // MESSAGE_BUS_LISTENER_DROP_IF_BUSY\n //%\n Reentrant = 8, // MESSAGE_BUS_LISTENER_REENTRANT\n }\ndeclare namespace control {\n}\n\n\n declare const enum DisplayMode {\n //% block=\"black and white\"\n BlackAndWhite = 0, // DISPLAY_MODE_BLACK_AND_WHITE\n //% blockHidden=true\n BackAndWhite = 0, // DISPLAY_MODE_BLACK_AND_WHITE\n //% block=\"greyscale\"\n Greyscale = 1, // DISPLAY_MODE_GREYSCALE\n // TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE\n }\ndeclare namespace led {\n}\n\n\n declare const enum DigitalPin {\n P0 = 100, // MICROBIT_ID_IO_P0\n P1 = 101, // MICROBIT_ID_IO_P1\n P2 = 102, // MICROBIT_ID_IO_P2\n P3 = 103, // MICROBIT_ID_IO_P3\n P4 = 104, // MICROBIT_ID_IO_P4\n P5 = 105, // MICROBIT_ID_IO_P5\n P6 = 106, // MICROBIT_ID_IO_P6\n P7 = 107, // MICROBIT_ID_IO_P7\n P8 = 108, // MICROBIT_ID_IO_P8\n P9 = 109, // MICROBIT_ID_IO_P9\n P10 = 110, // MICROBIT_ID_IO_P10\n P11 = 111, // MICROBIT_ID_IO_P11\n P12 = 112, // MICROBIT_ID_IO_P12\n P13 = 113, // MICROBIT_ID_IO_P13\n P14 = 114, // MICROBIT_ID_IO_P14\n P15 = 115, // MICROBIT_ID_IO_P15\n P16 = 116, // MICROBIT_ID_IO_P16\n //% blockHidden=1\n P19 = 119, // MICROBIT_ID_IO_P19\n //% blockHidden=1\n P20 = 120, // MICROBIT_ID_IO_P20\n }\n\n\n declare const enum AnalogPin {\n P0 = 100, // MICROBIT_ID_IO_P0\n P1 = 101, // MICROBIT_ID_IO_P1\n P2 = 102, // MICROBIT_ID_IO_P2\n P3 = 103, // MICROBIT_ID_IO_P3\n P4 = 104, // MICROBIT_ID_IO_P4\n P10 = 110, // MICROBIT_ID_IO_P10\n //% block=\"P5 (write only)\"\n P5 = 105, // MICROBIT_ID_IO_P5\n //% block=\"P6 (write only)\"\n P6 = 106, // MICROBIT_ID_IO_P6\n //% block=\"P7 (write only)\"\n P7 = 107, // MICROBIT_ID_IO_P7\n //% block=\"P8 (write only)\"\n P8 = 108, // MICROBIT_ID_IO_P8\n //% block=\"P9 (write only)\"\n P9 = 109, // MICROBIT_ID_IO_P9\n //% block=\"P11 (write only)\"\n P11 = 111, // MICROBIT_ID_IO_P11\n //% block=\"P12 (write only)\"\n P12 = 112, // MICROBIT_ID_IO_P12\n //% block=\"P13 (write only)\"\n P13 = 113, // MICROBIT_ID_IO_P13\n //% block=\"P14 (write only)\"\n P14 = 114, // MICROBIT_ID_IO_P14\n //% block=\"P15 (write only)\"\n P15 = 115, // MICROBIT_ID_IO_P15\n //% block=\"P16 (write only)\"\n P16 = 116, // MICROBIT_ID_IO_P16\n //% block=\"P19 (write only)\"\n //% blockHidden=1\n P19 = 119, // MICROBIT_ID_IO_P19\n //% block=\"P20 (write only)\"\n //% blockHidden=1\n P20 = 120, // MICROBIT_ID_IO_P20\n }\n\n\n declare const enum PulseValue {\n //% block=high\n High = 4, // MICROBIT_PIN_EVT_PULSE_HI\n //% block=low\n Low = 5, // MICROBIT_PIN_EVT_PULSE_LO\n }\n\n\n declare const enum PinPullMode {\n //% block=\"down\"\n PullDown = 0,\n //% block=\"up\"\n PullUp = 1,\n //% block=\"none\"\n PullNone = 2,\n }\n\n\n declare const enum PinEventType {\n //% block=\"edge\"\n Edge = 2, // MICROBIT_PIN_EVENT_ON_EDGE\n //% block=\"pulse\"\n Pulse = 3, // MICROBIT_PIN_EVENT_ON_PULSE\n //% block=\"touch\"\n Touch = 4, // MICROBIT_PIN_EVENT_ON_TOUCH\n //% block=\"none\"\n None = 0, // MICROBIT_PIN_EVENT_NONE\n }\n\n\n declare const enum SerialPin {\n P0 = 100, // MICROBIT_ID_IO_P0\n P1 = 101, // MICROBIT_ID_IO_P1\n P2 = 102, // MICROBIT_ID_IO_P2\n P8 = 108, // MICROBIT_ID_IO_P8\n P12 = 112, // MICROBIT_ID_IO_P12\n P13 = 113, // MICROBIT_ID_IO_P13\n P14 = 114, // MICROBIT_ID_IO_P14\n P15 = 115, // MICROBIT_ID_IO_P15\n P16 = 116, // MICROBIT_ID_IO_P16\n USB_TX = 1001,\n USB_RX = 1002,\n }\n\n\n declare const enum BaudRate {\n //% block=115200\n BaudRate115200 = 115200,\n //% block=57600\n BaudRate57600 = 57600,\n //% block=38400\n BaudRate38400 = 38400,\n //% block=31250\n BaudRate31250 = 31250,\n //% block=28800\n BaudRate28800 = 28800,\n //% block=19200\n BaudRate19200 = 19200,\n //% block=14400\n BaudRate14400 = 14400,\n //% block=9600\n BaudRate9600 = 9600,\n //% block=4800\n BaudRate4800 = 4800,\n //% block=2400\n BaudRate2400 = 2400,\n //% block=1200\n BaudRate1200 = 1200,\n }\ndeclare namespace serial {\n}\n\n\n /**\n * An action on a touch button\n */\n\n declare const enum TouchButtonEvent {\n //% block=pressed\n Pressed = 3, // MICROBIT_BUTTON_EVT_CLICK\n //% block=touched\n Touched = 1, // MICROBIT_BUTTON_EVT_DOWN\n //% block=released\n Released = 2, // MICROBIT_BUTTON_EVT_UP\n //% block=\"long pressed\"\n LongPressed = 4, // MICROBIT_BUTTON_EVT_LONG_CLICK\n }\n\n\n declare const enum TouchTargetMode {\n //% block=\"capacitive\"\n Capacitive = 1,\n //% block=\"resistive\"\n Resistive = 0,\n }\n\n\n declare const enum TouchTarget {\n //% block=\"P0\"\n P0 = 100, // MICROBIT_ID_IO_P0\n //% block=\"P1\"\n P1 = 101, // MICROBIT_ID_IO_P1\n //% block=\"P2\"\n P2 = 102, // MICROBIT_ID_IO_P2\n //% block=\"logo\"\n LOGO = 121, // MICROBIT_ID_LOGO\n }\n\n// Auto-generated. Do not edit. Really.\n",
2733
- "fixed.ts": "interface Fx8 {\n _dummyFx8: string;\n}\n\nfunction Fx8(v: number) {\n return ((v * 256) | 0) as any as Fx8\n}\n\nnamespace Fx {\n export const zeroFx8 = 0 as any as Fx8\n export const oneHalfFx8 = 128 as any as Fx8\n export const oneFx8 = 256 as any as Fx8\n export const twoFx8 = 512 as any as Fx8\n\n export function neg(a: Fx8) {\n return (-(a as any as number)) as any as Fx8\n }\n export function toIntShifted(a: Fx8, n: number) {\n return (a as any as number) >> (n + 8)\n }\n export function add(a: Fx8, b: Fx8) {\n return ((a as any as number) + (b as any as number)) as any as Fx8\n }\n export function iadd(a: number, b: Fx8) {\n return ((a << 8) + (b as any as number)) as any as Fx8\n }\n export function sub(a: Fx8, b: Fx8) {\n return ((a as any as number) - (b as any as number)) as any as Fx8\n }\n export function mul(a: Fx8, b: Fx8) {\n return (Math.imul((a as any as number), (b as any as number)) >> 8) as any as Fx8\n }\n export function imul(a: Fx8, b: number) {\n return Math.imul((a as any as number), (b as any as number)) as any as Fx8\n }\n export function div(a: Fx8, b: Fx8) {\n return Math.idiv((a as any as number) << 8, b as any as number) as any as Fx8\n }\n export function idiv(a: Fx8, b: number) {\n return Math.idiv((a as any as number), b) as any as Fx8\n }\n export function compare(a: Fx8, b: Fx8) {\n return (a as any as number) - (b as any as number)\n }\n export function abs(a: Fx8) {\n if ((a as any as number) < 0)\n return (-(a as any as number)) as any as Fx8\n else\n return a\n }\n export function min(a: Fx8, b: Fx8) {\n if (a < b)\n return a\n else\n return b\n }\n export function max(a: Fx8, b: Fx8) {\n if (a > b)\n return a\n else\n return b\n }\n export function leftShift(a: Fx8, n: number) {\n return (a as any as number << n) as any as Fx8\n }\n export function rightShift(a: Fx8, n: number) {\n return (a as any as number >> n) as any as Fx8\n }\n export function toInt(v: Fx8) {\n return ((v as any as number) + 128) >> 8\n }\n export function toFloat(v: Fx8) {\n return (v as any as number) / 256\n }\n}",
2733
+ "fixed.ts": "interface Fx8 {\n _dummyFx8: string;\n}\n\nfunction Fx8(v: number) {\n return ((v * 256) | 0) as any as Fx8\n}\n\nnamespace Fx {\n export const zeroFx8 = 0 as any as Fx8\n export const oneHalfFx8 = 128 as any as Fx8\n export const oneFx8 = 256 as any as Fx8\n export const twoFx8 = 512 as any as Fx8\n\n export function neg(a: Fx8) {\n return (-(a as any as number)) as any as Fx8\n }\n export function toIntShifted(a: Fx8, n: number) {\n return (a as any as number) >> (n + 8)\n }\n export function add(a: Fx8, b: Fx8) {\n return ((a as any as number) + (b as any as number)) as any as Fx8\n }\n export function iadd(a: number, b: Fx8) {\n return ((a << 8) + (b as any as number)) as any as Fx8\n }\n export function sub(a: Fx8, b: Fx8) {\n return ((a as any as number) - (b as any as number)) as any as Fx8\n }\n export function mul(a: Fx8, b: Fx8) {\n return (Math.imul((a as any as number), (b as any as number)) >> 8) as any as Fx8\n }\n export function imul(a: Fx8, b: number) {\n return Math.imul((a as any as number), (b as any as number)) as any as Fx8\n }\n export function div(a: Fx8, b: Fx8) {\n return Math.idiv((a as any as number) << 8, b as any as number) as any as Fx8\n }\n export function idiv(a: Fx8, b: number) {\n return Math.idiv((a as any as number), b) as any as Fx8\n }\n export function compare(a: Fx8, b: Fx8) {\n return (a as any as number) - (b as any as number)\n }\n export function abs(a: Fx8) {\n if ((a as any as number) < 0)\n return (-(a as any as number)) as any as Fx8\n else\n return a\n }\n export function min(a: Fx8, b: Fx8) {\n if (a < b)\n return a\n else\n return b\n }\n export function max(a: Fx8, b: Fx8) {\n if (a > b)\n return a\n else\n return b\n }\n export function floor(v: Fx8): Fx8 {\n return ((v as any as number) & ~0xff) as any as Fx8;\n }\n export function ceil(v: Fx8): Fx8 {\n return (v as any as number) & 0xff ? Fx.floor(Fx.add(v, Fx.oneFx8)) : v;\n }\n export function leftShift(a: Fx8, n: number) {\n return (a as any as number << n) as any as Fx8\n }\n export function rightShift(a: Fx8, n: number) {\n return (a as any as number >> n) as any as Fx8\n }\n export function toInt(v: Fx8) {\n return ((v as any as number) + 128) >> 8\n }\n export function toFloat(v: Fx8) {\n return (v as any as number) / 256\n }\n}",
2734
2734
  "game.ts": "enum Direction {\n //% block=right\n Right,\n //% block=left\n Left\n}\n\nenum LedSpriteProperty {\n //% block=x\n X,\n //% block=y\n Y,\n //% block=direction\n Direction,\n //% block=brightness\n Brightness,\n //% block=blink\n Blink\n}\n\n/**\n * A single-LED sprite game engine\n */\n//% color=#007A4B weight=32 icon=\"\\uf11b\"\n//% advanced=true\nnamespace game {\n let _score: number = 0;\n let _life: number = 3;\n let _startTime: number = 0;\n let _endTime: number = 0;\n let _isGameOver: boolean = false;\n let _countdownPause: number = 0;\n let _level: number = 1;\n let _gameId: number = 0;\n let _img: Image;\n let _sprites: LedSprite[];\n let _paused: boolean = false;\n let _backgroundAnimation = false; // indicates if an auxiliary animation (and fiber) is already running\n\n /**\n * Creates a new LED sprite pointing to the right.\n * @param x sprite horizontal coordinate, eg: 2\n * @param y sprite vertical coordinate, eg: 2\n */\n //% weight=60 blockGap=8 help=game/create-sprite\n //% blockId=game_create_sprite block=\"create sprite at|x: %x|y: %y\"\n //% parts=\"ledmatrix\"\n export function createSprite(x: number, y: number): LedSprite {\n init();\n let p = new LedSprite(x, y);\n return p;\n }\n\n /**\n * Gets the current score\n */\n //% weight=9 help=game/score\n //% blockId=game_score block=\"score\" blockGap=8\n export function score(): number {\n return _score;\n }\n\n /**\n * Adds points to the current score and shows an animation\n * @param points amount of points to change, eg: 1\n */\n //% weight=10 help=game/add-score\n //% blockId=game_add_score block=\"change score by|%points\" blockGap=8\n //% parts=\"ledmatrix\"\n export function addScore(points: number): void {\n setScore(_score + points);\n if (!_paused && !_backgroundAnimation) {\n _backgroundAnimation = true;\n control.inBackground(() => {\n led.stopAnimation();\n basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20);\n _backgroundAnimation = false;\n });\n }\n }\n\n /**\n * Shows an animation, then starts a game countdown timer, which causes Game Over when it reaches 0\n * @param ms countdown duration in milliseconds, eg: 10000\n */\n //% weight=9 help=game/start-countdown\n //% blockId=game_start_countdown block=\"start countdown|(ms) %duration\" blockGap=8\n //% parts=\"ledmatrix\"\n export function startCountdown(ms: number): void {\n if (checkStart()) {\n basic.showAnimation(`1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0`, 400);\n _countdownPause = Math.max(500, ms);\n _startTime = -1;\n _endTime = input.runningTime() + _countdownPause;\n _paused = false;\n control.inBackground(() => {\n basic.pause(_countdownPause);\n gameOver();\n });\n }\n }\n\n /**\n * Displays a game over animation and the score.\n */\n //% weight=8 help=game/game-over\n //% blockId=game_game_over block=\"game over\"\n //% parts=\"ledmatrix\"\n export function gameOver(): void {\n if (!_isGameOver) {\n _isGameOver = true;\n unplugEvents();\n led.stopAnimation();\n led.setBrightness(255);\n while (true) {\n for (let i = 0; i < 8; i++) {\n basic.clearScreen();\n basic.pause(100);\n basic.showLeds(`1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1`, 300);\n }\n basic.showAnimation(`1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0`, 100);\n for (let j = 0; j < 3; j++) {\n basic.showString(\" GAMEOVER \", 100);\n showScore();\n }\n }\n } else {\n // already in game over mode in another fiber\n while (true) {\n basic.pause(10000);\n }\n }\n }\n\n /**\n * Sets the current score value\n * @param value new score value.\n */\n //% blockId=game_set_score block=\"set score %points\" blockGap=8\n //% weight=10 help=game/set-score\n export function setScore(value: number): void {\n _score = Math.max(0, value);\n }\n\n /**\n * Gets the current life\n */\n //% weight=10\n export function life(): number {\n return _life;\n }\n\n /**\n * Sets the current life value\n * @param value current life value\n */\n //% weight=10 help=game/set-life\n //% blockId=game_set_life block=\"set life %value\" blockGap=8\n export function setLife(value: number): void {\n _life = Math.max(0, value);\n if (_life <= 0) {\n gameOver();\n }\n }\n\n /**\n * Add life points to the current life amount\n * @param lives amount of lives to add\n */\n //% weight=10 help=game/add-life\n //% blockId=game_add_life block=\"add life %lives\" blockGap=8\n export function addLife(lives: number): void {\n setLife(_life + lives);\n }\n\n /**\n * Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.\n */\n //% weight=10\n export function currentTime(): number {\n if (_endTime > 0) {\n return Math.max(0, _endTime - input.runningTime());\n } else {\n return input.runningTime() - _startTime;\n }\n }\n\n /**\n * Remove some life\n * @param life amount of life to remove\n */\n //% weight=10 help=game/remove-life\n //% parts=\"ledmatrix\"\n //% blockId=game_remove_life block=\"remove life %life\" blockGap=8\n export function removeLife(life: number): void {\n setLife(_life - life);\n if (!_paused && !_backgroundAnimation) {\n _backgroundAnimation = true;\n control.inBackground(() => {\n led.stopAnimation();\n basic.showAnimation(`1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0\n0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0\n1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0`, 40);\n _backgroundAnimation = false;\n });\n }\n }\n\n /**\n * Increments the level and display a message.\n */\n //% weight=10\n //% parts=\"ledmatrix\"\n export function levelUp(): void {\n _level = _level + 1;\n basic.showString(\"LEVEL:\", 150);\n basic.showNumber(_level, 150);\n }\n\n /**\n * Gets the current level\n */\n //% weight=10\n export function level(): number {\n return _level;\n }\n\n /**\n * Starts a stopwatch timer. `current time` will return the elapsed time.\n */\n //% weight=10\n export function startStopwatch(): void {\n _startTime = input.runningTime();\n _endTime = -1;\n }\n\n /**\n * Indicates if the game is still running. Returns `false` if the game is over or paused.\n */\n //% weight=5 help=game/is-running\n //% blockId=game_isrunning block=\"is running\" blockGap=8\n export function isRunning(): boolean {\n return !_isGameOver && !_paused && !!_img;\n }\n\n /**\n * Displays the score on the screen.\n */\n //% weight=60\n //% parts=\"ledmatrix\"\n export function showScore(): void {\n basic.showString(\" SCORE \", 100);\n basic.showNumber(_score, 150);\n basic.showString(\" \", 150);\n }\n\n /**\n * Indicates if the game is over and displaying the game over sequence.\n */\n //% weight=7 help=game/is-game-over\n //% blockId=game_isgameover block=\"is game over\" blockGap=8\n export function isGameOver(): boolean {\n return _isGameOver;\n }\n\n /**\n * Indicates if the game rendering is paused to allow other animations\n */\n //% weight=6 help=game/is-paused\n //% blockId=game_ispaused block=\"is paused\" blockGap=8\n export function isPaused(): boolean {\n return _paused;\n }\n\n /**\n * Pauses the game rendering engine to allow other animations\n */\n //% blockId=game_pause block=\"pause\"\n //% advanced=true blockGap=8 help=game/pause\n export function pause(): void {\n plot()\n _paused = true;\n }\n\n\n /**\n * Resumes the game rendering engine\n */\n //% blockId=game_resume block=\"resume\"\n //% advanced=true blockGap=8 help=game/resumeP\n export function resume(): void {\n _paused = false;\n plot();\n }\n\n /**\n * returns false if game can't start\n */\n function checkStart(): boolean {\n if (_countdownPause > 0 || _startTime > 0) {\n return false;\n } else {\n return true;\n }\n }\n\n function unplugEvents(): void {\n input.onButtonPressed(Button.A, () => { });\n input.onButtonPressed(Button.B, () => { });\n input.onButtonPressed(Button.AB, () => {\n control.reset();\n });\n }\n\n /**\n * A game sprite rendered as a single LED\n */\n //%\n export class LedSprite {\n private _x: number;\n private _y: number;\n private _dir: number;\n private _brightness: number;\n private _blink: number;\n private _enabled: boolean;\n\n constructor(x: number, y: number) {\n this._x = Math.clamp(0, 4, x);\n this._y = Math.clamp(0, 4, y);\n this._dir = 90;\n this._brightness = 255;\n this._enabled = true;\n init();\n _sprites.push(this);\n plot();\n }\n\n /**\n * Move a certain number of LEDs in the current direction\n * @param this the sprite to move\n * @param leds number of leds to move, eg: 1, -1\n */\n //% weight=50 help=game/move\n //% blockId=game_move_sprite block=\"%sprite|move by %leds\" blockGap=8\n //% parts=\"ledmatrix\"\n public move(leds: number): void {\n if (this._dir == 0) {\n this._y = this._y - leds;\n } else if (this._dir == 45) {\n this._x = this._x + leds;\n this._y = this._y - leds;\n } else if (this._dir == 90) {\n this._x = this._x + leds;\n } else if (this._dir == 135) {\n this._x = this._x + leds;\n this._y = this._y + leds;\n } else if (this._dir == 180) {\n this._y = this._y + leds;\n } else if (this._dir == -45) {\n this._x = this._x - leds;\n this._y = this._y - leds;\n } else if (this._dir == -90) {\n this._x = this._x - leds;\n } else {\n this._x = this._x - leds;\n this._y = this._y + leds;\n }\n this._x = Math.clamp(0, 4, this._x);\n this._y = Math.clamp(0, 4, this._y);\n plot();\n }\n\n /**\n * Go to this position on the screen\n * @param this TODO\n * @param x TODO\n * @param y TODO\n */\n //% parts=\"ledmatrix\"\n public goTo(x: number, y: number): void {\n this._x = x;\n this._y = y;\n this._x = Math.clamp(0, 4, this._x);\n this._y = Math.clamp(0, 4, this._y);\n plot();\n }\n\n /**\n * If touching the edge of the stage and facing towards it, then turn away.\n * @param this the sprite to check for bounce\n */\n //% weight=18 help=game/if-on-edge-bounce\n //% blockId=game_sprite_bounce block=\"%sprite|if on edge, bounce\"\n //% parts=\"ledmatrix\"\n public ifOnEdgeBounce(): void {\n if (this._dir == 0 && this._y == 0) {\n this._dir = 180;\n } else if (this._dir == 45 && (this._x == 4 || this._y == 0)) {\n if (this._x == 0 && this._y == 0) {\n this._dir = -135;\n } else if (this._y == 0) {\n this._dir = 135;\n } else {\n this._dir = -45;\n }\n } else if (this._dir == 90 && this._x == 4) {\n this._dir = -90;\n } else if (this._dir == 135 && (this._x == 4 || this._y == 4)) {\n if (this.x() == 4 && this.y() == 4) {\n this._dir = -45;\n } else if (this._y == 4) {\n this._dir = 45;\n } else {\n this._dir = -135;\n }\n } else if (this._dir == 180 && this._y == 4) {\n this._dir = 0;\n } else if (this._dir == -45 && (this._x == 0 || this._y == 0)) {\n if (this.x() == 0 && this.y() == 0) {\n this._dir = 135;\n } else if (this._y == 0) {\n this._dir = -135;\n } else {\n this._dir = 45;\n }\n } else if (this._dir == -90 && this._x == 0) {\n this._dir = 90;\n } else if (this._dir == -135 && (this._x == 0 || this._y == 4)) {\n if (this._x == 0 && this._y == 4) {\n this._dir = 45;\n } else if (this._y == 4) {\n this._dir = -45;\n } else {\n this._dir = 135;\n }\n }\n plot();\n }\n\n /**\n * Turn the sprite\n * @param this the sprite to trun\n * @param direction left or right\n * @param degrees angle in degrees to turn, eg: 45, 90, 180, 135\n */\n //% weight=49 help=game/turn\n //% blockId=game_turn_sprite block=\"%sprite|turn %direction|by (°) %degrees\"\n public turn(direction: Direction, degrees: number) {\n if (direction == Direction.Right)\n this.setDirection(this._dir + degrees);\n else\n this.setDirection(this._dir - degrees);\n }\n\n /**\n * Turn to the right (clockwise)\n * @param this the sprite to turn\n * @param degrees TODO\n */\n public turnRight(degrees: number): void {\n this.turn(Direction.Right, degrees);\n }\n\n /**\n * Turn to the left (counter-clockwise)\n * @param this the sprite to turn\n * @param degrees TODO\n */\n public turnLeft(degrees: number): void {\n this.turn(Direction.Left, degrees);\n }\n\n /**\n * Sets a property of the sprite\n * @param property the name of the property to change\n * @param the updated value\n */\n //% weight=29 help=game/set\n //% blockId=game_sprite_set_property block=\"%sprite|set %property|to %value\" blockGap=8\n public set(property: LedSpriteProperty, value: number) {\n switch (property) {\n case LedSpriteProperty.X: this.setX(value); break;\n case LedSpriteProperty.Y: this.setY(value); break;\n case LedSpriteProperty.Direction: this.setDirection(value); break;\n case LedSpriteProperty.Brightness: this.setBrightness(value); break;\n case LedSpriteProperty.Blink: this.setBlink(value); break;\n }\n }\n\n /**\n * Changes a property of the sprite\n * @param property the name of the property to change\n * @param value amount of change, eg: 1\n */\n //% weight=30 help=game/change\n //% blockId=game_sprite_change_xy block=\"%sprite|change %property|by %value\" blockGap=8\n public change(property: LedSpriteProperty, value: number) {\n switch (property) {\n case LedSpriteProperty.X: this.changeXBy(value); break;\n case LedSpriteProperty.Y: this.changeYBy(value); break;\n case LedSpriteProperty.Direction: this.changeDirectionBy(value); break;\n case LedSpriteProperty.Brightness: this.changeBrightnessBy(value); break;\n case LedSpriteProperty.Blink: this.changeBlinkBy(value); break;\n }\n }\n\n /**\n * Gets a property of the sprite\n * @param property the name of the property to change\n */\n //% weight=28 help=game/get\n //% blockId=game_sprite_property block=\"%sprite|%property\"\n public get(property: LedSpriteProperty) {\n switch (property) {\n case LedSpriteProperty.X: return this.x();\n case LedSpriteProperty.Y: return this.y();\n case LedSpriteProperty.Direction: return this.direction()\n case LedSpriteProperty.Brightness: return this.brightness();\n case LedSpriteProperty.Blink: return this.blink();\n default: return 0;\n }\n }\n\n /**\n * Set the direction of the current sprite, rounded to the nearest multiple of 45\n * @param this the sprite to set direction for\n * @param degrees new direction in degrees\n */\n //% parts=\"ledmatrix\"\n public setDirection(degrees: number): void {\n this._dir = (Math.floor(degrees / 45) % 8) * 45;\n if (this._dir <= -180) {\n this._dir = this._dir + 360;\n } else if (this._dir > 180) {\n this._dir = this._dir - 360;\n }\n plot();\n }\n\n /**\n * Reports the ``x`` position of a sprite on the LED screen\n * @param this TODO\n */\n public x(): number {\n return this._x;\n }\n\n /**\n * Reports the ``y`` position of a sprite on the LED screen\n * @param this TODO\n */\n public y(): number {\n return this._y;\n }\n\n /**\n * Reports the current direction of a sprite\n * @param this TODO\n */\n public direction(): number {\n return this._dir;\n }\n\n /**\n * Set the ``x`` position of a sprite\n * @param this TODO\n * @param x TODO\n */\n public setX(x: number): void {\n this.goTo(x, this._y);\n }\n\n /**\n * Set the ``y`` position of a sprite\n * @param this TODO\n * @param y TODO\n */\n public setY(y: number): void {\n this.goTo(this._x, y);\n }\n\n /**\n * Changes the ``y`` position by the given amount\n * @param this TODO\n * @param y TODO\n */\n public changeYBy(y: number): void {\n this.goTo(this._x, this._y + y);\n }\n\n /**\n * Changes the ``x`` position by the given amount\n * @param this TODO\n * @param x TODO\n */\n public changeXBy(x: number): void {\n this.goTo(this._x + x, this._y);\n }\n\n /**\n * Reports true if sprite has the same position as specified sprite\n * @param this the sprite to check overlap or touch\n * @param other the other sprite to check overlap or touch\n */\n //% weight=20 help=game/is-touching\n //% blockId=game_sprite_touching_sprite block=\"is %sprite|touching %other\" blockGap=8\n public isTouching(other: LedSprite): boolean {\n return this._enabled && other._enabled && this._x == other._x && this._y == other._y;\n }\n\n /**\n * Reports true if sprite is touching an edge\n * @param this the sprite to check for an edge contact\n */\n //% weight=19 help=game/is-touching-edge\n //% blockId=game_sprite_touching_edge block=\"is %sprite|touching edge\" blockGap=8\n public isTouchingEdge(): boolean {\n return this._enabled && (this._x == 0 || this._x == 4 || this._y == 0 || this._y == 4);\n }\n\n /**\n * Turns on the sprite (on by default)\n * @param this the sprite\n */\n public on(): void {\n this.setBrightness(255);\n }\n\n /**\n * Turns off the sprite (on by default)\n * @param this the sprite\n */\n public off(): void {\n this.setBrightness(0);\n }\n\n /**\n * Set the ``brightness`` of a sprite\n * @param this the sprite\n * @param brightness the brightness from 0 (off) to 255 (on), eg: 255.\n */\n //% parts=\"ledmatrix\"\n public setBrightness(brightness: number): void {\n this._brightness = Math.clamp(0, 255, brightness);\n plot();\n }\n\n /**\n * Reports the ``brightness` of a sprite on the LED screen\n * @param this the sprite\n */\n //% parts=\"ledmatrix\"\n public brightness(): number {\n let r: number;\n return this._brightness;\n }\n\n /**\n * Changes the ``y`` position by the given amount\n * @param this the sprite\n * @param value the value to change brightness\n */\n public changeBrightnessBy(value: number): void {\n this.setBrightness(this._brightness + value);\n }\n\n /**\n * Changes the ``direction`` position by the given amount by turning right\n * @param this TODO\n * @param angle TODO\n */\n public changeDirectionBy(angle: number): void {\n this.turnRight(angle);\n }\n\n /**\n * Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.\n * @param this sprite to delete\n */\n //% weight=59 blockGap=8 help=game/delete\n //% blockId=\"game_delete_sprite\" block=\"delete %this(sprite)\"\n public delete(): void {\n this._enabled = false;\n if (_sprites.removeElement(this))\n plot();\n }\n\n /**\n * Reports whether the sprite has been deleted from the game engine.\n */\n //% weight=58 help=game/is-deleted\n //% blockId=\"game_sprite_is_deleted\" block=\"is %sprite|deleted\"\n public isDeleted(): boolean {\n return !this._enabled;\n }\n\n /**\n * Sets the blink duration interval in millisecond.\n * @param sprite TODO\n * @param ms TODO\n */\n public setBlink(ms: number): void {\n this._blink = Math.clamp(0, 10000, ms);\n }\n\n /**\n * Changes the ``blink`` duration by the given amount of millisecons\n * @param this TODO\n * @param ms TODO\n */\n public changeBlinkBy(ms: number): void {\n this.setBlink(this._blink + ms);\n }\n\n /**\n * Reports the ``blink`` duration of a sprite\n * @param this TODO\n */\n public blink(): number {\n return this._blink;\n }\n\n //% weight=-1\n //% parts=\"ledmatrix\"\n public _plot(now: number) {\n let ps = this\n if (ps._brightness > 0) {\n let r = 0;\n if (ps._blink > 0) {\n r = Math.floor(now / ps._blink) % 2;\n }\n if (r == 0) {\n _img.setPixelBrightness(ps._x, ps._y, _img.pixelBrightness(ps._x, ps._y) + ps._brightness);\n }\n }\n }\n }\n\n function init(): void {\n if (_img) return;\n const img = images.createImage(\n`0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0`);\n _sprites = (<LedSprite[]>[]);\n basic.forever(() => {\n basic.pause(30);\n plot();\n if (game.isGameOver()) {\n basic.pause(600);\n }\n });\n _img = img;\n }\n\n /**\n * Plots the current sprites on the screen\n */\n //% parts=\"ledmatrix\"\n function plot(): void {\n if (game.isGameOver() || game.isPaused() || !_img || _backgroundAnimation) {\n return;\n }\n // ensure greyscale mode\n const dm = led.displayMode();\n if (dm != DisplayMode.Greyscale)\n led.setDisplayMode(DisplayMode.Greyscale);\n // render sprites\n const now = input.runningTime();\n _img.clear();\n for (let i = 0; i < _sprites.length; i++) {\n _sprites[i]._plot(now);\n }\n _img.plotImage(0);\n }\n\n /**\n * Gets an invalid sprite; used to initialize locals.\n */\n //% weight=0\n export function invalidSprite(): LedSprite {\n return null;\n }\n\n}\n\n",
2735
2735
  "gc.cpp": "#include \"pxtbase.h\"\n\n#ifndef GC_BLOCK_SIZE\n#define GC_BLOCK_SIZE (1024 * 16)\n#endif\n\n#ifndef GC_MAX_ALLOC_SIZE\n#define GC_MAX_ALLOC_SIZE (GC_BLOCK_SIZE - 16)\n#endif\n\n#ifndef GC_ALLOC_BLOCK\n#define GC_ALLOC_BLOCK xmalloc\n#endif\n\n#ifdef PXT64\n#define HIGH_SHIFT 48\n#define BYTES_TO_WORDS(x) ((x) >> 3)\n#define WORDS_TO_BYTES(x) ((x) << 3)\n#define ALIGN_TO_WORD(x) (((x) + 7) & (~7ULL))\n#define VAR_BLOCK_WORDS(vt) ((uint32_t)(uint64_t)(vt) >> 2)\n#else\n#define HIGH_SHIFT 28\n#define BYTES_TO_WORDS(x) ((x) >> 2)\n#define WORDS_TO_BYTES(x) ((x) << 2)\n#define ALIGN_TO_WORD(x) (((x) + 3) & (~3U))\n#define VAR_BLOCK_WORDS(vt) (((uint32_t)(vt) << 4) >> (4 + 2))\n#endif\n\n#define FREE_MASK (1ULL << (HIGH_SHIFT + 3))\n#define ARRAY_MASK (1ULL << (HIGH_SHIFT + 2))\n#define PERMA_MASK (1ULL << (HIGH_SHIFT + 1))\n#define MARKED_MASK 0x1\n#define ANY_MARKED_MASK 0x3\n\n// the bit operations should be faster than loading large constants\n#define IS_FREE(vt) ((uintptr_t)(vt) >> (HIGH_SHIFT + 3))\n#define IS_ARRAY(vt) (((uintptr_t)(vt) >> (HIGH_SHIFT + 2)) & 1)\n#define IS_PERMA(vt) (((uintptr_t)(vt) >> (HIGH_SHIFT + 1)) & 1)\n#define IS_VAR_BLOCK(vt) ((uintptr_t)(vt) >> (HIGH_SHIFT + 2))\n#define IS_MARKED(vt) ((uintptr_t)(vt)&MARKED_MASK)\n#define IS_LIVE(vt) (IS_MARKED(vt) || (((uintptr_t)(vt) >> (HIGH_SHIFT)) == 0x6))\n\n//#define PXT_GC_DEBUG 1\n#ifndef PXT_GC_CHECKS\n#define PXT_GC_CHECKS 1\n#endif\n//#define PXT_GC_STRESS 1\n\n//#define PXT_GC_CHECKS 1\n\n#define MARK(v) \\\n do { \\\n GC_CHECK(inGCArea(v), 42); \\\n *(uintptr_t *)(v) |= MARKED_MASK; \\\n } while (0)\n\n#ifdef PXT_GC_DEBUG\n#define LOG DMESG\n#define VLOG DMESG\n#define VVLOG DMESG\n#else\n#define LOG NOLOG\n#define VLOG NOLOG\n#define VVLOG NOLOG\n#endif\n\n#ifdef PXT_GC_CHECKS\n#define GC_CHECK(cond, code) \\\n if (!(cond)) \\\n oops(code)\n#else\n#define GC_CHECK(cond, code) ((void)0)\n#endif\n\nnamespace pxt {\n\n// keep in sync with base/control.ts, function gcStats()\nstruct GCStats {\n uint32_t numGC;\n uint32_t numBlocks;\n uint32_t totalBytes;\n uint32_t lastFreeBytes;\n uint32_t lastMaxBlockBytes;\n uint32_t minFreeBytes;\n};\n\nstatic GCStats gcStats;\n\n//% expose\nBuffer getGCStats() {\n return mkBuffer((uint8_t *)&gcStats, sizeof(gcStats));\n}\n\n//%\nvoid popThreadContext(ThreadContext *ctx);\n//%\nThreadContext *pushThreadContext(void *sp, void *endSP);\n\nunsigned RefRecord_gcsize(RefRecord *r) {\n VTable *tbl = getVTable(r);\n return BYTES_TO_WORDS(tbl->numbytes);\n}\n\n#ifdef PXT_GC_THREAD_LIST\nThreadContext *threadContexts;\n#endif\n\n#define IN_GC_ALLOC 1\n#define IN_GC_COLLECT 2\n#define IN_GC_FREEZE 4\n#define IN_GC_PREALLOC 8\n\n#ifndef PXT_VM\nstatic TValue *tempRoot;\nstatic uint8_t tempRootLen;\n#endif\n\nuint8_t inGC;\n\nvoid popThreadContext(ThreadContext *ctx) {\n#ifndef PXT_VM\n VLOG(\"pop: %p\", ctx);\n\n if (!ctx)\n return;\n\n auto n = ctx->stack.next;\n if (n) {\n VLOG(\"seg %p\", n);\n ctx->stack.top = n->top;\n ctx->stack.bottom = n->bottom;\n ctx->stack.next = n->next;\n app_free(n);\n } else {\n#ifdef PXT_GC_THREAD_LIST\n if (ctx->next)\n ctx->next->prev = ctx->prev;\n if (ctx->prev)\n ctx->prev->next = ctx->next;\n else {\n if (threadContexts != ctx)\n oops(41);\n threadContexts = ctx->next;\n if (threadContexts)\n threadContexts->prev = NULL;\n }\n#endif\n app_free(ctx);\n setThreadContext(NULL);\n }\n#endif\n}\n\n#define ALLOC(tp) (tp *)app_alloc(sizeof(tp))\n\nThreadContext *pushThreadContext(void *sp, void *endSP) {\n#ifdef PXT_VM\n return NULL;\n#else\n if (PXT_IN_ISR())\n target_panic(PANIC_CALLED_FROM_ISR);\n\n auto curr = getThreadContext();\n tempRoot = (TValue *)endSP;\n tempRootLen = (uintptr_t *)sp - (uintptr_t *)endSP;\n if (curr) {\n#ifdef PXT_GC_THREAD_LIST\n#ifdef PXT_GC_DEBUG\n auto ok = false;\n for (auto p = threadContexts; p; p = p->next)\n if (p == curr) {\n ok = true;\n break;\n }\n if (!ok)\n oops(49);\n#endif\n#endif\n auto seg = ALLOC(StackSegment);\n VLOG(\"stack %p / %p\", seg, curr);\n seg->top = curr->stack.top;\n seg->bottom = curr->stack.bottom;\n seg->next = curr->stack.next;\n curr->stack.next = seg;\n } else {\n curr = ALLOC(ThreadContext);\n LOG(\"push: %p\", curr);\n curr->globals = globals;\n curr->stack.next = NULL;\n curr->thrownValue = TAG_NON_VALUE;\n curr->tryFrame = NULL;\n\n#ifdef PXT_GC_THREAD_LIST\n curr->next = threadContexts;\n curr->prev = NULL;\n if (curr->next)\n curr->next->prev = curr;\n threadContexts = curr;\n#endif\n setThreadContext(curr);\n }\n tempRootLen = 0;\n curr->stack.bottom = sp;\n curr->stack.top = NULL;\n return curr;\n#endif\n}\n\nclass RefBlock : public RefObject {\n public:\n RefBlock *nextFree;\n};\n\nstruct GCBlock {\n GCBlock *next;\n uint32_t blockSize;\n RefObject data[0];\n};\n\nstruct PendingArray {\n PendingArray *next;\n TValue *data;\n unsigned len;\n};\n\n#define PENDING_ARRAY_THR 100\n\nstatic PendingArray *pendingArrays;\nstatic LLSegment gcRoots;\nLLSegment workQueue; // (ab)used by consString making\nstatic GCBlock *firstBlock;\nstatic RefBlock *firstFree;\nstatic uint8_t *midPtr;\n\nstatic bool inGCArea(void *ptr) {\n for (auto block = firstBlock; block; block = block->next) {\n if ((void *)block->data <= ptr && ptr < (void *)((uint8_t *)block->data + block->blockSize))\n return true;\n }\n return false;\n}\n\n#define NO_MAGIC(vt) ((VTable *)vt)->magic != VTABLE_MAGIC\n#define VT(p) (*(uintptr_t *)(p))\n#define SKIP_PROCESSING(p) \\\n (isReadOnly(p) || (VT(p) & (ANY_MARKED_MASK | ARRAY_MASK)) || NO_MAGIC(VT(p)))\n\nvoid gcMarkArray(void *data) {\n auto segBl = (uintptr_t *)data - 1;\n GC_CHECK(!IS_MARKED(VT(segBl)), 47);\n MARK(segBl);\n}\n\nvoid gcScan(TValue v) {\n if (SKIP_PROCESSING(v))\n return;\n MARK(v);\n workQueue.push(v);\n}\n\nvoid gcScanMany(TValue *data, unsigned len) {\n // VLOG(\"scan: %p %d\", data, len);\n for (unsigned i = 0; i < len; ++i) {\n auto v = data[i];\n // VLOG(\"psh: %p %d %d\", v, isReadOnly(v), (*(uint32_t *)v & 1));\n if (SKIP_PROCESSING(v))\n continue;\n MARK(v);\n workQueue.push(v);\n if (workQueue.getLength() > PENDING_ARRAY_THR) {\n i++;\n // store rest of the work for later, when we have cleared the queue\n auto pa = (PendingArray *)xmalloc(sizeof(PendingArray));\n pa->next = pendingArrays;\n pa->data = data + i;\n pa->len = len - i;\n pendingArrays = pa;\n break;\n }\n }\n}\n\nvoid gcScanSegment(Segment &seg) {\n auto data = seg.getData();\n if (!data)\n return;\n VVLOG(\"seg %p %d\", data, seg.getLength());\n gcMarkArray(data);\n gcScanMany(data, seg.getLength());\n}\n\n#define getScanMethod(vt) ((RefObjectMethod)(((VTable *)(vt))->methods[2]))\n#define getSizeMethod(vt) ((RefObjectSizeMethod)(((VTable *)(vt))->methods[3]))\n\nvoid gcProcess(TValue v) {\n if (SKIP_PROCESSING(v))\n return;\n VVLOG(\"gcProcess: %p\", v);\n MARK(v);\n auto scan = getScanMethod(VT(v) & ~ANY_MARKED_MASK);\n if (scan)\n scan((RefObject *)v);\n for (;;) {\n while (workQueue.getLength()) {\n auto curr = (RefObject *)workQueue.pop();\n VVLOG(\" - %p\", curr);\n scan = getScanMethod(curr->vt() & ~ANY_MARKED_MASK);\n if (scan)\n scan(curr);\n }\n if (pendingArrays) {\n auto pa = pendingArrays;\n pendingArrays = pa->next;\n auto data = pa->data;\n auto len = pa->len;\n xfree(pa);\n gcScanMany(data, len);\n } else {\n break;\n }\n }\n}\n\nstatic void mark(int flags) {\n#ifdef PXT_GC_DEBUG\n flags |= 2;\n#endif\n auto data = gcRoots.getData();\n auto len = gcRoots.getLength();\n if (flags & 2) {\n DMESG(\"--MARK\");\n DMESG(\"RP:%p/%d\", data, len);\n }\n for (unsigned i = 0; i < len; ++i) {\n auto d = data[i];\n if ((uintptr_t)d & 1) {\n d = *(TValue *)((uintptr_t)d & ~1);\n }\n gcProcess(d);\n }\n\n#ifdef PXT_GC_THREAD_LIST\n for (auto ctx = threadContexts; ctx; ctx = ctx->next) {\n gcProcess(ctx->thrownValue);\n for (auto seg = &ctx->stack; seg; seg = seg->next) {\n auto ptr = (TValue *)threadAddressFor(ctx, seg->top);\n auto end = (TValue *)threadAddressFor(ctx, seg->bottom);\n VLOG(\"mark: %p - %p\", ptr, end);\n while (ptr < end) {\n gcProcess(*ptr++);\n }\n }\n }\n#else\n gcProcessStacks(flags);\n#endif\n\n if (globals) {\n#ifdef PXT_VM\n auto nonPtrs = vmImg->infoHeader->nonPointerGlobals;\n#else\n auto nonPtrs = bytecode[21];\n#endif\n len = getNumGlobals() - nonPtrs;\n data = globals + nonPtrs;\n if (flags & 2)\n DMESG(\"RG:%p/%d\", data, len);\n VLOG(\"globals: %p %d\", data, len);\n for (unsigned i = 0; i < len; ++i) {\n gcProcess(*data++);\n }\n }\n\n#ifndef PXT_VM\n data = tempRoot;\n len = tempRootLen;\n for (unsigned i = 0; i < len; ++i) {\n gcProcess(*data++);\n }\n#endif\n}\n\nstatic uint32_t getObjectSize(RefObject *o) {\n auto vt = o->vt() & ~ANY_MARKED_MASK;\n uint32_t r;\n GC_CHECK(vt != 0, 49);\n if (IS_VAR_BLOCK(vt)) {\n r = VAR_BLOCK_WORDS(vt);\n } else {\n auto sz = getSizeMethod(vt);\n // GC_CHECK(0x2000 <= (intptr_t)sz && (intptr_t)sz <= 0x100000, 47);\n r = sz(o);\n }\n GC_CHECK(1 <= r && (r <= BYTES_TO_WORDS(GC_MAX_ALLOC_SIZE) || IS_FREE(vt)), 41);\n return r;\n}\n\nstatic void setupFreeBlock(GCBlock *curr) {\n gcStats.numBlocks++;\n gcStats.totalBytes += curr->blockSize;\n curr->data[0].setVT(FREE_MASK | (TOWORDS(curr->blockSize) << 2));\n ((RefBlock *)curr->data)[0].nextFree = firstFree;\n firstFree = (RefBlock *)curr->data;\n midPtr = (uint8_t *)curr->data + curr->blockSize / 4;\n}\n\nstatic void linkFreeBlock(GCBlock *curr) {\n // blocks need to be sorted by address for midPtr to work\n if (!firstBlock || curr < firstBlock) {\n curr->next = firstBlock;\n firstBlock = curr;\n } else {\n for (auto p = firstBlock; p; p = p->next) {\n if (!p->next || curr < p->next) {\n curr->next = p->next;\n p->next = curr;\n break;\n }\n }\n }\n}\n\nvoid gcPreAllocateBlock(uint32_t sz) {\n auto curr = (GCBlock *)GC_ALLOC_BLOCK(sz);\n curr->blockSize = sz - sizeof(GCBlock);\n LOG(\"GC pre-alloc: %p\", curr);\n GC_CHECK((curr->blockSize & 3) == 0, 40);\n setupFreeBlock(curr);\n linkFreeBlock(curr);\n}\n\nstatic GCBlock *allocateBlockCore() {\n int sz = GC_BLOCK_SIZE;\n void *dummy = NULL;\n#ifdef GC_GET_HEAP_SIZE\n if (firstBlock) {\n#ifdef GC_STACK_BASE\n if (!firstBlock->next) {\n int memSize = getConfig(CFG_RAM_BYTES, 0);\n int codalEnd = GC_STACK_BASE;\n // round up to 1k - there is sometimes a few bytes below the stack\n codalEnd = (codalEnd + 1024) & ~1023;\n int codalSize = codalEnd & 0xffffff;\n sz = memSize - codalSize - 4;\n if (sz > 0) {\n auto curr = (GCBlock *)codalEnd;\n curr->blockSize = sz - sizeof(GCBlock);\n return curr;\n }\n }\n#endif\n gc(2); // dump roots\n soft_panic(PANIC_GC_OOM);\n }\n auto lowMem = getConfig(CFG_LOW_MEM_SIMULATION_KB, 0);\n auto sysHeapSize = getConfig(CFG_SYSTEM_HEAP_BYTES, 4 * 1024);\n auto heapSize = GC_GET_HEAP_SIZE();\n sz = heapSize - sysHeapSize;\n if (lowMem) {\n auto memIncrement = 32 * 1024;\n // get the memory size - assume it's increment of 32k,\n // and we don't statically allocate more than 32k\n auto memSize = ((heapSize + memIncrement - 1) / memIncrement) * memIncrement;\n int fillerSize = memSize - lowMem * 1024;\n if (fillerSize > 0) {\n dummy = GC_ALLOC_BLOCK(fillerSize);\n sz -= fillerSize;\n }\n }\n#endif\n auto curr = (GCBlock *)GC_ALLOC_BLOCK(sz);\n curr->blockSize = sz - sizeof(GCBlock);\n // make sure reference to allocated block is stored somewhere, otherwise\n // GCC optimizes out the call to GC_ALLOC_BLOCK\n curr->data[4].setVT((uintptr_t)dummy);\n return curr;\n}\n\n__attribute__((noinline)) static void allocateBlock() {\n auto curr = allocateBlockCore();\n DMESG(\"GC block %db @ %p\", curr->blockSize, curr);\n GC_CHECK((curr->blockSize & 3) == 0, 40);\n setupFreeBlock(curr);\n linkFreeBlock(curr);\n}\n\nstatic void sweep(int flags) {\n RefBlock *prevFreePtr = NULL;\n uint32_t freeSize = 0;\n uint32_t totalSize = 0;\n uint32_t maxFreeBlock = 0;\n firstFree = NULL;\n\n gcStats.numGC++;\n\n for (auto h = firstBlock; h; h = h->next) {\n auto d = h->data;\n auto words = BYTES_TO_WORDS(h->blockSize);\n auto end = d + words;\n totalSize += words;\n VLOG(\"sweep: %p - %p\", d, end);\n while (d < end) {\n if (IS_LIVE(d->vtable)) {\n VVLOG(\"Live %p\", d);\n d->setVT(d->vt() & ~MARKED_MASK);\n d += getObjectSize(d);\n } else {\n auto start = (RefBlock *)d;\n while (d < end) {\n if (IS_FREE(d->vtable)) {\n VVLOG(\"Free %p\", d);\n } else if (IS_LIVE(d->vtable)) {\n break;\n } else if (IS_ARRAY(d->vtable)) {\n VVLOG(\"Dead Arr %p\", d);\n } else {\n VVLOG(\"Dead Obj %p\", d);\n GC_CHECK(d->vtable->magic == VTABLE_MAGIC, 41);\n d->destroyVT();\n VVLOG(\"destroyed\");\n }\n d += getObjectSize(d);\n }\n auto sz = d - (RefObject *)start;\n freeSize += sz;\n if (sz > (int)maxFreeBlock)\n maxFreeBlock = sz;\n#ifdef PXT_GC_CHECKS\n memset((void *)start, 0xff, WORDS_TO_BYTES(sz));\n#endif\n start->setVT((sz << 2) | FREE_MASK);\n if (sz > 1) {\n start->nextFree = NULL;\n if (!prevFreePtr) {\n firstFree = start;\n } else {\n prevFreePtr->nextFree = start;\n }\n prevFreePtr = start;\n }\n }\n }\n }\n\n if (midPtr) {\n uint32_t currFree = 0;\n#ifdef PXT_ESP32\n auto limit = freeSize * 1 / 4;\n#else\n auto limit = freeSize * 1 / 2;\n#endif\n for (auto p = firstFree; p; p = p->nextFree) {\n auto len = VAR_BLOCK_WORDS(p->vtable);\n currFree += len;\n if (currFree > limit) {\n midPtr = (uint8_t *)p + ((limit - currFree + len) << 2);\n break;\n }\n }\n }\n\n freeSize = WORDS_TO_BYTES(freeSize);\n totalSize = WORDS_TO_BYTES(totalSize);\n maxFreeBlock = WORDS_TO_BYTES(maxFreeBlock);\n\n gcStats.lastFreeBytes = freeSize;\n gcStats.lastMaxBlockBytes = maxFreeBlock;\n\n if (gcStats.minFreeBytes == 0 || gcStats.minFreeBytes > freeSize)\n gcStats.minFreeBytes = freeSize;\n\n if (flags & 1)\n DMESG(\"GC %d/%d free; %d maxBlock\", freeSize, totalSize, maxFreeBlock);\n else\n LOG(\"GC %d/%d free; %d maxBlock\", freeSize, totalSize, maxFreeBlock);\n\n#ifndef GC_GET_HEAP_SIZE\n // if the heap is 90% full, allocate a new block\n if (freeSize * 10 <= totalSize) {\n allocateBlock();\n }\n#endif\n}\n\nvoid gc(int flags) {\n startPerfCounter(PerfCounters::GC);\n GC_CHECK(!(inGC & IN_GC_COLLECT), 40);\n inGC |= IN_GC_COLLECT;\n VLOG(\"GC mark\");\n mark(flags);\n VLOG(\"GC sweep\");\n sweep(flags);\n VLOG(\"GC done\");\n stopPerfCounter(PerfCounters::GC);\n inGC &= ~IN_GC_COLLECT;\n}\n\n#ifdef GC_GET_HEAP_SIZE\nextern \"C\" void free(void *ptr) {\n if (!ptr)\n return;\n if (inGCArea(ptr))\n app_free(ptr);\n else\n xfree(ptr);\n}\n\nextern \"C\" void *malloc(size_t sz) {\n if (PXT_IN_ISR() || inGC)\n return xmalloc(sz);\n else\n return app_alloc(sz);\n}\n\nextern \"C\" void *realloc(void *ptr, size_t size) {\n if (inGCArea(ptr)) {\n void *mem = malloc(size);\n\n if (ptr != NULL && mem != NULL) {\n auto r = (uintptr_t *)ptr;\n GC_CHECK((r[-1] >> (HIGH_SHIFT + 1)) == 3, 41);\n size_t blockSize = VAR_BLOCK_WORDS(r[-1]);\n memcpy(mem, ptr, min(blockSize * sizeof(void *), size));\n free(ptr);\n }\n\n return mem;\n } else {\n return device_realloc(ptr, size);\n }\n}\n#endif\n\nvoid *gcAllocateArray(int numbytes) {\n numbytes = ALIGN_TO_WORD(numbytes);\n numbytes += sizeof(void *);\n auto r = (uintptr_t *)gcAllocate(numbytes);\n *r = ARRAY_MASK | (TOWORDS(numbytes) << 2);\n return r + 1;\n}\n\nstatic void *gcAllocAt(void *hint, int numbytes) {\n gc(0);\n size_t numwords = BYTES_TO_WORDS(ALIGN_TO_WORD(numbytes));\n\n for (auto p = firstFree; p; p = p->nextFree) {\n GC_CHECK(!isReadOnly((TValue)p), 49);\n auto vt = p->vtable;\n GC_CHECK(IS_FREE(vt), 43);\n int offset = BYTES_TO_WORDS((uint8_t *)hint - (uint8_t *)p);\n int left = (int)(VAR_BLOCK_WORDS(vt) - numwords - offset);\n // we give ourselves some space here, so we don't get some strange overlaps\n if (offset >= 8 && left >= 8) {\n auto nf = (RefBlock *)((void **)p + numwords + offset);\n nf->setVT((left << 2) | FREE_MASK);\n nf->nextFree = p->nextFree;\n p->nextFree = nf;\n p->setVT((offset << 2) | FREE_MASK);\n p = (RefBlock *)((void **)p + offset);\n p->setVT(0);\n return p;\n }\n }\n\n return NULL;\n}\n\nvoid *app_alloc_at(void *at, int numbytes) {\n if (numbytes < 8)\n return NULL;\n if (!at)\n return NULL;\n\n numbytes = ALIGN_TO_WORD(numbytes) + sizeof(void *);\n auto r = (uintptr_t *)gcAllocAt((uintptr_t *)at - 1, numbytes);\n if (!r)\n return NULL;\n *r = ARRAY_MASK | PERMA_MASK | (TOWORDS(numbytes) << 2);\n gc(0);\n return r + 1;\n}\n\nvoid *app_alloc(int numbytes) {\n if (!numbytes)\n return NULL;\n\n // gc(0);\n auto r = (uintptr_t *)gcAllocateArray(numbytes);\n r[-1] |= PERMA_MASK;\n return r;\n}\n\nvoid *app_free(void *ptr) {\n auto r = (uintptr_t *)ptr;\n GC_CHECK((r[-1] >> (HIGH_SHIFT + 1)) == 3, 41);\n r[-1] |= FREE_MASK;\n return r;\n}\n\nvoid gcFreeze() {\n inGC |= IN_GC_FREEZE;\n}\n\nvoid gcReset() {\n inGC &= ~IN_GC_FREEZE;\n\n gcRoots.setLength(0);\n\n if (inGC)\n oops(41);\n\n if (workQueue.getLength())\n oops(41);\n\n memset(&gcStats, 0, sizeof(gcStats));\n firstFree = NULL;\n for (auto h = firstBlock; h; h = h->next) {\n setupFreeBlock(h);\n }\n}\n\n#ifdef PXT_VM\nvoid gcPreStartup() {\n inGC |= IN_GC_PREALLOC;\n}\n\nvoid gcStartup() {\n inGC &= ~IN_GC_PREALLOC;\n}\n#endif\n\nvoid *gcAllocate(int numbytes) {\n size_t numwords = BYTES_TO_WORDS(ALIGN_TO_WORD(numbytes));\n // VVLOG(\"alloc %d bytes %d words\", numbytes, numwords);\n\n if (numbytes > GC_MAX_ALLOC_SIZE)\n soft_panic(PANIC_GC_TOO_BIG_ALLOCATION);\n\n if (PXT_IN_ISR() || (inGC & (IN_GC_PREALLOC | IN_GC_ALLOC | IN_GC_COLLECT | IN_GC_FREEZE)))\n target_panic(PANIC_CALLED_FROM_ISR);\n\n inGC |= IN_GC_ALLOC;\n\n#if defined(PXT_GC_CHECKS) && !defined(PXT_VM)\n {\n auto curr = getThreadContext();\n if (curr && !curr->stack.top)\n oops(46);\n }\n#endif\n\n#ifdef PXT_GC_STRESS\n gc(0);\n#endif\n\n for (int i = 0;; ++i) {\n RefBlock *prev = NULL;\n for (auto p = firstFree; p; p = p->nextFree) {\n VVLOG(\"p=%p\", p);\n if (i == 0 && (uint8_t *)p > midPtr) {\n VLOG(\"past midptr %p; gc\", midPtr);\n break;\n }\n GC_CHECK(!isReadOnly((TValue)p), 49);\n auto vt = p->vtable;\n if (!IS_FREE(vt))\n oops(43);\n int left = (int)(VAR_BLOCK_WORDS(vt) - numwords);\n VVLOG(\"%p %d - %d = %d\", (void *)vt, (int)VAR_BLOCK_WORDS(vt), (int)numwords, left);\n if (left >= 0) {\n auto nf = (RefBlock *)((void **)p + numwords);\n auto nextFree = p->nextFree; // p and nf can overlap when allocating 4 bytes\n // VVLOG(\"nf=%p nef=%p\", nf, nextFree);\n if (left)\n nf->setVT((left << 2) | FREE_MASK);\n if (left >= 2) {\n nf->nextFree = nextFree;\n } else {\n nf = nextFree;\n }\n if (prev)\n prev->nextFree = nf;\n else\n firstFree = nf;\n p->setVT(0);\n VVLOG(\"GC=>%p %d %p -> %p,%p\", p, numwords, nf, nf ? nf->nextFree : 0,\n nf ? (void *)nf->vtable : 0);\n GC_CHECK(!nf || !nf->nextFree || !isReadOnly((TValue)nf->nextFree), 48);\n inGC &= ~IN_GC_ALLOC;\n return p;\n }\n prev = p;\n }\n\n // we didn't find anything, try GC\n if (i == 0)\n gc(0);\n // GC didn't help, try new block\n else if (i == 1) {\n DMESG(\"gcAlloc(%d) (%d/%d free; %d max block) -> new block\", numbytes,\n gcStats.lastFreeBytes, gcStats.totalBytes, gcStats.lastMaxBlockBytes);\n allocateBlock();\n } else\n // the block allocated was apparently too small\n soft_panic(PANIC_GC_OOM);\n }\n}\n\nstatic void removePtr(TValue v) {\n int len = gcRoots.getLength();\n auto data = gcRoots.getData();\n // scan from the back, as this is often used as a stack\n for (int i = len - 1; i >= 0; --i) {\n if (data[i] == v) {\n if (i == len - 1) {\n gcRoots.pop();\n } else {\n data[i] = gcRoots.pop();\n }\n return;\n }\n }\n oops(40);\n}\n\nvoid registerGC(TValue *root, int numwords) {\n if (!numwords)\n return;\n\n if (numwords > 1) {\n while (numwords-- > 0) {\n registerGC(root++, 1);\n }\n return;\n }\n\n gcRoots.push((TValue)((uintptr_t)root | 1));\n}\n\nvoid unregisterGC(TValue *root, int numwords) {\n if (!numwords)\n return;\n if (numwords > 1) {\n while (numwords-- > 0) {\n unregisterGC(root++, 1);\n }\n return;\n }\n\n removePtr((TValue)((uintptr_t)root | 1));\n}\n\nvoid registerGCPtr(TValue ptr) {\n if (isReadOnly(ptr))\n return;\n gcRoots.push(ptr);\n}\n\nvoid unregisterGCPtr(TValue ptr) {\n if (isReadOnly(ptr))\n return;\n removePtr(ptr);\n}\n\nvoid RefImage::scan(RefImage *t) {\n gcScan((TValue)t->buffer);\n}\n\nvoid RefCollection::scan(RefCollection *t) {\n gcScanSegment(t->head);\n}\n\nvoid RefAction::scan(RefAction *t) {\n gcScanMany(t->fields, t->len);\n}\n\nvoid RefRefLocal::scan(RefRefLocal *t) {\n gcScan(t->v);\n}\n\nvoid RefMap::scan(RefMap *t) {\n gcScanSegment(t->keys);\n gcScanSegment(t->values);\n}\n\nvoid RefRecord_scan(RefRecord *r) {\n VTable *tbl = getVTable(r);\n gcScanMany(r->fields, BYTES_TO_WORDS(tbl->numbytes - sizeof(RefRecord)));\n}\n\n#define SIZE(off) TOWORDS(sizeof(*t) + (off))\n\nunsigned RefImage::gcsize(RefImage *t) {\n return SIZE(0);\n}\n\nunsigned RefCollection::gcsize(RefCollection *t) {\n return SIZE(0);\n}\n\nunsigned RefAction::gcsize(RefAction *t) {\n return SIZE(WORDS_TO_BYTES(t->len));\n}\n\nunsigned RefRefLocal::gcsize(RefRefLocal *t) {\n return SIZE(0);\n}\n\nunsigned RefMap::gcsize(RefMap *t) {\n return SIZE(0);\n}\n\n} // namespace pxt\n",
2736
2736
  "gcstats.ts": "namespace control {\n //% shim=pxt::getGCStats\n function getGCStats(): Buffer {\n return null\n }\n\n export interface GCStats {\n numGC: number;\n numBlocks: number;\n totalBytes: number;\n lastFreeBytes: number;\n lastMaxBlockBytes: number;\n minFreeBytes: number;\n }\n\n /**\n * Get various statistics about the garbage collector (GC)\n */\n export function gcStats(): GCStats {\n const buf = getGCStats()\n if (!buf)\n return null\n let off = 0\n const res: any = {}\n\n addField(\"numGC\")\n addField(\"numBlocks\")\n addField(\"totalBytes\")\n addField(\"lastFreeBytes\")\n addField(\"lastMaxBlockBytes\")\n addField(\"minFreeBytes\")\n\n return res\n\n function addField(name: string) {\n res[name] = buf.getNumber(NumberFormat.UInt32LE, off)\n off += 4\n }\n } \n}",
@@ -2749,14 +2749,14 @@ var pxtTargetBundle = {
2749
2749
  "logo.cpp": "#include \"pxt.h\"\n\n/**\n * An action on a touch button\n */\nenum TouchButtonEvent {\n //% block=pressed\n Pressed = MICROBIT_BUTTON_EVT_CLICK,\n //% block=touched\n Touched = MICROBIT_BUTTON_EVT_DOWN,\n //% block=released\n Released = MICROBIT_BUTTON_EVT_UP,\n //% block=\"long pressed\"\n LongPressed = MICROBIT_BUTTON_EVT_LONG_CLICK\n};\n\nnamespace input {\n /**\n * Do something when the logo is touched and released again.\n * @param body the code to run when the logo is pressed\n */\n //% weight=83 blockGap=32\n //% blockId=input_logo_event block=\"on logo $action\"\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/on-logo-event\"\n void onLogoEvent(TouchButtonEvent action, Action body) {\n#if MICROBIT_CODAL\n registerWithDal(uBit.logo.id, action, body);\n#else\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n#endif\n }\n\n /**\n * Get the logo state (pressed or not).\n */\n //% weight=58\n //% blockId=\"input_logo_is_pressed\" block=\"logo is pressed\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/logo-is-pressed\"\n bool logoIsPressed() {\n#if MICROBIT_CODAL\n return uBit.logo.isPressed();\n#else\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n return false;\n#endif\n }\n}\n",
2750
2750
  "loops.ts": "namespace loops {\n /**\n * Repeats the code forever in the background.\n * After each iteration, allows other codes to run for a set duration\n * so that it runs on a timer\n * @param interval time (in ms) to wait between each iteration of the action.\n * @param body code to execute\n */\n //% weight=45 blockAllowMultiple=1\n //% interval.shadow=longTimePicker\n //% afterOnStart=true help=loops/every-interval\n //% blockId=every_interval block=\"every $interval ms\"\n export function everyInterval(interval: number, a: () => void): void {\n control.runInParallel(() => {\n while (true) {\n control.runInParallel(a);\n pause(interval);\n }\n });\n }\n\n /**\n * Get the time field editor\n * @param ms time duration in milliseconds, eg: 500, 1000\n */\n //% blockId=longTimePicker block=\"%ms\"\n //% blockHidden=true shim=TD_ID\n //% colorSecondary=\"#FFFFFF\"\n //% ms.fieldEditor=\"numberdropdown\" ms.fieldOptions.decompileLiterals=true\n //% ms.fieldOptions.data='[[\"100 ms\", 100], [\"200 ms\", 200], [\"500 ms\", 500], [\"1 second\", 1000], [\"1 minute\", 60000], [\"1 hour\", 3600000]]'\n export function __timePicker(ms: number): number {\n return ms;\n }\n}",
2751
2751
  "math.ts": "namespace Math {\n\n export const E = 2.718281828459045;\n export const LN2 = 0.6931471805599453;\n export const LN10 = 2.302585092994046;\n export const LOG2E = 1.4426950408889634;\n export const LOG10E = 0.4342944819032518;\n export const PI = 3.141592653589793;\n export const SQRT1_2 = 0.7071067811865476;\n export const SQRT2 = 1.4142135623730951;\n\n /**\n * Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.\n * @param value value to map in ranges\n * @param fromLow the lower bound of the value's current range\n * @param fromHigh the upper bound of the value's current range, eg: 1023\n * @param toLow the lower bound of the value's target range\n * @param toHigh the upper bound of the value's target range, eg: 4\n */\n //% help=math/map weight=10 blockGap=8\n //% blockId=math_map block=\"map %value|from low %fromLow|high %fromHigh|to low %toLow|high %toHigh\"\n //% inlineInputMode=inline\n export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {\n return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;\n } \n\n /**\n * Constrains a number to be within a range\n * @param x the number to constrain, all data types\n * @param y the lower end of the range, all data types\n * @param z the upper end of the range, all data types\n */\n //% help=math/constrain weight=11 blockGap=8\n //% blockId=\"math_constrain_value\" block=\"constrain %value|between %low|and %high\"\n export function constrain(value: number, low: number, high: number): number {\n return value < low ? low : value > high ? high : value;\n }\n\n const b_m16: number[] = [0, 49, 49, 41, 90, 27, 117, 10]\n /**\n * Returns the sine of an input angle. This is an 8-bit approximation.\n * @param theta input angle from 0-255\n */\n //% help=math/isin weight=11 advanced=true blockGap=8\n export function isin(theta: number) {\n //reference: based on FASTLed's sin approximation method: [https://github.com/FastLED/FastLED](MIT)\n let offset = theta;\n if( theta & 0x40 ) {\n offset = 255 - offset;\n }\n offset &= 0x3F; // 0..63\n\n let secoffset = offset & 0x0F; // 0..15\n if( theta & 0x40) secoffset++;\n\n let section = offset >> 4; // 0..3\n let s2 = section * 2;\n\n let b = b_m16[s2];\n let m16 = b_m16[s2+1];\n let mx = (m16 * secoffset) >> 4;\n \n let y = mx + b;\n if( theta & 0x80 ) y = -y;\n\n y += 128;\n\n return y;\n }\n\n /**\n * Returns the cosine of an input angle. This is an 8-bit approximation. \n * @param theta input angle from 0-255\n */\n //% help=math/icos weight=10 advanced=true blockGap=8\n export function icos(theta: number) {\n return isin(theta + 16384);\n }\n}\n\nnamespace Number {\n export const EPSILON = 2.220446049250313e-16;\n}",
2752
- "melodies.ts": "/*\nThe MIT License (MIT)\n\nCopyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed\nin the accompanying AUTHORS file\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n*/\n\n// Melodies from file microbitmusictunes.c https://github.com/bbcmicrobit/MicroPython\n\nenum Melodies {\n //% block=\"dadadum\" blockIdentity=music.builtInMelody\n Dadadadum = 0,\n //% block=\"entertainer\" blockIdentity=music.builtInMelody\n Entertainer,\n //% block=\"prelude\" blockIdentity=music.builtInMelody\n Prelude,\n //% block=\"ode\" blockIdentity=music.builtInMelody\n Ode,\n //% block=\"nyan\" blockIdentity=music.builtInMelody\n Nyan,\n //% block=\"ringtone\" blockIdentity=music.builtInMelody\n Ringtone,\n //% block=\"funk\" blockIdentity=music.builtInMelody\n Funk,\n //% block=\"blues\" blockIdentity=music.builtInMelody\n Blues,\n //% block=\"birthday\" blockIdentity=music.builtInMelody\n Birthday,\n //% block=\"wedding\" blockIdentity=music.builtInMelody\n Wedding,\n //% block=\"funeral\" blockIdentity=music.builtInMelody\n Funeral,\n //% block=\"punchline\" blockIdentity=music.builtInMelody\n Punchline,\n //% block=\"baddy\" blockIdentity=music.builtInMelody\n Baddy,\n //% block=\"chase\" blockIdentity=music.builtInMelody\n Chase,\n //% block=\"ba ding\" blockIdentity=music.builtInMelody\n BaDing,\n //% block=\"wawawawaa\" blockIdentity=music.builtInMelody\n Wawawawaa,\n //% block=\"jump up\" blockIdentity=music.builtInMelody\n JumpUp,\n //% block=\"jump down\" blockIdentity=music.builtInMelody\n JumpDown,\n //% block=\"power up\" blockIdentity=music.builtInMelody\n PowerUp,\n //% block=\"power down\" blockIdentity=music.builtInMelody\n PowerDown,\n}\n\nnamespace music {\n\n export function getMelody(melody: Melodies): string[] {\n switch (melody) {\n case Melodies.Dadadadum:\n return ['r4:2', 'g', 'g', 'g', 'eb:8', 'r:2', 'f', 'f', 'f', 'd:8'];\n case Melodies.Entertainer:\n return ['d4:1', 'd#', 'e', 'c5:2', 'e4:1', 'c5:2', 'e4:1', 'c5:3', 'c:1', 'd', 'd#', 'e', 'c', 'd', 'e:2', 'b4:1', 'd5:2', 'c:4'];\n case Melodies.Prelude:\n return ['c4:1', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e'];\n case Melodies.Ode:\n return ['e4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'e:6', 'd:2', 'd:8', 'e:4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'd:6', 'c:2', 'c:8'];\n case Melodies.Nyan:\n return ['f#5:2', 'g#', 'c#:1', 'd#:2', 'b4:1', 'd5:1', 'c#', 'b4:2', 'b', 'c#5', 'd', 'd:1', 'c#', 'b4:1', 'c#5:1', 'd#', 'f#', 'g#', 'd#', 'f#', 'c#', 'd', 'b4', 'c#5', 'b4', 'd#5:2', 'f#', 'g#:1', 'd#', 'f#', 'c#', 'd#', 'b4', 'd5', 'd#', 'd', 'c#', 'b4', 'c#5', 'd:2', 'b4:1', 'c#5', 'd#', 'f#', 'c#', 'd', 'c#', 'b4', 'c#5:2', 'b4', 'c#5', 'b4', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'c#5', 'd#', 'b4', 'e5', 'd#', 'e', 'f#', 'b4:2', 'b', 'f#:1', 'g#', 'b', 'f#', 'e5', 'd#', 'c#', 'b4', 'f#', 'd#', 'e', 'f#', 'b:2', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'b', 'c#5', 'd#', 'b4', 'f#', 'g#', 'f#', 'b:2', 'b:1', 'a#', 'b', 'f#', 'g#', 'b', 'e5', 'd#', 'e', 'f#', 'b4:2', 'c#5'];\n case Melodies.Ringtone:\n return ['c4:1', 'd', 'e:2', 'g', 'd:1', 'e', 'f:2', 'a', 'e:1', 'f', 'g:2', 'b', 'c5:4'];\n case Melodies.Funk:\n return ['c2:2', 'c', 'd#', 'c:1', 'f:2', 'c:1', 'f:2', 'f#', 'g', 'c', 'c', 'g', 'c:1', 'f#:2', 'c:1', 'f#:2', 'f', 'd#'];\n case Melodies.Blues:\n return ['c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'f', 'a', 'c3', 'd', 'd#', 'd', 'c', 'a2', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'g', 'b', 'd3', 'f', 'f2', 'a', 'c3', 'd#', 'c2:2', 'e', 'g', 'e', 'g', 'f', 'e', 'd'];\n case Melodies.Birthday:\n return ['c4:3', 'c:1', 'd:4', 'c:4', 'f', 'e:8', 'c:3', 'c:1', 'd:4', 'c:4', 'g', 'f:8', 'c:3', 'c:1', 'c5:4', 'a4', 'f', 'e', 'd', 'a#:3', 'a#:1', 'a:4', 'f', 'g', 'f:8'];\n case Melodies.Wedding:\n return ['c4:4', 'f:3', 'f:1', 'f:8', 'c:4', 'g:3', 'e:1', 'f:8', 'c:4', 'f:3', 'a:1', 'c5:4', 'a4:3', 'f:1', 'f:4', 'e:3', 'f:1', 'g:8'];\n case Melodies.Funeral:\n return ['c3:4', 'c:3', 'c:1', 'c:4', 'd#:3', 'd:1', 'd:3', 'c:1', 'c:3', 'b2:1', 'c3:4'];\n case Melodies.Punchline:\n return ['c4:3', 'g3:1', 'f#', 'g', 'g#:3', 'g', 'r', 'b', 'c4'];\n case Melodies.Baddy:\n return ['c3:3', 'r', 'd:2', 'd#', 'r', 'c', 'r', 'f#:8'];\n case Melodies.Chase:\n return ['a4:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e', 'b4:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e'];\n case Melodies.BaDing:\n return ['b5:1', 'e6:3'];\n case Melodies.Wawawawaa:\n return ['e3:3', 'r:1', 'd#:3', 'r:1', 'd:4', 'r:1', 'c#:8'];\n case Melodies.JumpUp:\n return ['c5:1', 'd', 'e', 'f', 'g'];\n case Melodies.JumpDown:\n return ['g5:1', 'f', 'e', 'd', 'c'];\n case Melodies.PowerUp:\n return ['g4:1', 'c5', 'e', 'g:2', 'e:1', 'g:3'];\n case Melodies.PowerDown:\n return ['g5:1', 'd#', 'c', 'g4:2', 'b:1', 'c5:3'];\n default:\n return [];\n }\n }\n}",
2752
+ "melodies.ts": "/*\nThe MIT License (MIT)\n\nCopyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed\nin the accompanying AUTHORS file\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n*/\n\n// Melodies from file microbitmusictunes.c https://github.com/bbcmicrobit/MicroPython\n\nenum Melodies {\n //% block=\"dadadum\" blockIdentity=music.builtInMelody\n Dadadadum = 0,\n //% block=\"entertainer\" blockIdentity=music.builtInMelody\n Entertainer,\n //% block=\"prelude\" blockIdentity=music.builtInMelody\n Prelude,\n //% block=\"ode\" blockIdentity=music.builtInMelody\n Ode,\n //% block=\"nyan\" blockIdentity=music.builtInMelody\n Nyan,\n //% block=\"ringtone\" blockIdentity=music.builtInMelody\n Ringtone,\n //% block=\"funk\" blockIdentity=music.builtInMelody\n Funk,\n //% block=\"blues\" blockIdentity=music.builtInMelody\n Blues,\n //% block=\"birthday\" blockIdentity=music.builtInMelody\n Birthday,\n //% block=\"wedding\" blockIdentity=music.builtInMelody\n Wedding,\n //% block=\"funeral\" blockIdentity=music.builtInMelody\n Funeral,\n //% block=\"punchline\" blockIdentity=music.builtInMelody\n Punchline,\n //% block=\"baddy\" blockIdentity=music.builtInMelody\n Baddy,\n //% block=\"chase\" blockIdentity=music.builtInMelody\n Chase,\n //% block=\"ba ding\" blockIdentity=music.builtInMelody\n BaDing,\n //% block=\"wawawawaa\" blockIdentity=music.builtInMelody\n Wawawawaa,\n //% block=\"jump up\" blockIdentity=music.builtInMelody\n JumpUp,\n //% block=\"jump down\" blockIdentity=music.builtInMelody\n JumpDown,\n //% block=\"power up\" blockIdentity=music.builtInMelody\n PowerUp,\n //% block=\"power down\" blockIdentity=music.builtInMelody\n PowerDown,\n}\n\nnamespace music {\n export function getMelody(melody: Melodies): string[] {\n return _bufferToMelody(_getMelodyBuffer(melody));\n }\n\n // The buffer format is 2 bytes per note. First note byte is midi\n // note number, second byte is duration in quarter beats. The note\n // number 0 is reserved for rests\n export function _getMelodyBuffer(melody: Melodies) {\n switch (melody) {\n case Melodies.Dadadadum:\n return hex`00024f024f024f024b0800024d024d024d024a08`;\n case Melodies.Entertainer:\n return hex`4a014b014c0154024c0154024c0154035401560157015801540156015802530156025404`;\n case Melodies.Prelude:\n return hex`48014c014f01540158014f015401580148014c014f01540158014f015401580148014a014f01560159014f015601590148014a014f01560159014f015601590147014a014f01560159014f015601590147014a014f01560159014f015601590148014c014f01540158014f015401580148014c014f01540158014f0154015801`;\n case Melodies.Ode:\n return hex`4c044c044d044f044f044d044c044a04480448044a044c044c064a024a084c044c044d044f044f044d044c044a04480448044a044c044a0648024808`;\n case Melodies.Nyan:\n return hex`5a025c02550157025301560155015302530255025602560155015301550157015a015c0157015a015501560153015501530157025a025c0157015a0155015701530156015701560155015301550156025301550157015a01550156015501530155025302550253024e01500153024e01500153015501570153015801570158015a01530253024e01500153014e0158015701550153014e014b014c014e0153024e01500153024e015001530153015501570153014e0150014e0153025301520153014e01500153015801570158015a0153025502`;\n case Melodies.Ringtone:\n return hex`48014a014c024f024a014c014d0251024c014d014f0253025404`;\n case Melodies.Funk:\n return hex`300230023302300135023001350236023702300230023702300136023001360235023302`;\n case Melodies.Blues:\n return hex`30023402370239023a0239023702340230023402370239023a02390237023402350239023c023e023f023e023c02390230023402370239023a0239023702340237023b023e024102350239023c023f0230023402370234023702350234023202`;\n case Melodies.Birthday:\n return hex`480348014a0448044d044c08480348014a0448044f044d0848034801540451044d044c044a045203520151044d044f044d08`;\n case Melodies.Wedding:\n return hex`48044d034d014d0848044f034c014d0848044d035101540451034d014d044c034d014f08`;\n case Melodies.Funeral:\n return hex`3c043c033c013c043f033e013e033c013c033b013c04`;\n case Melodies.Punchline:\n return hex`480343014201430144034303000347034803`;\n case Melodies.Baddy:\n return hex`3c0300033e023f0200023c0200024208`;\n case Melodies.Chase:\n return hex`5101530154015301510200025101530154015301510200025102580257025802590258025702580253015401560154015302000253015401560154015302000253025802570258025902580257025802`;\n case Melodies.BaDing:\n return hex`5f016403`;\n case Melodies.Wawawawaa:\n return hex`400300013f0300013e0400013d08`;\n case Melodies.JumpUp:\n return hex`54015601580159015b01`;\n case Melodies.JumpDown:\n return hex`5b015901580156015401`;\n case Melodies.PowerUp:\n return hex`4f01540158015b0258015b03`;\n case Melodies.PowerDown:\n return hex`5b01570154014f0253015403`;\n\n default: return undefined;\n }\n }\n}",
2753
2753
  "music.cpp": "#include \"pxt.h\"\n\nnamespace pins {\n void analogSetPitchVolume(int volume);\n int analogPitchVolume();\n}\n\nnamespace music {\n/**\n * Set the default output volume of the sound synthesizer.\n * @param volume the volume 0...255\n */\n//% blockId=synth_set_volume block=\"set volume %volume\"\n//% volume.min=0 volume.max=255\n//% volume.defl=127\n//% help=music/set-volume\n//% weight=70\n//% group=\"Volume\"\n//% blockGap=8\nvoid setVolume(int volume) {\n#if MICROBIT_CODAL\n uBit.audio.setVolume(max(0, min(255, volume)));\n#else\n pins::analogSetPitchVolume(volume);\n#endif\n}\n\n/**\n * Returns the current output volume of the sound synthesizer.\n */\n//% blockId=synth_get_volume block=\"volume\"\n//% help=music/volume\n//% weight=69\n//% group=\"Volume\"\n//% blockGap=8\nint volume() {\n#if MICROBIT_CODAL\n return uBit.audio.getVolume();\n#else\n return pins::analogPitchVolume();\n#endif\n}\n\n/**\n* Turn the built-in speaker on or off.\n* Disabling the speaker resets the sound pin to the default of P0.\n* @param enabled whether the built-in speaker is enabled in addition to the sound pin\n*/\n//% blockId=music_set_built_in_speaker_enable block=\"set built-in speaker $enabled\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\n//% parts=builtinspeaker\n//% help=music/set-built-in-speaker-enabled\n//% enabled.shadow=toggleOnOff\nvoid setBuiltInSpeakerEnabled(bool enabled) {\n#if MICROBIT_CODAL\n uBit.audio.setSpeakerEnabled(enabled);\n#else\n // don't crash if user asks to turn it off\n if (enabled) {\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n }\n#endif\n}\n\n/**\n * Defines an optional sample level to generate during periods of silence.\n **/\n//% group=\"micro:bit (V2)\"\n//% help=music/set-silence-level\n//% level.min=0\n//% level.max=1024\n//% level.defl=0\n//% weight=1\nvoid setSilenceLevel(int level) {\n#if MICROBIT_CODAL\n uBit.audio.mixer.setSilenceLevel(level);\n#else\n // this is an optimization\n // ignore in V1\n#endif\n}\n\n}",
2754
- "music.ts": "enum Note {\n //% blockIdentity=music.noteFrequency enumval=262\n C = 262,\n //% block=C#\n //% blockIdentity=music.noteFrequency enumval=277\n CSharp = 277,\n //% blockIdentity=music.noteFrequency enumval=294\n D = 294,\n //% blockIdentity=music.noteFrequency enumval=311\n Eb = 311,\n //% blockIdentity=music.noteFrequency enumval=330\n E = 330,\n //% blockIdentity=music.noteFrequency enumval=349\n F = 349,\n //% block=F#\n //% blockIdentity=music.noteFrequency enumval=370\n FSharp = 370,\n //% blockIdentity=music.noteFrequency enumval=392\n G = 392,\n //% block=G#\n //% blockIdentity=music.noteFrequency enumval=415\n GSharp = 415,\n //% blockIdentity=music.noteFrequency enumval=440\n A = 440,\n //% blockIdentity=music.noteFrequency enumval=466\n Bb = 466,\n //% blockIdentity=music.noteFrequency enumval=494\n B = 494,\n //% blockIdentity=music.noteFrequency enumval=131\n C3 = 131,\n //% block=C#3\n //% blockIdentity=music.noteFrequency enumval=139\n CSharp3 = 139,\n //% blockIdentity=music.noteFrequency enumval=147\n D3 = 147,\n //% blockIdentity=music.noteFrequency enumval=156\n Eb3 = 156,\n //% blockIdentity=music.noteFrequency enumval=165\n E3 = 165,\n //% blockIdentity=music.noteFrequency enumval=175\n F3 = 175,\n //% block=F#3\n //% blockIdentity=music.noteFrequency enumval=185\n FSharp3 = 185,\n //% blockIdentity=music.noteFrequency enumval=196\n G3 = 196,\n //% block=G#3\n //% blockIdentity=music.noteFrequency enumval=208\n GSharp3 = 208,\n //% blockIdentity=music.noteFrequency enumval=220\n A3 = 220,\n //% blockIdentity=music.noteFrequency enumval=233\n Bb3 = 233,\n //% blockIdentity=music.noteFrequency enumval=247\n B3 = 247,\n //% blockIdentity=music.noteFrequency enumval=262\n C4 = 262,\n //% block=C#4\n //% blockIdentity=music.noteFrequency enumval=277\n CSharp4 = 277,\n //% blockIdentity=music.noteFrequency enumval=294\n D4 = 294,\n //% blockIdentity=music.noteFrequency enumval=311\n Eb4 = 311,\n //% blockIdentity=music.noteFrequency enumval=330\n E4 = 330,\n //% blockIdentity=music.noteFrequency enumval=349\n F4 = 349,\n //% block=F#4\n //% blockIdentity=music.noteFrequency enumval=370\n FSharp4 = 370,\n //% blockIdentity=music.noteFrequency enumval=392\n G4 = 392,\n //% block=G#4\n //% blockIdentity=music.noteFrequency enumval=415\n GSharp4 = 415,\n //% blockIdentity=music.noteFrequency enumval=440\n A4 = 440,\n //% blockIdentity=music.noteFrequency enumval=466\n Bb4 = 466,\n //% blockIdentity=music.noteFrequency enumval=494\n B4 = 494,\n //% blockIdentity=music.noteFrequency enumval=523\n C5 = 523,\n //% block=C#5\n //% blockIdentity=music.noteFrequency enumval=555\n CSharp5 = 555,\n //% blockIdentity=music.noteFrequency enumval=587\n D5 = 587,\n //% blockIdentity=music.noteFrequency enumval=622\n Eb5 = 622,\n //% blockIdentity=music.noteFrequency enumval=659\n E5 = 659,\n //% blockIdentity=music.noteFrequency enumval=698\n F5 = 698,\n //% block=F#5\n //% blockIdentity=music.noteFrequency enumval=740\n FSharp5 = 740,\n //% blockIdentity=music.noteFrequency enumval=784\n G5 = 784,\n //% block=G#5\n //% blockIdentity=music.noteFrequency enumval=831\n GSharp5 = 831,\n //% blockIdentity=music.noteFrequency enumval=880\n A5 = 880,\n //% blockIdentity=music.noteFrequency enumval=932\n Bb5 = 932,\n //% blockIdentity=music.noteFrequency enumval=988\n B5 = 988,\n}\n\nenum BeatFraction {\n //% block=1\n Whole = 1,\n //% block=\"1/2\"\n Half = 2,\n //% block=\"1/4\"\n Quarter = 4,\n //% block=\"1/8\"\n Eighth = 8,\n //% block=\"1/16\"\n Sixteenth = 16,\n //% block=\"2\"\n Double = 32,\n //% block=\"4\",\n Breve = 64\n}\n\nenum MelodyOptions {\n //% block=\"once\"\n Once = 1,\n //% block=\"forever\"\n Forever = 2,\n //% block=\"once in background\"\n OnceInBackground = 4,\n //% block=\"forever in background\"\n ForeverInBackground = 8\n}\n\nenum MelodyStopOptions {\n //% block=\"all\"\n All = MelodyOptions.Once | MelodyOptions.OnceInBackground,\n //% block=\"foreground\"\n Foreground = MelodyOptions.Once,\n //% block=\"background\"\n Background = MelodyOptions.OnceInBackground\n}\n\nenum MusicEvent {\n //% block=\"melody note played\"\n MelodyNotePlayed = 1,\n //% block=\"melody started\"\n MelodyStarted = 2,\n //% block=\"melody ended\"\n MelodyEnded = 3,\n //% block=\"melody repeated\"\n MelodyRepeated = 4,\n //% block=\"background melody note played\"\n BackgroundMelodyNotePlayed = MelodyNotePlayed | 0xf0,\n //% block=\"background melody started\"\n BackgroundMelodyStarted = MelodyStarted | 0xf0,\n //% block=\"background melody ended\"\n BackgroundMelodyEnded = MelodyEnded | 0xf0,\n //% block=\"background melody repeated\"\n BackgroundMelodyRepeated = MelodyRepeated | 0xf0,\n //% block=\"background melody paused\"\n BackgroundMelodyPaused = 5 | 0xf0,\n //% block=\"background melody resumed\"\n BackgroundMelodyResumed = 6 | 0xf0\n}\n\n/**\n * Generation of music tones.\n */\n//% color=#E63022 weight=106 icon=\"\\uf025\"\n//% groups='[\"Melody\", \"Tone\", \"Volume\", \"Tempo\", \"Melody Advanced\"]'\nnamespace music {\n const INTERNAL_MELODY_ENDED = 5;\n\n let beatsPerMinute: number = 120;\n //% whenUsed\n const freqs = hex`\n 1f00210023002500270029002c002e003100340037003a003e004100450049004e00520057005c00620068006e00\n 75007b0083008b0093009c00a500af00b900c400d000dc00e900f70006011501260137014a015d01720188019f01\n b801d201ee010b022a024b026e029302ba02e40210033f037003a403dc03170455049704dd0427057505c8052006\n 7d06e0064907b8072d08a9082d09b9094d0aea0a900b400cfa0cc00d910e6f0f5a1053115b1272139a14d4152017\n 8018f519801b231dde1e`;\n let _playTone: (frequency: number, duration: number) => void;\n const MICROBIT_MELODY_ID = 2000;\n\n /**\n * Plays a tone through pin ``P0`` for the given duration.\n * @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C\n * @param ms tone duration in milliseconds (ms)\n */\n //% help=music/play-tone weight=90\n //% blockId=device_play_note block=\"play|tone %note=device_note|for %duration=device_beat\" blockGap=8\n //% parts=\"headphone\"\n //% useEnumVal=1\n //% group=\"Tone\"\n export function playTone(frequency: number, ms: number): void {\n if (_playTone) _playTone(frequency, ms);\n else pins.analogPitch(frequency, ms);\n }\n\n /**\n * Plays a tone through pin ``P0``.\n * @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C\n */\n //% help=music/ring-tone weight=80\n //% blockId=device_ring block=\"ring tone (Hz)|%note=device_note\" blockGap=8\n //% parts=\"headphone\"\n //% useEnumVal=1\n //% group=\"Tone\"\n export function ringTone(frequency: number): void {\n playTone(frequency, 0);\n }\n\n /**\n * Rests (plays nothing) for a specified time through pin ``P0``.\n * @param ms rest duration in milliseconds (ms)\n */\n //% help=music/rest weight=79\n //% blockId=device_rest block=\"rest(ms)|%duration=device_beat\"\n //% parts=\"headphone\"\n //% group=\"Tone\"\n export function rest(ms: number): void {\n playTone(0, ms);\n }\n\n\n /**\n * Gets the frequency of a note.\n * @param name the note name\n */\n //% weight=50 help=music/note-frequency\n //% blockId=device_note block=\"%name\"\n //% shim=TD_ID color=\"#FFFFFF\" colorSecondary=\"#FFFFFF\"\n //% name.fieldEditor=\"note\" name.defl=\"262\"\n //% name.fieldOptions.decompileLiterals=true\n //% useEnumVal=1\n //% group=\"Tone\"\n //% blockGap=8\n export function noteFrequency(name: Note): number {\n return name;\n }\n\n function init() {\n if (beatsPerMinute <= 0) beatsPerMinute = 120;\n }\n\n /**\n * Returns the duration of a beat in milli-seconds\n */\n //% help=music/beat weight=49\n //% blockId=device_beat block=\"%fraction|beat\"\n //% group=\"Tempo\"\n //% blockGap=8\n export function beat(fraction?: BeatFraction): number {\n init();\n if (fraction == null) fraction = BeatFraction.Whole;\n let beat = Math.idiv(60000, beatsPerMinute);\n switch (fraction) {\n case BeatFraction.Half: return beat >> 1;\n case BeatFraction.Quarter: return beat >> 2;\n case BeatFraction.Eighth: return beat >> 3;\n case BeatFraction.Sixteenth: return beat >> 4;\n case BeatFraction.Double: return beat << 1;\n case BeatFraction.Breve: return beat << 2;\n default: return beat;\n }\n }\n\n /**\n * Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.\n */\n //% help=music/tempo weight=40\n //% blockId=device_tempo block=\"tempo (bpm)\" blockGap=8\n //% group=\"Tempo\"\n export function tempo(): number {\n init();\n return beatsPerMinute;\n }\n\n /**\n * Change the tempo by the specified amount\n * @param bpm The change in beats per minute to the tempo, eg: 20\n */\n //% help=music/change-tempo-by weight=39\n //% blockId=device_change_tempo block=\"change tempo by (bpm)|%value\" blockGap=8\n //% group=\"Tempo\"\n //% weight=100\n export function changeTempoBy(bpm: number): void {\n init();\n setTempo(beatsPerMinute + bpm);\n }\n\n /**\n * Sets the tempo to the specified amount\n * @param bpm The new tempo in beats per minute, eg: 120\n */\n //% help=music/set-tempo weight=38\n //% blockId=device_set_tempo block=\"set tempo to (bpm)|%value\"\n //% bpm.min=4 bpm.max=400\n //% group=\"Tempo\"\n //% weight=99\n export function setTempo(bpm: number): void {\n init();\n if (bpm > 0) {\n beatsPerMinute = Math.max(1, bpm);\n }\n }\n\n let currentMelody: Melody;\n let currentBackgroundMelody: Melody;\n\n /**\n * Gets the melody array of a built-in melody.\n * @param name the note name, eg: Note.C\n */\n //% weight=50 help=music/builtin-melody\n //% blockId=device_builtin_melody block=\"%melody\"\n //% blockHidden=true\n //% group=\"Melody Advanced\"\n export function builtInMelody(melody: Melodies): string[] {\n return getMelody(melody);\n }\n\n /**\n * Registers code to run on various melody events\n */\n //% blockId=melody_on_event block=\"music on %value\"\n //% help=music/on-event weight=59 blockGap=32\n //% group=\"Melody Advanced\"\n export function onEvent(value: MusicEvent, handler: () => void) {\n control.onEvent(MICROBIT_MELODY_ID, value, handler);\n }\n\n /**\n * Use startMelody instead\n */\n //% hidden=1 deprecated=1\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {\n return startMelody(melodyArray, options);\n }\n\n /**\n * Starts playing a melody.\n * Notes are expressed as a string of characters with this format: NOTE[octave][:duration]\n * @param melodyArray the melody array to play\n * @param options melody options, once / forever, in the foreground / background\n */\n //% help=music/begin-melody weight=60 blockGap=16\n //% blockId=device_start_melody block=\"start melody %melody=device_builtin_melody| repeating %options\"\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function startMelody(melodyArray: string[], options: MelodyOptions = 1) {\n init();\n if (currentMelody != undefined) {\n if (((options & MelodyOptions.OnceInBackground) == 0)\n && ((options & MelodyOptions.ForeverInBackground) == 0)\n && currentMelody.background) {\n currentBackgroundMelody = currentMelody;\n currentMelody = null;\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyPaused);\n }\n if (currentMelody)\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);\n currentMelody = new Melody(melodyArray, options);\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);\n } else {\n currentMelody = new Melody(melodyArray, options);\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);\n // Only start the fiber once\n control.inBackground(() => {\n while (currentMelody.hasNextNote()) {\n playNextNote(currentMelody);\n if (!currentMelody.hasNextNote() && currentBackgroundMelody) {\n // Swap the background melody back\n currentMelody = currentBackgroundMelody;\n currentBackgroundMelody = null;\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.MelodyEnded);\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyResumed);\n control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n }\n }\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);\n if (!currentMelody.background)\n control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n currentMelody = null;\n })\n }\n }\n\n\n /**\n * Play a melody from the melody editor.\n * @param melody - string of up to eight notes [C D E F G A B C5] or rests [-] separated by spaces, which will be played one at a time, ex: \"E D G F B A C5 B \"\n * @param tempo - number in beats per minute (bpm), dictating how long each note will play for\n */\n //% block=\"play melody $melody at tempo $tempo|(bpm)\" blockId=playMelody\n //% weight=85 blockGap=8 help=music/play-melody\n //% melody.shadow=\"melody_editor\"\n //% tempo.min=40 tempo.max=500\n //% tempo.defl=120\n //% parts=headphone\n //% group=\"Melody\"\n export function playMelody(melody: string, tempo: number) {\n melody = melody || \"\";\n setTempo(tempo);\n let notes: string[] = melody.split(\" \").filter(n => !!n);\n let newOctave = false;\n\n // build melody string, replace '-' with 'R' and add tempo\n // creates format like \"C5-174 B4 A G F E D C \"\n for (let i = 0; i < notes.length; i++) {\n if (notes[i] === \"-\") {\n notes[i] = \"R\";\n } else if (notes[i] === \"C5\") {\n newOctave = true;\n } else if (newOctave) { // change the octave if necesary\n notes[i] += \"4\";\n newOctave = false;\n }\n }\n\n music.startMelody(notes, MelodyOptions.Once)\n control.waitForEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n }\n\n /**\n * Create a melody with the melody editor.\n * @param melody\n */\n //% block=\"$melody\" blockId=melody_editor\n //% blockHidden = true\n //% weight=85 blockGap=8\n //% duplicateShadowOnDrag\n //% melody.fieldEditor=\"melody\"\n //% melody.fieldOptions.decompileLiterals=true\n //% melody.fieldOptions.decompileIndirectFixedInstances=\"true\"\n //% melody.fieldOptions.onParentBlock=\"true\"\n //% shim=TD_ID\n //% group=\"Melody\"\n export function melodyEditor(melody: string): string {\n return melody;\n }\n\n /**\n * Stops the melodies\n * @param options which melody to stop\n */\n //% help=music/stop-melody weight=59 blockGap=16\n //% blockId=device_stop_melody block=\"stop melody $options\"\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function stopMelody(options: MelodyStopOptions) {\n if (options & MelodyStopOptions.Background)\n startMelody([], MelodyOptions.OnceInBackground);\n if (options & MelodyStopOptions.Foreground)\n startMelody([], MelodyOptions.Once);\n }\n\n /**\n * Stop all sounds and melodies currently playing.\n */\n //% help=music/stop-all-sounds\n //% blockId=music_stop_all_sounds block=\"stop all sounds\"\n //% weight=10\n //% group=\"Volume\"\n export function stopAllSounds() {\n rest(0);\n stopMelody(MelodyStopOptions.All);\n music.__stopSoundExpressions();\n }\n\n\n /**\n * Sets a custom playTone function for playing melodies\n */\n //% help=music/set-play-tone\n //% advanced=true\n //% group=\"Tone\"\n export function setPlayTone(f: (frequency: number, duration: number) => void) {\n _playTone = f;\n }\n\n function playNextNote(melody: Melody): void {\n // cache elements\n let currNote = melody.nextNote();\n let currentPos = melody.currentPos;\n let currentDuration = melody.currentDuration;\n let currentOctave = melody.currentOctave;\n\n let note: number;\n let isrest: boolean = false;\n let beatPos: number;\n let parsingOctave: boolean = true;\n let prevNote: boolean = false;\n\n for (let pos = 0; pos < currNote.length; pos++) {\n let noteChar = currNote.charAt(pos);\n switch (noteChar) {\n case 'c': case 'C': note = 1; prevNote = true; break;\n case 'd': case 'D': note = 3; prevNote = true; break;\n case 'e': case 'E': note = 5; prevNote = true; break;\n case 'f': case 'F': note = 6; prevNote = true; break;\n case 'g': case 'G': note = 8; prevNote = true; break;\n case 'a': case 'A': note = 10; prevNote = true; break;\n case 'B': note = 12; prevNote = true; break;\n case 'r': case 'R': isrest = true; prevNote = false; break;\n case '#': note++; prevNote = false; break;\n case 'b': if (prevNote) note--; else { note = 12; prevNote = true; } break;\n case ':': parsingOctave = false; beatPos = pos; prevNote = false; break;\n default: prevNote = false; if (parsingOctave) currentOctave = parseInt(noteChar);\n }\n }\n if (!parsingOctave) {\n currentDuration = parseInt(currNote.substr(beatPos + 1, currNote.length - beatPos));\n }\n let beat = Math.idiv(60000, beatsPerMinute) >> 2;\n if (isrest) {\n music.rest(currentDuration * beat)\n } else {\n let keyNumber = note + (12 * (currentOctave - 1));\n let frequency = freqs.getNumber(NumberFormat.UInt16LE, keyNumber * 2) || 0;\n music.playTone(frequency, currentDuration * beat);\n }\n melody.currentDuration = currentDuration;\n melody.currentOctave = currentOctave;\n const repeating = melody.repeating && currentPos == melody.melodyArray.length - 1;\n melody.currentPos = repeating ? 0 : currentPos + 1;\n\n control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyNotePlayed : MusicEvent.MelodyNotePlayed);\n if (repeating)\n control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyRepeated : MusicEvent.MelodyRepeated);\n }\n\n class Melody {\n public melodyArray: string[];\n public currentDuration: number;\n public currentOctave: number;\n public currentPos: number;\n public repeating: boolean;\n public background: boolean;\n\n constructor(melodyArray: string[], options: MelodyOptions) {\n this.melodyArray = melodyArray;\n this.repeating = ((options & MelodyOptions.Forever) != 0);\n this.repeating = this.repeating ? true : ((options & MelodyOptions.ForeverInBackground) != 0)\n this.background = ((options & MelodyOptions.OnceInBackground) != 0);\n this.background = this.background ? true : ((options & MelodyOptions.ForeverInBackground) != 0);\n this.currentDuration = 4; //Default duration (Crotchet)\n this.currentOctave = 4; //Middle octave\n this.currentPos = 0;\n }\n\n hasNextNote() {\n return this.repeating || this.currentPos < this.melodyArray.length;\n }\n\n nextNote(): string {\n const currentNote = this.melodyArray[this.currentPos];\n return currentNote;\n }\n }\n}\n",
2754
+ "music.ts": "enum Note {\n //% blockIdentity=music.noteFrequency enumval=262\n C = 262,\n //% block=C#\n //% blockIdentity=music.noteFrequency enumval=277\n CSharp = 277,\n //% blockIdentity=music.noteFrequency enumval=294\n D = 294,\n //% blockIdentity=music.noteFrequency enumval=311\n Eb = 311,\n //% blockIdentity=music.noteFrequency enumval=330\n E = 330,\n //% blockIdentity=music.noteFrequency enumval=349\n F = 349,\n //% block=F#\n //% blockIdentity=music.noteFrequency enumval=370\n FSharp = 370,\n //% blockIdentity=music.noteFrequency enumval=392\n G = 392,\n //% block=G#\n //% blockIdentity=music.noteFrequency enumval=415\n GSharp = 415,\n //% blockIdentity=music.noteFrequency enumval=440\n A = 440,\n //% blockIdentity=music.noteFrequency enumval=466\n Bb = 466,\n //% blockIdentity=music.noteFrequency enumval=494\n B = 494,\n //% blockIdentity=music.noteFrequency enumval=131\n C3 = 131,\n //% block=C#3\n //% blockIdentity=music.noteFrequency enumval=139\n CSharp3 = 139,\n //% blockIdentity=music.noteFrequency enumval=147\n D3 = 147,\n //% blockIdentity=music.noteFrequency enumval=156\n Eb3 = 156,\n //% blockIdentity=music.noteFrequency enumval=165\n E3 = 165,\n //% blockIdentity=music.noteFrequency enumval=175\n F3 = 175,\n //% block=F#3\n //% blockIdentity=music.noteFrequency enumval=185\n FSharp3 = 185,\n //% blockIdentity=music.noteFrequency enumval=196\n G3 = 196,\n //% block=G#3\n //% blockIdentity=music.noteFrequency enumval=208\n GSharp3 = 208,\n //% blockIdentity=music.noteFrequency enumval=220\n A3 = 220,\n //% blockIdentity=music.noteFrequency enumval=233\n Bb3 = 233,\n //% blockIdentity=music.noteFrequency enumval=247\n B3 = 247,\n //% blockIdentity=music.noteFrequency enumval=262\n C4 = 262,\n //% block=C#4\n //% blockIdentity=music.noteFrequency enumval=277\n CSharp4 = 277,\n //% blockIdentity=music.noteFrequency enumval=294\n D4 = 294,\n //% blockIdentity=music.noteFrequency enumval=311\n Eb4 = 311,\n //% blockIdentity=music.noteFrequency enumval=330\n E4 = 330,\n //% blockIdentity=music.noteFrequency enumval=349\n F4 = 349,\n //% block=F#4\n //% blockIdentity=music.noteFrequency enumval=370\n FSharp4 = 370,\n //% blockIdentity=music.noteFrequency enumval=392\n G4 = 392,\n //% block=G#4\n //% blockIdentity=music.noteFrequency enumval=415\n GSharp4 = 415,\n //% blockIdentity=music.noteFrequency enumval=440\n A4 = 440,\n //% blockIdentity=music.noteFrequency enumval=466\n Bb4 = 466,\n //% blockIdentity=music.noteFrequency enumval=494\n B4 = 494,\n //% blockIdentity=music.noteFrequency enumval=523\n C5 = 523,\n //% block=C#5\n //% blockIdentity=music.noteFrequency enumval=555\n CSharp5 = 555,\n //% blockIdentity=music.noteFrequency enumval=587\n D5 = 587,\n //% blockIdentity=music.noteFrequency enumval=622\n Eb5 = 622,\n //% blockIdentity=music.noteFrequency enumval=659\n E5 = 659,\n //% blockIdentity=music.noteFrequency enumval=698\n F5 = 698,\n //% block=F#5\n //% blockIdentity=music.noteFrequency enumval=740\n FSharp5 = 740,\n //% blockIdentity=music.noteFrequency enumval=784\n G5 = 784,\n //% block=G#5\n //% blockIdentity=music.noteFrequency enumval=831\n GSharp5 = 831,\n //% blockIdentity=music.noteFrequency enumval=880\n A5 = 880,\n //% blockIdentity=music.noteFrequency enumval=932\n Bb5 = 932,\n //% blockIdentity=music.noteFrequency enumval=988\n B5 = 988,\n}\n\nenum BeatFraction {\n //% block=1\n Whole = 1,\n //% block=\"1/2\"\n Half = 2,\n //% block=\"1/4\"\n Quarter = 4,\n //% block=\"1/8\"\n Eighth = 8,\n //% block=\"1/16\"\n Sixteenth = 16,\n //% block=\"2\"\n Double = 32,\n //% block=\"4\",\n Breve = 64\n}\n\nenum MelodyOptions {\n //% block=\"once\"\n Once = 1,\n //% block=\"forever\"\n Forever = 2,\n //% block=\"once in background\"\n OnceInBackground = 4,\n //% block=\"forever in background\"\n ForeverInBackground = 8\n}\n\nenum MelodyStopOptions {\n //% block=\"all\"\n All = MelodyOptions.Once | MelodyOptions.OnceInBackground,\n //% block=\"foreground\"\n Foreground = MelodyOptions.Once,\n //% block=\"background\"\n Background = MelodyOptions.OnceInBackground\n}\n\nenum MusicEvent {\n //% block=\"melody note played\"\n MelodyNotePlayed = 1,\n //% block=\"melody started\"\n MelodyStarted = 2,\n //% block=\"melody ended\"\n MelodyEnded = 3,\n //% block=\"melody repeated\"\n MelodyRepeated = 4,\n //% block=\"background melody note played\"\n BackgroundMelodyNotePlayed = MelodyNotePlayed | 0xf0,\n //% block=\"background melody started\"\n BackgroundMelodyStarted = MelodyStarted | 0xf0,\n //% block=\"background melody ended\"\n BackgroundMelodyEnded = MelodyEnded | 0xf0,\n //% block=\"background melody repeated\"\n BackgroundMelodyRepeated = MelodyRepeated | 0xf0,\n //% block=\"background melody paused\"\n BackgroundMelodyPaused = 5 | 0xf0,\n //% block=\"background melody resumed\"\n BackgroundMelodyResumed = 6 | 0xf0\n}\n\n/**\n * Generation of music tones.\n */\n//% color=#E63022 weight=106 icon=\"\\uf025\"\n//% groups='[\"Melody\", \"Tone\", \"Volume\", \"Tempo\", \"Melody Advanced\"]'\nnamespace music {\n const INTERNAL_MELODY_ENDED = 5;\n\n let beatsPerMinute: number = 120;\n //% whenUsed\n const freqs = hex`\n 1f00210023002500270029002c002e003100340037003a003e004100450049004e00520057005c00620068006e00\n 75007b0083008b0093009c00a500af00b900c400d000dc00e900f70006011501260137014a015d01720188019f01\n b801d201ee010b022a024b026e029302ba02e40210033f037003a403dc03170455049704dd0427057505c8052006\n 7d06e0064907b8072d08a9082d09b9094d0aea0a900b400cfa0cc00d910e6f0f5a1053115b1272139a14d4152017\n 8018f519801b231dde1e`;\n let _playTone: (frequency: number, duration: number) => void;\n const MICROBIT_MELODY_ID = 2000;\n\n /**\n * Plays a tone through pin ``P0`` for the given duration.\n * @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C\n * @param ms tone duration in milliseconds (ms)\n */\n //% help=music/play-tone weight=90\n //% blockId=device_play_note block=\"play|tone %note=device_note|for %duration=device_beat\" blockGap=8\n //% parts=\"headphone\"\n //% useEnumVal=1\n //% group=\"Tone\"\n export function playTone(frequency: number, ms: number): void {\n if (_playTone) _playTone(frequency, ms);\n else pins.analogPitch(frequency, ms);\n }\n\n /**\n * Plays a tone through pin ``P0``.\n * @param frequency pitch of the tone to play in Hertz (Hz), eg: Note.C\n */\n //% help=music/ring-tone weight=80\n //% blockId=device_ring block=\"ring tone (Hz)|%note=device_note\" blockGap=8\n //% parts=\"headphone\"\n //% useEnumVal=1\n //% group=\"Tone\"\n export function ringTone(frequency: number): void {\n playTone(frequency, 0);\n }\n\n /**\n * Rests (plays nothing) for a specified time through pin ``P0``.\n * @param ms rest duration in milliseconds (ms)\n */\n //% help=music/rest weight=79\n //% blockId=device_rest block=\"rest(ms)|%duration=device_beat\"\n //% parts=\"headphone\"\n //% group=\"Tone\"\n export function rest(ms: number): void {\n playTone(0, ms);\n }\n\n\n /**\n * Gets the frequency of a note.\n * @param name the note name\n */\n //% weight=50 help=music/note-frequency\n //% blockId=device_note block=\"%name\"\n //% shim=TD_ID color=\"#FFFFFF\" colorSecondary=\"#FFFFFF\"\n //% name.fieldEditor=\"note\" name.defl=\"262\"\n //% name.fieldOptions.decompileLiterals=true\n //% useEnumVal=1\n //% group=\"Tone\"\n //% blockGap=8\n export function noteFrequency(name: Note): number {\n return name;\n }\n\n function init() {\n if (beatsPerMinute <= 0) beatsPerMinute = 120;\n }\n\n /**\n * Returns the duration of a beat in milli-seconds\n */\n //% help=music/beat weight=49\n //% blockId=device_beat block=\"%fraction|beat\"\n //% group=\"Tempo\"\n //% blockGap=8\n export function beat(fraction?: BeatFraction): number {\n init();\n if (fraction == null) fraction = BeatFraction.Whole;\n let beat = Math.idiv(60000, beatsPerMinute);\n switch (fraction) {\n case BeatFraction.Half: return beat >> 1;\n case BeatFraction.Quarter: return beat >> 2;\n case BeatFraction.Eighth: return beat >> 3;\n case BeatFraction.Sixteenth: return beat >> 4;\n case BeatFraction.Double: return beat << 1;\n case BeatFraction.Breve: return beat << 2;\n default: return beat;\n }\n }\n\n /**\n * Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.\n */\n //% help=music/tempo weight=40\n //% blockId=device_tempo block=\"tempo (bpm)\" blockGap=8\n //% group=\"Tempo\"\n export function tempo(): number {\n init();\n return beatsPerMinute;\n }\n\n /**\n * Change the tempo by the specified amount\n * @param bpm The change in beats per minute to the tempo, eg: 20\n */\n //% help=music/change-tempo-by weight=39\n //% blockId=device_change_tempo block=\"change tempo by (bpm)|%value\" blockGap=8\n //% group=\"Tempo\"\n //% weight=100\n export function changeTempoBy(bpm: number): void {\n init();\n setTempo(beatsPerMinute + bpm);\n }\n\n /**\n * Sets the tempo to the specified amount\n * @param bpm The new tempo in beats per minute, eg: 120\n */\n //% help=music/set-tempo weight=38\n //% blockId=device_set_tempo block=\"set tempo to (bpm)|%value\"\n //% bpm.min=4 bpm.max=400\n //% group=\"Tempo\"\n //% weight=99\n export function setTempo(bpm: number): void {\n init();\n if (bpm > 0) {\n beatsPerMinute = Math.max(1, bpm);\n }\n }\n\n let currentMelody: Melody;\n let currentBackgroundMelody: Melody;\n\n /**\n * Gets the melody array of a built-in melody.\n * @param name the note name, eg: Note.C\n */\n //% weight=50 help=music/builtin-melody\n //% blockId=device_builtin_melody block=\"%melody\"\n //% blockHidden=true\n //% group=\"Melody Advanced\"\n export function builtInMelody(melody: Melodies): string[] {\n return getMelody(melody);\n }\n\n /**\n * Registers code to run on various melody events\n */\n //% blockId=melody_on_event block=\"music on %value\"\n //% help=music/on-event weight=59 blockGap=32\n //% group=\"Melody Advanced\"\n export function onEvent(value: MusicEvent, handler: () => void) {\n control.onEvent(MICROBIT_MELODY_ID, value, handler);\n }\n\n /**\n * Use startMelody instead\n */\n //% hidden=1 deprecated=1\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {\n return startMelody(melodyArray, options);\n }\n\n /**\n * Starts playing a melody.\n * Notes are expressed as a string of characters with this format: NOTE[octave][:duration]\n * @param melodyArray the melody array to play\n * @param options melody options, once / forever, in the foreground / background\n */\n //% help=music/begin-melody weight=60 blockGap=16\n //% blockId=device_start_melody block=\"start melody %melody=device_builtin_melody| repeating %options\"\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function startMelody(melodyArray: string[], options: MelodyOptions = 1) {\n init();\n const isBackground = options & (MelodyOptions.OnceInBackground | MelodyOptions.ForeverInBackground);\n if (currentMelody != undefined) {\n if (!isBackground && currentMelody.background) {\n currentBackgroundMelody = currentMelody;\n currentMelody = null;\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyPaused);\n }\n if (currentMelody)\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background | MusicEvent.MelodyEnded);\n currentMelody = new Melody(melodyArray, options);\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background | MusicEvent.MelodyStarted);\n } else {\n currentMelody = new Melody(melodyArray, options);\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background | MusicEvent.MelodyStarted);\n // Only start the fiber once\n control.inBackground(() => {\n while (currentMelody.hasNextNote()) {\n playNextNote(currentMelody);\n if (!currentMelody.hasNextNote() && currentBackgroundMelody) {\n // Swap the background melody back\n currentMelody = currentBackgroundMelody;\n currentBackgroundMelody = null;\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.MelodyEnded);\n control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyResumed);\n control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n }\n }\n control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background | MusicEvent.MelodyEnded);\n if (!currentMelody.background)\n control.raiseEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n currentMelody = null;\n })\n }\n }\n\n\n /**\n * Play a melody from the melody editor.\n * @param melody - string of up to eight notes [C D E F G A B C5] or rests [-] separated by spaces, which will be played one at a time, ex: \"E D G F B A C5 B \"\n * @param tempo - number in beats per minute (bpm), dictating how long each note will play for\n */\n //% block=\"play melody $melody at tempo $tempo|(bpm)\" blockId=playMelody\n //% weight=85 blockGap=8 help=music/play-melody\n //% melody.shadow=\"melody_editor\"\n //% tempo.min=40 tempo.max=500\n //% tempo.defl=120\n //% parts=headphone\n //% group=\"Melody\"\n export function playMelody(melody: string, tempo: number) {\n melody = melody || \"\";\n setTempo(tempo);\n let notes: string[] = melody.split(\" \").filter(n => !!n);\n let newOctave = false;\n\n // build melody string, replace '-' with 'R' and add tempo\n // creates format like \"C5-174 B4 A G F E D C \"\n for (let i = 0; i < notes.length; i++) {\n if (notes[i] === \"-\") {\n notes[i] = \"R\";\n } else if (notes[i] === \"C5\") {\n newOctave = true;\n } else if (newOctave) { // change the octave if necesary\n notes[i] += \"4\";\n newOctave = false;\n }\n }\n\n music.startMelody(notes, MelodyOptions.Once)\n control.waitForEvent(MICROBIT_MELODY_ID, INTERNAL_MELODY_ENDED);\n }\n\n /**\n * Create a melody with the melody editor.\n * @param melody\n */\n //% block=\"$melody\" blockId=melody_editor\n //% blockHidden = true\n //% weight=85 blockGap=8\n //% duplicateShadowOnDrag\n //% melody.fieldEditor=\"melody\"\n //% melody.fieldOptions.decompileLiterals=true\n //% melody.fieldOptions.decompileIndirectFixedInstances=\"true\"\n //% melody.fieldOptions.onParentBlock=\"true\"\n //% shim=TD_ID\n //% group=\"Melody\"\n export function melodyEditor(melody: string): string {\n return melody;\n }\n\n /**\n * Stops the melodies\n * @param options which melody to stop\n */\n //% help=music/stop-melody weight=59 blockGap=16\n //% blockId=device_stop_melody block=\"stop melody $options\"\n //% parts=\"headphone\"\n //% group=\"Melody Advanced\"\n export function stopMelody(options: MelodyStopOptions) {\n if (options & MelodyStopOptions.Background)\n startMelody([], MelodyOptions.OnceInBackground);\n if (options & MelodyStopOptions.Foreground)\n startMelody([], MelodyOptions.Once);\n }\n\n /**\n * Stop all sounds and melodies currently playing.\n */\n //% help=music/stop-all-sounds\n //% blockId=music_stop_all_sounds block=\"stop all sounds\"\n //% weight=10\n //% group=\"Volume\"\n export function stopAllSounds() {\n rest(0);\n stopMelody(MelodyStopOptions.All);\n music.__stopSoundExpressions();\n }\n\n\n /**\n * Sets a custom playTone function for playing melodies\n */\n //% help=music/set-play-tone\n //% advanced=true\n //% group=\"Tone\"\n export function setPlayTone(f: (frequency: number, duration: number) => void) {\n _playTone = f;\n }\n\n /**\n * Converts an octave and note offset into an integer frequency.\n * Returns 0 if the note is out of range.\n *\n * @param octave The octave of the note (1 - 8)\n * @param note The offset of the note within the octave\n * @returns A frequency in HZ or 0 if out of range\n */\n export function getFrequencyForNote(octave: number, note: number) {\n return freqs.getNumber(NumberFormat.UInt16LE, (note + (12 * (octave - 1))) * 2) || 0;\n }\n\n function playNextNote(melody: Melody): void {\n // cache elements\n let currNote = melody.nextNote();\n let currentPos = melody.currentPos;\n let currentDuration = melody.currentDuration;\n let currentOctave = melody.currentOctave;\n\n let note: number;\n let isrest: boolean = false;\n let beatPos: number;\n let parsingOctave: boolean = true;\n let prevNote: boolean = false;\n\n for (let pos = 0; pos < currNote.length; pos++) {\n let noteChar = currNote.charAt(pos);\n switch (noteChar) {\n case 'c': case 'C': note = 1; prevNote = true; break;\n case 'd': case 'D': note = 3; prevNote = true; break;\n case 'e': case 'E': note = 5; prevNote = true; break;\n case 'f': case 'F': note = 6; prevNote = true; break;\n case 'g': case 'G': note = 8; prevNote = true; break;\n case 'a': case 'A': note = 10; prevNote = true; break;\n case 'B': note = 12; prevNote = true; break;\n case 'r': case 'R': isrest = true; prevNote = false; break;\n case '#': note++; prevNote = false; break;\n case 'b': if (prevNote) note--; else { note = 12; prevNote = true; } break;\n case ':': parsingOctave = false; beatPos = pos; prevNote = false; break;\n default: prevNote = false; if (parsingOctave) currentOctave = parseInt(noteChar);\n }\n }\n if (!parsingOctave) {\n currentDuration = parseInt(currNote.substr(beatPos + 1, currNote.length - beatPos));\n }\n let beat = Math.idiv(60000, beatsPerMinute) >> 2;\n if (isrest) {\n music.rest(currentDuration * beat)\n } else {\n music.playTone(getFrequencyForNote(note, currentOctave), currentDuration * beat);\n }\n melody.currentDuration = currentDuration;\n melody.currentOctave = currentOctave;\n const repeating = melody.repeating && currentPos == melody.melodyArray.length - 1;\n melody.currentPos = repeating ? 0 : currentPos + 1;\n\n control.raiseEvent(MICROBIT_MELODY_ID, melody.background | MusicEvent.MelodyNotePlayed);\n if (repeating)\n control.raiseEvent(MICROBIT_MELODY_ID, melody.background | MusicEvent.MelodyRepeated);\n }\n\n class Melody {\n public melodyArray: string[];\n public currentDuration: number;\n public currentOctave: number;\n public currentPos: number;\n public repeating: boolean;\n\n // This is bitwise or'd with the events. 0 is not in background, 0xf0 if in background\n public background: number;\n\n constructor(melodyArray: string[], options: MelodyOptions) {\n this.melodyArray = melodyArray;\n this.repeating = !!(options & (MelodyOptions.Forever | MelodyOptions.ForeverInBackground));\n this.background = (options & (MelodyOptions.OnceInBackground | MelodyOptions.ForeverInBackground)) ? 0xf0 : 0;\n this.currentDuration = 4; //Default duration (Crotchet)\n this.currentOctave = 4; //Middle octave\n this.currentPos = 0;\n }\n\n hasNextNote() {\n return this.repeating || this.currentPos < this.melodyArray.length;\n }\n\n nextNote(): string {\n const currentNote = this.melodyArray[this.currentPos];\n return currentNote;\n }\n }\n\n export function _bufferToMelody(melody: Buffer) {\n if (!melody) return [];\n\n let currentDuration = 4;\n let currentOctave = -1;\n const out: string[] = [];\n\n const notes = \"c#d#ef#g#a#b\"\n let current = \"\";\n\n // The buffer format is 2 bytes per note. First note byte is midi\n // note number, second byte is duration in quarter beats. The note\n // number 0 is reserved for rests\n for (let i = 0; i < melody.length; i += 2) {\n let octave = 4;\n const note = melody[i] % 12;\n if (melody[i] === 0) {\n current = \"r\"\n }\n else {\n current = notes.charAt(note);\n if (current === \"#\") current = notes.charAt(note - 1) + current\n\n octave = Math.idiv((melody[i] - 23), 12)\n }\n\n const duration = melody[i + 1];\n\n if (octave !== currentOctave) {\n current += octave\n currentOctave = octave;\n }\n\n if (duration !== currentDuration) {\n current += \":\" + duration;\n currentDuration = duration;\n }\n\n out.push(current);\n }\n\n return out;\n }\n}\n",
2755
2755
  "parts/headphone.svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"142\" height=\"180\" viewBox=\"0 0 142 180\"><rect ry=\".3\" rx=\"1\" y=\"58.615\" x=\"-8.878\" height=\"23.571\" width=\"17.143\" transform=\"rotate(-45)\" fill=\"#b3b3b3\"/><rect ry=\".3\" rx=\"1\" y=\"32.043\" x=\"-8.878\" height=\"23.571\" width=\"17.143\" transform=\"rotate(-45)\" fill=\"#b3b3b3\"/><path d=\"M.346 7.296c-.394.39-.31 4.797-.18 4.898l13.404 10.18c.117.12.337 4.76.73 4.368l5.506-5.56.01.01 6.51-6.444c.39-.392-4.25-.614-4.366-.73L11.777.612c-.1-.132-4.51-.215-4.898.18L4.087 3.636l-.01-.01-3.73 3.67z\" fill=\"#b3b3b3\"/><rect ry=\"6.85\" rx=\"4.571\" y=\"84.758\" x=\"-20.128\" height=\"75.571\" width=\"39.643\" transform=\"rotate(-45)\"/><rect ry=\".374\" rx=\"1.038\" y=\"29.442\" x=\"-8.925\" height=\"2.228\" width=\"17.238\" transform=\"rotate(-45)\" fill=\"#fff\"/><rect ry=\".374\" rx=\"1.038\" y=\"55.939\" x=\"-8.925\" height=\"2.228\" width=\"17.238\" transform=\"rotate(-45)\" fill=\"#fff\"/><rect ry=\".374\" rx=\"1.038\" y=\"82.392\" x=\"-8.925\" height=\"2.228\" width=\"17.238\" transform=\"rotate(-45)\" fill=\"#fff\"/><rect ry=\"2.317\" rx=\"2.183\" y=\"158.876\" x=\"-9.774\" height=\"25.568\" width=\"18.935\" transform=\"rotate(-45)\"/><path d=\"M128.588 128.82s14.97 11.165 7.547 26.35c-8.426 17.24-25.57 20.653-25.57 20.653\" fill=\"none\" stroke=\"#000\" stroke-width=\"6.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>",
2756
2756
  "parts/speaker.svg": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 500 500\" xmlns=\"http://www.w3.org/2000/svg\">\n <g transform=\"matrix(1, 0, 0, 1, -0.00023, -58.230297)\">\n <ellipse style=\"fill: rgb(70, 70, 70);\" cx=\"250.58\" cy=\"308.81\" rx=\"215\" ry=\"215\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(1, 0, 0, 1.000001, -232.069031, 248.780606)\" cx=\"482.069\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(1, 0, 0, 0.999999, -232.067871, 110.041956)\" cx=\"482.067\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"389.12\" cy=\"308.23\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"110.88\" cy=\"308.23\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"250\" cy=\"169.393\" rx=\"23.028\" ry=\"23.028\"/>\n <g transform=\"matrix(1, 0, 0, 1, -0.000009, 0.000015)\">\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"250\" cy=\"238.513\" rx=\"23.028\" ry=\"23.028\" transform=\"matrix(1.000001, 0, 0, 0.999999, 69.996739, 69.71816)\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(1, 0, 0, 0.999999, -302.064453, 110.043115)\" cx=\"482.064\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n </g>\n <g transform=\"matrix(0.866026, 0.5, -0.5, 0.866026, 7.386552, -105.261086)\">\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(0.999999, 0, 0, 0.999999, -65.212313, 177.387415)\" cx=\"482.068\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"555.975\" cy=\"236.836\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"277.735\" cy=\"236.836\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"416.855\" cy=\"97.999\" rx=\"23.028\" ry=\"23.028\"/>\n </g>\n <g transform=\"matrix(0.5, 0.866026, -0.866026, 0.5, 246.635941, -171.170502)\">\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(0.999999, 0, 0, 0.999999, -65.212313, 177.387415)\" cx=\"482.068\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"555.975\" cy=\"236.836\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"277.735\" cy=\"236.836\" rx=\"23.028\" ry=\"23.028\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"416.855\" cy=\"97.999\" rx=\"23.028\" ry=\"23.028\"/>\n </g>\n <g transform=\"matrix(-0.5, 0.866026, -0.866026, -0.5, 641.934998, 245.84082)\">\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"250\" cy=\"238.513\" rx=\"23.028\" ry=\"23.028\" transform=\"matrix(1.000001, 0, 0, 0.999999, 69.996739, 69.71816)\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(1, 0, 0, 0.999999, -302.064453, 110.043115)\" cx=\"482.064\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n </g>\n <g transform=\"matrix(-0.500001, -0.866026, 0.866026, -0.500001, 108.063393, 678.85083)\">\n <ellipse style=\"fill: rgb(0, 0, 0);\" cx=\"250\" cy=\"238.513\" rx=\"23.028\" ry=\"23.028\" transform=\"matrix(1.000001, 0, 0, 0.999999, 69.996739, 69.71816)\"/>\n <ellipse style=\"fill: rgb(0, 0, 0);\" transform=\"matrix(1, 0, 0, 0.999999, -302.064453, 110.043115)\" cx=\"482.064\" cy=\"198.188\" rx=\"23.028\" ry=\"23.028\"/>\n </g>\n </g>\n</svg>",
2757
2757
  "perfcounters.ts": "namespace control {\n /**\n * Enable profiling for current function.\n */\n //% shim=TD_NOOP shimArgument=perfCounter\n export function enablePerfCounter(name?: string) { }\n\n /**\n * Dump values of profiling performance counters.\n */\n //% shim=pxt::dumpPerfCounters\n export function dmesgPerfCounters() { }\n}\n",
2758
- "pins.cpp": "#include \"pxt.h\"\n\n#if MICROBIT_CODAL\n#include \"Pin.h\"\n#define PinCompat codal::Pin\n#else\n#define PinCompat MicroBitPin\n#endif\n\nenum class DigitalPin {\n P0 = MICROBIT_ID_IO_P0,\n P1 = MICROBIT_ID_IO_P1,\n P2 = MICROBIT_ID_IO_P2,\n P3 = MICROBIT_ID_IO_P3,\n P4 = MICROBIT_ID_IO_P4,\n P5 = MICROBIT_ID_IO_P5,\n P6 = MICROBIT_ID_IO_P6,\n P7 = MICROBIT_ID_IO_P7,\n P8 = MICROBIT_ID_IO_P8,\n P9 = MICROBIT_ID_IO_P9,\n P10 = MICROBIT_ID_IO_P10,\n P11 = MICROBIT_ID_IO_P11,\n P12 = MICROBIT_ID_IO_P12,\n P13 = MICROBIT_ID_IO_P13,\n P14 = MICROBIT_ID_IO_P14,\n P15 = MICROBIT_ID_IO_P15,\n P16 = MICROBIT_ID_IO_P16,\n //% blockHidden=1\n P19 = MICROBIT_ID_IO_P19,\n //% blockHidden=1\n P20 = MICROBIT_ID_IO_P20,\n};\n\nenum class AnalogPin {\n P0 = MICROBIT_ID_IO_P0,\n P1 = MICROBIT_ID_IO_P1,\n P2 = MICROBIT_ID_IO_P2,\n P3 = MICROBIT_ID_IO_P3,\n P4 = MICROBIT_ID_IO_P4,\n P10 = MICROBIT_ID_IO_P10,\n //% block=\"P5 (write only)\"\n P5 = MICROBIT_ID_IO_P5,\n //% block=\"P6 (write only)\"\n P6 = MICROBIT_ID_IO_P6,\n //% block=\"P7 (write only)\"\n P7 = MICROBIT_ID_IO_P7,\n //% block=\"P8 (write only)\"\n P8 = MICROBIT_ID_IO_P8,\n //% block=\"P9 (write only)\"\n P9 = MICROBIT_ID_IO_P9,\n //% block=\"P11 (write only)\"\n P11 = MICROBIT_ID_IO_P11,\n //% block=\"P12 (write only)\"\n P12 = MICROBIT_ID_IO_P12,\n //% block=\"P13 (write only)\"\n P13 = MICROBIT_ID_IO_P13,\n //% block=\"P14 (write only)\"\n P14 = MICROBIT_ID_IO_P14,\n //% block=\"P15 (write only)\"\n P15 = MICROBIT_ID_IO_P15,\n //% block=\"P16 (write only)\"\n P16 = MICROBIT_ID_IO_P16,\n //% block=\"P19 (write only)\"\n //% blockHidden=1\n P19 = MICROBIT_ID_IO_P19,\n //% block=\"P20 (write only)\"\n //% blockHidden=1\n P20 = MICROBIT_ID_IO_P20\n};\n\nenum class PulseValue {\n //% block=high\n High = MICROBIT_PIN_EVT_PULSE_HI,\n //% block=low\n Low = MICROBIT_PIN_EVT_PULSE_LO\n};\n\nenum class PinPullMode {\n //% block=\"down\"\n PullDown = 0,\n //% block=\"up\"\n PullUp = 1,\n //% block=\"none\"\n PullNone = 2\n};\n\nenum class PinEventType {\n //% block=\"edge\"\n Edge = MICROBIT_PIN_EVENT_ON_EDGE,\n //% block=\"pulse\"\n Pulse = MICROBIT_PIN_EVENT_ON_PULSE,\n //% block=\"touch\"\n Touch = MICROBIT_PIN_EVENT_ON_TOUCH,\n //% block=\"none\"\n None = MICROBIT_PIN_EVENT_NONE\n};\n\n\nnamespace pxt\n{\nMicroBitPin *getPin(int id) {\n switch (id) {\n case MICROBIT_ID_IO_P0: return &uBit.io.P0;\n case MICROBIT_ID_IO_P1: return &uBit.io.P1;\n case MICROBIT_ID_IO_P2: return &uBit.io.P2;\n case MICROBIT_ID_IO_P3: return &uBit.io.P3;\n case MICROBIT_ID_IO_P4: return &uBit.io.P4;\n case MICROBIT_ID_IO_P5: return &uBit.io.P5;\n case MICROBIT_ID_IO_P6: return &uBit.io.P6;\n case MICROBIT_ID_IO_P7: return &uBit.io.P7;\n case MICROBIT_ID_IO_P8: return &uBit.io.P8;\n case MICROBIT_ID_IO_P9: return &uBit.io.P9;\n case MICROBIT_ID_IO_P10: return &uBit.io.P10;\n case MICROBIT_ID_IO_P11: return &uBit.io.P11;\n case MICROBIT_ID_IO_P12: return &uBit.io.P12;\n case MICROBIT_ID_IO_P13: return &uBit.io.P13;\n case MICROBIT_ID_IO_P14: return &uBit.io.P14;\n case MICROBIT_ID_IO_P15: return &uBit.io.P15;\n case MICROBIT_ID_IO_P16: return &uBit.io.P16;\n case MICROBIT_ID_IO_P19: return &uBit.io.P19;\n case MICROBIT_ID_IO_P20: return &uBit.io.P20;\n#if MICROBIT_CODAL\n case 1001: return &uBit.io.usbTx;\n case 1002: return &uBit.io.usbRx;\n#endif\n default: return NULL;\n }\n}\n\n} // pxt\n\nnamespace pins {\n #define PINOP(op) \\\n MicroBitPin *pin = getPin((int)name); \\\n if (!pin) return; \\\n pin->op\n\n #define PINREAD(op) \\\n MicroBitPin *pin = getPin((int)name); \\\n if (!pin) return 0; \\\n return pin->op\n\n\n //%\n MicroBitPin *getPinAddress(int id) {\n return getPin(id);\n }\n\n /**\n * Read the specified pin or connector as either 0 or 1\n * @param name pin to read from, eg: DigitalPin.P0\n */\n //% help=pins/digital-read-pin weight=30\n //% blockId=device_get_digital_pin block=\"digital read|pin %name\" blockGap=8\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n int digitalReadPin(DigitalPin name) {\n PINREAD(getDigitalValue());\n }\n\n /**\n * Set a pin or connector value to either 0 or 1.\n * @param name pin to write to, eg: DigitalPin.P0\n * @param value value to set on the pin, 1 eg,0\n */\n //% help=pins/digital-write-pin weight=29\n //% blockId=device_set_digital_pin block=\"digital write|pin %name|to %value\"\n //% value.min=0 value.max=1\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void digitalWritePin(DigitalPin name, int value) {\n PINOP(setDigitalValue(value));\n }\n\n /**\n * Read the connector value as analog, that is, as a value comprised between 0 and 1023.\n * @param name pin to write to, eg: AnalogPin.P0\n */\n //% help=pins/analog-read-pin weight=25\n //% blockId=device_get_analog_pin block=\"analog read|pin %name\" blockGap=\"8\"\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n int analogReadPin(AnalogPin name) {\n PINREAD(getAnalogValue());\n }\n\n /**\n * Set the connector value as analog. Value must be comprised between 0 and 1023.\n * @param name pin name to write to, eg: AnalogPin.P0\n * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0\n */\n //% help=pins/analog-write-pin weight=24\n //% blockId=device_set_analog_pin block=\"analog write|pin %name|to %value\" blockGap=8\n //% value.min=0 value.max=1023\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void analogWritePin(AnalogPin name, int value) {\n PINOP(setAnalogValue(value));\n }\n\n /**\n * Configure the pulse-width modulation (PWM) period of the analog output in microseconds.\n * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.\n * @param name analog pin to set period to, eg: AnalogPin.P0\n * @param micros period in micro seconds. eg:20000\n */\n //% help=pins/analog-set-period weight=23 blockGap=8\n //% blockId=device_set_analog_period block=\"analog set period|pin %pin|to (µs)%micros\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\"\n void analogSetPeriod(AnalogPin name, int micros) {\n PINOP(setAnalogPeriodUs(micros));\n }\n\n /**\n * Configure the pin as a digital input and generate an event when the pin is pulsed either high or low.\n * @param name digital pin to register to, eg: DigitalPin.P0\n * @param pulse the value of the pulse, eg: PulseValue.High\n */\n //% help=pins/on-pulsed weight=22 blockGap=16 advanced=true\n //% blockId=pins_on_pulsed block=\"on|pin %pin|pulsed %pulse\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n void onPulsed(DigitalPin name, PulseValue pulse, Action body) {\n MicroBitPin* pin = getPin((int)name);\n if (!pin) return;\n\n pin->eventOn(MICROBIT_PIN_EVENT_ON_PULSE);\n registerWithDal((int)name, (int)pulse, body);\n }\n\n /**\n * Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler.\n */\n //% help=pins/pulse-duration advanced=true\n //% blockId=pins_pulse_duration block=\"pulse duration (µs)\"\n //% weight=21 blockGap=8\n int pulseDuration() {\n return pxt::lastEvent.timestamp;\n }\n\n /**\n * Return the duration of a pulse at a pin in microseconds.\n * @param name the pin which measures the pulse, eg: DigitalPin.P0\n * @param value the value of the pulse, eg: PulseValue.High\n * @param maximum duration in microseconds\n */\n //% blockId=\"pins_pulse_in\" block=\"pulse in (µs)|pin %name|pulsed %value\"\n //% weight=20 advanced=true\n //% help=pins/pulse-in\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {\n MicroBitPin* pin = getPin((int)name);\n if (!pin) return 0;\n\n#if MICROBIT_CODAL\n // set polarity\n pin->setPolarity(PulseValue::High == value ? 1 : 0);\n // record pulse\n int period = pin->getPulseUs(maxDuration);\n // timeout\n if (DEVICE_CANCELLED == period)\n return 0;\n // success!\n return period;\n#else\n int pulse = value == PulseValue::High ? 1 : 0;\n uint64_t tick = system_timer_current_time_us();\n uint64_t maxd = (uint64_t)maxDuration;\n while(pin->getDigitalValue() != pulse) {\n if(system_timer_current_time_us() - tick > maxd)\n return 0;\n }\n\n uint64_t start = system_timer_current_time_us();\n while(pin->getDigitalValue() == pulse) {\n if(system_timer_current_time_us() - tick > maxd)\n return 0;\n }\n uint64_t end = system_timer_current_time_us();\n return end - start;\n#endif\n }\n\n /**\n * Write a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).\n * @param name pin to write to, eg: AnalogPin.P0\n * @param value angle or rotation speed, eg:180,90,0\n */\n //% help=pins/servo-write-pin weight=20\n //% blockId=device_set_servo_pin block=\"servo write|pin %name|to %value\" blockGap=8\n //% parts=microservo trackArgs=0\n //% value.min=0 value.max=180\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void servoWritePin(AnalogPin name, int value) {\n PINOP(setServoValue(value));\n }\n\n /**\n * Specifies that a continuous servo is connected.\n */\n //%\n void servoSetContinuous(AnalogPin name, bool value) {\n // handled in simulator\n }\n\n /**\n * Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds.\n * @param name pin name\n * @param micros pulse duration in micro seconds, eg:1500\n */\n //% help=pins/servo-set-pulse weight=19\n //% blockId=device_set_servo_pulse block=\"servo set pulse|pin %value|to (µs) %micros\"\n //% value.fieldEditor=\"gridpicker\" value.fieldOptions.columns=4\n //% value.fieldOptions.tooltips=\"false\" value.fieldOptions.width=\"250\"\n void servoSetPulse(AnalogPin name, int micros) {\n PINOP(setServoPulseUs(micros));\n }\n\n\n PinCompat* pitchPin = NULL;\n uint8_t pitchVolume = 0xff;\n bool analogTonePlaying = false;\n\n /**\n * Set the pin used when using analog pitch or music.\n * @param name pin to modulate pitch from\n */\n //% blockId=device_analog_set_pitch_pin block=\"analog set pitch pin %name\"\n //% help=pins/analog-set-pitch-pin weight=3 advanced=true\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void analogSetPitchPin(AnalogPin name) {\n pitchPin = getPin((int)name);\n }\n\n void pinAnalogSetPitch(PinCompat* pin, int frequency, int ms) {\n if (frequency <= 0 || pitchVolume == 0) {\n pin->setAnalogValue(0);\n } else {\n int v = 1 << (pitchVolume >> 5);\n pin->setAnalogValue(v);\n pin->setAnalogPeriodUs(1000000/frequency);\n }\n }\n\n /**\n * Sets the volume on the pitch pin\n * @param volume the intensity of the sound from 0..255\n */\n //% blockId=device_analog_set_pitch_volume block=\"analog set pitch volume $volume\"\n //% help=pins/analog-set-pitch-volume weight=3 advanced=true\n //% volume.min=0 volume.max=255\n //% deprecated\n void analogSetPitchVolume(int volume) {\n pitchVolume = max(0, min(0xff, volume));\n\n if (analogTonePlaying) {\n int v = pitchVolume == 0 ? 0 : 1 << (pitchVolume >> 5);\n if (NULL != pitchPin)\n pitchPin->setAnalogValue(v);\n }\n }\n\n /**\n * Gets the volume the pitch pin from 0..255\n */\n //% blockId=device_analog_pitch_volume block=\"analog pitch volume\"\n //% help=pins/analog-pitch-volume weight=3 advanced=true\n //% deprecated\n int analogPitchVolume() {\n return pitchVolume;\n }\n\n /**\n * Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.\n * @param frequency frequency to modulate in Hz.\n * @param ms duration of the pitch in milli seconds.\n */\n //% blockId=device_analog_pitch block=\"analog pitch %frequency|for (ms) %ms\"\n //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8\n void analogPitch(int frequency, int ms) {\n // init pins if needed\n if (NULL == pitchPin) {\n#if MICROBIT_CODAL\n pitchPin = &uBit.audio.virtualOutputPin;\n#else\n pitchPin = getPin((int)AnalogPin::P0);\n#endif \n }\n // set pitch\n analogTonePlaying = true;\n if (NULL != pitchPin)\n pinAnalogSetPitch(pitchPin, frequency, ms);\n // clear pitch\n if (ms > 0) {\n fiber_sleep(ms);\n if (NULL != pitchPin)\n pitchPin->setAnalogValue(0);\n analogTonePlaying = false;\n // causes issues with v2 DMA.\n // fiber_sleep(5);\n }\n }\n\n\n /**\n * Configure the pull directiion of of a pin.\n * @param name pin to set the pull mode on, eg: DigitalPin.P0\n * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp\n */\n //% help=pins/set-pull weight=3 advanced=true\n //% blockId=device_set_pull block=\"set pull|pin %pin|to %pull\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n void setPull(DigitalPin name, PinPullMode pull) {\n#if MICROBIT_CODAL\n codal::PullMode m = pull == PinPullMode::PullDown\n ? codal::PullMode::Down\n : pull == PinPullMode::PullUp ? codal::PullMode::Up\n : codal::PullMode::None;\n PINOP(setPull(m));\n#else\n PinMode m = pull == PinPullMode::PullDown\n ? PinMode::PullDown\n : pull == PinPullMode::PullUp ? PinMode::PullUp\n : PinMode::PullNone;\n PINOP(setPull(m));\n#endif\n }\n\n /**\n * Configure the events emitted by this pin. Events can be subscribed to\n * using ``control.onEvent()``.\n * @param name pin to set the event mode on, eg: DigitalPin.P0\n * @param type the type of events for this pin to emit, eg: PinEventType.Edge\n */\n //% help=pins/set-events weight=4 advanced=true\n //% blockId=device_set_pin_events block=\"set pin %pin|to emit %type|events\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n void setEvents(DigitalPin name, PinEventType type) {\n getPin((int)name)->eventOn((int)type);\n }\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //%\n Buffer createBuffer(int size)\n {\n return mkBuffer(NULL, size);\n }\n\n\n /**\n * Set the matrix width for Neopixel strip (already assigned to a pin).\n * Should be used in conjunction with `set matrix width` from Neopixel package.\n * @param name pin of Neopixel strip, eg: DigitalPin.P1\n * @param value width of matrix (at least ``2``)\n */\n //% help=pins/neopixel-matrix-width weight=3 advanced=true\n //% blockId=pin_neopixel_matrix_width block=\"neopixel matrix width|pin %pin %width\" blockGap=8\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% width.defl=5 width.min=2\n void setMatrixWidth(DigitalPin pin, int width) {}\n\n#if MICROBIT_CODAL\n#define BUFFER_TYPE uint8_t*\n#else\n#define BUFFER_TYPE char*\n#endif\n\n /**\n * Read `size` bytes from a 7-bit I2C `address`.\n */\n //%\n Buffer i2cReadBuffer(int address, int size, bool repeat = false)\n {\n Buffer buf = createBuffer(size);\n uBit.i2c.read(address << 1, (BUFFER_TYPE)buf->data, size, repeat);\n return buf;\n }\n\n /**\n * Write bytes to a 7-bit I2C `address`.\n */\n //%\n int i2cWriteBuffer(int address, Buffer buf, bool repeat = false)\n {\n return uBit.i2c.write(address << 1, (BUFFER_TYPE)buf->data, buf->length, repeat);\n }\n\n SPI* spi = NULL;\n SPI* allocSPI() {\n if (NULL == spi)\n spi = new SPI(MOSI, MISO, SCK);\n return spi;\n }\n\n /**\n * Write to the SPI slave and return the response\n * @param value Data to be sent to the SPI slave\n */\n //% help=pins/spi-write weight=5 advanced=true\n //% blockId=spi_write block=\"spi write %value\"\n int spiWrite(int value) {\n auto p = allocSPI();\n return p->write(value);\n }\n\n /**\n * Write to and read from the SPI slave at the same time\n * @param command Data to be sent to the SPI slave (can be null)\n * @param response Data received from the SPI slave (can be null)\n */\n //% help=pins/spi-transfer argsNullable\n void spiTransfer(Buffer command, Buffer response) {\n if (!command && !response)\n target_panic(PANIC_INVALID_ARGUMENT);\n if (command && response && command->length != response->length)\n target_panic(PANIC_INVALID_ARGUMENT);\n auto p = allocSPI();\n unsigned len = command ? command->length : response->length;\n#if MICROBIT_CODAL\n p->transfer(command ? command->data : NULL, command ? len : 0,\n response ? response->data : NULL, response ? len : 0);\n#else\n for (unsigned i = 0; i < len; ++i) {\n int v = p->write(command ? command->data[i] : 0);\n if (response) response->data[i] = v;\n }\n#endif\n }\n\n /**\n * Set the SPI frequency\n * @param frequency the clock frequency, eg: 1000000\n */\n //% help=pins/spi-frequency weight=4 advanced=true\n //% blockId=spi_frequency block=\"spi frequency %frequency\"\n void spiFrequency(int frequency) {\n auto p = allocSPI();\n p->frequency(frequency);\n }\n\n /**\n * Set the SPI bits and mode\n * @param bits the number of bits, eg: 8\n * @param mode the mode, eg: 3\n */\n //% help=pins/spi-format weight=3 advanced=true\n //% blockId=spi_format block=\"spi format|bits %bits|mode %mode\"\n void spiFormat(int bits, int mode) {\n auto p = allocSPI();\n p->format(bits, mode);\n }\n\n#if MICROBIT_CODAL\n#define PIN_ARG(pin) *(getPin((int)(pin)))\n#else\n#define PIN_ARG(pin) (getPin((int)(pin)))->name\n#endif\n\n /**\n * Set the MOSI, MISO, SCK pins used by the SPI connection\n *\n */\n //% help=pins/spi-pins weight=2 advanced=true\n //% blockId=spi_pins block=\"spi set pins|MOSI %mosi|MISO %miso|SCK %sck\"\n //% mosi.fieldEditor=\"gridpicker\" mosi.fieldOptions.columns=4\n //% mosi.fieldOptions.tooltips=\"false\" mosi.fieldOptions.width=\"250\"\n //% miso.fieldEditor=\"gridpicker\" miso.fieldOptions.columns=4\n //% miso.fieldOptions.tooltips=\"false\" miso.fieldOptions.width=\"250\"\n //% sck.fieldEditor=\"gridpicker\" sck.fieldOptions.columns=4\n //% sck.fieldOptions.tooltips=\"false\" sck.fieldOptions.width=\"250\"\n void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) {\n if (NULL != spi) {\n delete spi;\n spi = NULL;\n }\n spi = new SPI(PIN_ARG(mosi), PIN_ARG(miso), PIN_ARG(sck));\n }\n\n /**\n * Mounts a push button on the given pin\n */\n //% help=pins/push-button advanced=true\n void pushButton(DigitalPin pin) {\n new MicroBitButton((PinName)getPin((int)(pin))->name, (int)pin, MICROBIT_BUTTON_ALL_EVENTS, PinMode::PullUp);\n }\n\n /**\n * Set the pin used when producing sounds and melodies. Default is P0.\n * @param name pin to modulate pitch from\n */\n //% blockId=pin_set_audio_pin block=\"set audio pin $name\"\n //% help=pins/set-audio-pin weight=3\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% weight=1\n void setAudioPin(AnalogPin name) {\n#if MICROBIT_CODAL\n uBit.audio.setPin(*getPin((int)name));\n uBit.audio.setPinEnabled(true);\n#else\n // v1 behavior\n pins::analogSetPitchPin(name);\n#endif\n }\n}",
2759
- "pins.ts": "/**\n * Control currents in Pins for analog/digital signals, servos, i2c, ...\n */\n//% color=#B22222 weight=30 icon=\"\\uf140\"\n//% advanced=true\nnamespace pins {\n /**\n * Map a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.\n * @param value value to map in ranges\n * @param fromLow the lower bound of the value's current range\n * @param fromHigh the upper bound of the value's current range, eg: 1023\n * @param toLow the lower bound of the value's target range\n * @param toHigh the upper bound of the value's target range, eg: 4\n */\n //% help=pins/map weight=23\n //% blockId=pin_map block=\"map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh\"\n export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {\n return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;\n }\n\n /**\n * Read one number from 7-bit I2C address.\n */\n //% help=pins/i2c-read-number blockGap=8 advanced=true\n //% blockId=pins_i2c_readnumber block=\"i2c read number|at address %address|of format %format|repeated %repeat\" weight=7\n export function i2cReadNumber(address: number, format: NumberFormat, repeated?: boolean): number {\n let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeated)\n return buf.getNumber(format, 0)\n }\n\n /**\n * Write one number to a 7-bit I2C address.\n */\n //% help=pins/i2c-write-number blockGap=8 advanced=true\n //% blockId=i2c_writenumber block=\"i2c write number|at address %address|with value %value|of format %format|repeated %repeat\" weight=6\n export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeated?: boolean): void {\n let buf = createBuffer(pins.sizeOf(format))\n buf.setNumber(format, 0, value)\n pins.i2cWriteBuffer(address, buf, repeated)\n }\n}\n",
2758
+ "pins.cpp": "#include \"pxt.h\"\n\n#if MICROBIT_CODAL\n#include \"Pin.h\"\n#define PinCompat codal::Pin\n#else\n#define PinCompat MicroBitPin\n#endif\n\nenum class DigitalPin {\n P0 = MICROBIT_ID_IO_P0,\n P1 = MICROBIT_ID_IO_P1,\n P2 = MICROBIT_ID_IO_P2,\n P3 = MICROBIT_ID_IO_P3,\n P4 = MICROBIT_ID_IO_P4,\n P5 = MICROBIT_ID_IO_P5,\n P6 = MICROBIT_ID_IO_P6,\n P7 = MICROBIT_ID_IO_P7,\n P8 = MICROBIT_ID_IO_P8,\n P9 = MICROBIT_ID_IO_P9,\n P10 = MICROBIT_ID_IO_P10,\n P11 = MICROBIT_ID_IO_P11,\n P12 = MICROBIT_ID_IO_P12,\n P13 = MICROBIT_ID_IO_P13,\n P14 = MICROBIT_ID_IO_P14,\n P15 = MICROBIT_ID_IO_P15,\n P16 = MICROBIT_ID_IO_P16,\n //% blockHidden=1\n P19 = MICROBIT_ID_IO_P19,\n //% blockHidden=1\n P20 = MICROBIT_ID_IO_P20,\n};\n\nenum class AnalogPin {\n P0 = MICROBIT_ID_IO_P0,\n P1 = MICROBIT_ID_IO_P1,\n P2 = MICROBIT_ID_IO_P2,\n P3 = MICROBIT_ID_IO_P3,\n P4 = MICROBIT_ID_IO_P4,\n P10 = MICROBIT_ID_IO_P10,\n //% block=\"P5 (write only)\"\n P5 = MICROBIT_ID_IO_P5,\n //% block=\"P6 (write only)\"\n P6 = MICROBIT_ID_IO_P6,\n //% block=\"P7 (write only)\"\n P7 = MICROBIT_ID_IO_P7,\n //% block=\"P8 (write only)\"\n P8 = MICROBIT_ID_IO_P8,\n //% block=\"P9 (write only)\"\n P9 = MICROBIT_ID_IO_P9,\n //% block=\"P11 (write only)\"\n P11 = MICROBIT_ID_IO_P11,\n //% block=\"P12 (write only)\"\n P12 = MICROBIT_ID_IO_P12,\n //% block=\"P13 (write only)\"\n P13 = MICROBIT_ID_IO_P13,\n //% block=\"P14 (write only)\"\n P14 = MICROBIT_ID_IO_P14,\n //% block=\"P15 (write only)\"\n P15 = MICROBIT_ID_IO_P15,\n //% block=\"P16 (write only)\"\n P16 = MICROBIT_ID_IO_P16,\n //% block=\"P19 (write only)\"\n //% blockHidden=1\n P19 = MICROBIT_ID_IO_P19,\n //% block=\"P20 (write only)\"\n //% blockHidden=1\n P20 = MICROBIT_ID_IO_P20\n};\n\nenum class PulseValue {\n //% block=high\n High = MICROBIT_PIN_EVT_PULSE_HI,\n //% block=low\n Low = MICROBIT_PIN_EVT_PULSE_LO\n};\n\nenum class PinPullMode {\n //% block=\"down\"\n PullDown = 0,\n //% block=\"up\"\n PullUp = 1,\n //% block=\"none\"\n PullNone = 2\n};\n\nenum class PinEventType {\n //% block=\"edge\"\n Edge = MICROBIT_PIN_EVENT_ON_EDGE,\n //% block=\"pulse\"\n Pulse = MICROBIT_PIN_EVENT_ON_PULSE,\n //% block=\"touch\"\n Touch = MICROBIT_PIN_EVENT_ON_TOUCH,\n //% block=\"none\"\n None = MICROBIT_PIN_EVENT_NONE\n};\n\n\nnamespace pxt\n{\nMicroBitPin *getPin(int id) {\n switch (id) {\n case MICROBIT_ID_IO_P0: return &uBit.io.P0;\n case MICROBIT_ID_IO_P1: return &uBit.io.P1;\n case MICROBIT_ID_IO_P2: return &uBit.io.P2;\n case MICROBIT_ID_IO_P3: return &uBit.io.P3;\n case MICROBIT_ID_IO_P4: return &uBit.io.P4;\n case MICROBIT_ID_IO_P5: return &uBit.io.P5;\n case MICROBIT_ID_IO_P6: return &uBit.io.P6;\n case MICROBIT_ID_IO_P7: return &uBit.io.P7;\n case MICROBIT_ID_IO_P8: return &uBit.io.P8;\n case MICROBIT_ID_IO_P9: return &uBit.io.P9;\n case MICROBIT_ID_IO_P10: return &uBit.io.P10;\n case MICROBIT_ID_IO_P11: return &uBit.io.P11;\n case MICROBIT_ID_IO_P12: return &uBit.io.P12;\n case MICROBIT_ID_IO_P13: return &uBit.io.P13;\n case MICROBIT_ID_IO_P14: return &uBit.io.P14;\n case MICROBIT_ID_IO_P15: return &uBit.io.P15;\n case MICROBIT_ID_IO_P16: return &uBit.io.P16;\n case MICROBIT_ID_IO_P19: return &uBit.io.P19;\n case MICROBIT_ID_IO_P20: return &uBit.io.P20;\n#if MICROBIT_CODAL\n case 1001: return &uBit.io.usbTx;\n case 1002: return &uBit.io.usbRx;\n#endif\n default: return NULL;\n }\n}\n\n} // pxt\n\nnamespace pins {\n #define PINOP(op) \\\n MicroBitPin *pin = getPin((int)name); \\\n if (!pin) return; \\\n pin->op\n\n #define PINREAD(op) \\\n MicroBitPin *pin = getPin((int)name); \\\n if (!pin) return 0; \\\n return pin->op\n\n\n //%\n MicroBitPin *getPinAddress(int id) {\n return getPin(id);\n }\n\n /**\n * Read the specified pin or connector as either 0 or 1\n * @param name pin to read from, eg: DigitalPin.P0\n */\n //% help=pins/digital-read-pin weight=30\n //% blockId=device_get_digital_pin block=\"digital read|pin %name\" blockGap=8\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n int digitalReadPin(DigitalPin name) {\n PINREAD(getDigitalValue());\n }\n\n /**\n * Set a pin or connector value to either 0 or 1.\n * @param name pin to write to, eg: DigitalPin.P0\n * @param value value to set on the pin, 1 eg,0\n */\n //% help=pins/digital-write-pin weight=29\n //% blockId=device_set_digital_pin block=\"digital write|pin %name|to %value\"\n //% value.min=0 value.max=1\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void digitalWritePin(DigitalPin name, int value) {\n PINOP(setDigitalValue(value));\n }\n\n /**\n * Read the connector value as analog, that is, as a value comprised between 0 and 1023.\n * @param name pin to write to, eg: AnalogPin.P0\n */\n //% help=pins/analog-read-pin weight=25\n //% blockId=device_get_analog_pin block=\"analog read|pin %name\" blockGap=\"8\"\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n int analogReadPin(AnalogPin name) {\n PINREAD(getAnalogValue());\n }\n\n /**\n * Set the connector value as analog. Value must be comprised between 0 and 1023.\n * @param name pin name to write to, eg: AnalogPin.P0\n * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0\n */\n //% help=pins/analog-write-pin weight=24\n //% blockId=device_set_analog_pin block=\"analog write|pin %name|to %value\" blockGap=8\n //% value.min=0 value.max=1023\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n void analogWritePin(AnalogPin name, int value) {\n PINOP(setAnalogValue(value));\n }\n\n /**\n * Configure the pulse-width modulation (PWM) period of the analog output in microseconds.\n * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.\n * @param name analog pin to set period to, eg: AnalogPin.P0\n * @param micros period in micro seconds. eg:20000\n */\n //% help=pins/analog-set-period weight=23 blockGap=8\n //% blockId=device_set_analog_period block=\"analog set period|pin %pin|to (µs)%micros\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\"\n void analogSetPeriod(AnalogPin name, int micros) {\n PINOP(setAnalogPeriodUs(micros));\n }\n\n /**\n * Configure the pin as a digital input and generate an event when the pin is pulsed either high or low.\n * @param name digital pin to register to, eg: DigitalPin.P0\n * @param pulse the value of the pulse, eg: PulseValue.High\n */\n //% help=pins/on-pulsed advanced=true\n //% blockId=pins_on_pulsed block=\"on|pin %pin|pulsed %pulse\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pulse\"\n //% weight=25\n //% blockGap=8\n void onPulsed(DigitalPin name, PulseValue pulse, Action body) {\n MicroBitPin* pin = getPin((int)name);\n if (!pin) return;\n\n pin->eventOn(MICROBIT_PIN_EVENT_ON_PULSE);\n registerWithDal((int)name, (int)pulse, body);\n }\n\n /**\n * Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler.\n */\n //% help=pins/pulse-duration advanced=true\n //% blockId=pins_pulse_duration block=\"pulse duration (µs)\"\n //% group=\"Pulse\"\n //% weight=24\n //% blockGap=8\n int pulseDuration() {\n return pxt::lastEvent.timestamp;\n }\n\n /**\n * Return the duration of a pulse at a pin in microseconds.\n * @param name the pin which measures the pulse, eg: DigitalPin.P0\n * @param value the value of the pulse, eg: PulseValue.High\n * @param maximum duration in microseconds\n */\n //% blockId=\"pins_pulse_in\" block=\"pulse in (µs)|pin %name|pulsed %value\"\n //% advanced=true\n //% help=pins/pulse-in\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Pulse\"\n //% weight=23\n //% blockGap=8\n int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {\n MicroBitPin* pin = getPin((int)name);\n if (!pin) return 0;\n\n#if MICROBIT_CODAL\n // set polarity\n pin->setPolarity(PulseValue::High == value ? 1 : 0);\n // record pulse\n int period = pin->getPulseUs(maxDuration);\n // timeout\n if (DEVICE_CANCELLED == period)\n return 0;\n // success!\n return period;\n#else\n int pulse = value == PulseValue::High ? 1 : 0;\n uint64_t tick = system_timer_current_time_us();\n uint64_t maxd = (uint64_t)maxDuration;\n while(pin->getDigitalValue() != pulse) {\n if(system_timer_current_time_us() - tick > maxd)\n return 0;\n }\n\n uint64_t start = system_timer_current_time_us();\n while(pin->getDigitalValue() == pulse) {\n if(system_timer_current_time_us() - tick > maxd)\n return 0;\n }\n uint64_t end = system_timer_current_time_us();\n return end - start;\n#endif\n }\n\n /**\n * Write a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).\n * @param name pin to write to, eg: AnalogPin.P0\n * @param value angle or rotation speed, eg:180,90,0\n */\n //% help=pins/servo-write-pin weight=20\n //% blockId=device_set_servo_pin block=\"servo write|pin %name|to %value\" blockGap=8\n //% parts=microservo trackArgs=0\n //% value.min=0 value.max=180\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Servo\"\n void servoWritePin(AnalogPin name, int value) {\n PINOP(setServoValue(value));\n }\n\n /**\n * Specifies that a continuous servo is connected.\n */\n //%\n void servoSetContinuous(AnalogPin name, bool value) {\n // handled in simulator\n }\n\n /**\n * Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds.\n * @param name pin name\n * @param micros pulse duration in micro seconds, eg:1500\n */\n //% help=pins/servo-set-pulse weight=19\n //% blockId=device_set_servo_pulse block=\"servo set pulse|pin %value|to (µs) %micros\"\n //% value.fieldEditor=\"gridpicker\" value.fieldOptions.columns=4\n //% value.fieldOptions.tooltips=\"false\" value.fieldOptions.width=\"250\"\n //% group=\"Servo\"\n void servoSetPulse(AnalogPin name, int micros) {\n PINOP(setServoPulseUs(micros));\n }\n\n\n PinCompat* pitchPin = NULL;\n uint8_t pitchVolume = 0xff;\n bool analogTonePlaying = false;\n\n /**\n * Set the pin used when using analog pitch or music.\n * @param name pin to modulate pitch from\n */\n //% blockId=device_analog_set_pitch_pin block=\"analog set pitch pin %name\"\n //% help=pins/analog-set-pitch-pin advanced=true\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=12\n //% blockGap=8\n void analogSetPitchPin(AnalogPin name) {\n pitchPin = getPin((int)name);\n }\n\n void pinAnalogSetPitch(PinCompat* pin, int frequency, int ms) {\n if (frequency <= 0 || pitchVolume == 0) {\n pin->setAnalogValue(0);\n } else {\n int v = 1 << (pitchVolume >> 5);\n pin->setAnalogValue(v);\n pin->setAnalogPeriodUs(1000000/frequency);\n }\n }\n\n /**\n * Sets the volume on the pitch pin\n * @param volume the intensity of the sound from 0..255\n */\n //% blockId=device_analog_set_pitch_volume block=\"analog set pitch volume $volume\"\n //% help=pins/analog-set-pitch-volume weight=3 advanced=true\n //% volume.min=0 volume.max=255\n //% deprecated\n void analogSetPitchVolume(int volume) {\n pitchVolume = max(0, min(0xff, volume));\n\n if (analogTonePlaying) {\n int v = pitchVolume == 0 ? 0 : 1 << (pitchVolume >> 5);\n if (NULL != pitchPin)\n pitchPin->setAnalogValue(v);\n }\n }\n\n /**\n * Gets the volume the pitch pin from 0..255\n */\n //% blockId=device_analog_pitch_volume block=\"analog pitch volume\"\n //% help=pins/analog-pitch-volume weight=3 advanced=true\n //% deprecated\n int analogPitchVolume() {\n return pitchVolume;\n }\n\n /**\n * Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.\n * @param frequency frequency to modulate in Hz.\n * @param ms duration of the pitch in milli seconds.\n */\n //% blockId=device_analog_pitch block=\"analog pitch %frequency|for (ms) %ms\"\n //% help=pins/analog-pitch async advanced=true\n //% group=\"Pins\"\n //% weight=14\n //% blockGap=8\n void analogPitch(int frequency, int ms) {\n // init pins if needed\n if (NULL == pitchPin) {\n#if MICROBIT_CODAL\n pitchPin = &uBit.audio.virtualOutputPin;\n#else\n pitchPin = getPin((int)AnalogPin::P0);\n#endif \n }\n // set pitch\n analogTonePlaying = true;\n if (NULL != pitchPin)\n pinAnalogSetPitch(pitchPin, frequency, ms);\n // clear pitch\n if (ms > 0) {\n fiber_sleep(ms);\n if (NULL != pitchPin)\n pitchPin->setAnalogValue(0);\n analogTonePlaying = false;\n // causes issues with v2 DMA.\n // fiber_sleep(5);\n }\n }\n\n\n /**\n * Configure the pull direction of of a pin.\n * @param name pin to set the pull mode on, eg: DigitalPin.P0\n * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp\n */\n //% help=pins/set-pull advanced=true\n //% blockId=device_set_pull block=\"set pull|pin %pin|to %pull\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=15\n //% blockGap=8\n void setPull(DigitalPin name, PinPullMode pull) {\n#if MICROBIT_CODAL\n codal::PullMode m = pull == PinPullMode::PullDown\n ? codal::PullMode::Down\n : pull == PinPullMode::PullUp ? codal::PullMode::Up\n : codal::PullMode::None;\n PINOP(setPull(m));\n#else\n PinMode m = pull == PinPullMode::PullDown\n ? PinMode::PullDown\n : pull == PinPullMode::PullUp ? PinMode::PullUp\n : PinMode::PullNone;\n PINOP(setPull(m));\n#endif\n }\n\n /**\n * Configure the events emitted by this pin. Events can be subscribed to\n * using ``control.onEvent()``.\n * @param name pin to set the event mode on, eg: DigitalPin.P0\n * @param type the type of events for this pin to emit, eg: PinEventType.Edge\n */\n //% help=pins/set-events advanced=true\n //% blockId=device_set_pin_events block=\"set pin %pin|to emit %type|events\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=13\n //% blockGap=8\n void setEvents(DigitalPin name, PinEventType type) {\n getPin((int)name)->eventOn((int)type);\n }\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //%\n Buffer createBuffer(int size)\n {\n return mkBuffer(NULL, size);\n }\n\n\n /**\n * Set the matrix width for Neopixel strip (already assigned to a pin).\n * Should be used in conjunction with `set matrix width` from Neopixel package.\n * @param name pin of Neopixel strip, eg: DigitalPin.P1\n * @param value width of matrix (at least ``2``)\n */\n //% help=pins/neopixel-matrix-width advanced=true\n //% blockId=pin_neopixel_matrix_width block=\"neopixel matrix width|pin %pin %width\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% width.defl=5 width.min=2\n //% group=\"Pins\"\n //% weight=11\n //% blockGap=8\n void setMatrixWidth(DigitalPin pin, int width) {}\n\n#if MICROBIT_CODAL\n#define BUFFER_TYPE uint8_t*\n#else\n#define BUFFER_TYPE char*\n#endif\n\n /**\n * Read `size` bytes from a 7-bit I2C `address`.\n */\n //%\n Buffer i2cReadBuffer(int address, int size, bool repeat = false)\n {\n Buffer buf = createBuffer(size);\n uBit.i2c.read(address << 1, (BUFFER_TYPE)buf->data, size, repeat);\n return buf;\n }\n\n /**\n * Write bytes to a 7-bit I2C `address`.\n */\n //%\n int i2cWriteBuffer(int address, Buffer buf, bool repeat = false)\n {\n return uBit.i2c.write(address << 1, (BUFFER_TYPE)buf->data, buf->length, repeat);\n }\n\n SPI* spi = NULL;\n SPI* allocSPI() {\n if (NULL == spi)\n spi = new SPI(MOSI, MISO, SCK);\n return spi;\n }\n\n /**\n * Write to the SPI slave and return the response\n * @param value Data to be sent to the SPI slave\n */\n //% help=pins/spi-write advanced=true\n //% blockId=spi_write block=\"spi write %value\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=53\n int spiWrite(int value) {\n auto p = allocSPI();\n return p->write(value);\n }\n\n /**\n * Write to and read from the SPI slave at the same time\n * @param command Data to be sent to the SPI slave (can be null)\n * @param response Data received from the SPI slave (can be null)\n */\n //% help=pins/spi-transfer argsNullable\n void spiTransfer(Buffer command, Buffer response) {\n if (!command && !response)\n target_panic(PANIC_INVALID_ARGUMENT);\n if (command && response && command->length != response->length)\n target_panic(PANIC_INVALID_ARGUMENT);\n auto p = allocSPI();\n unsigned len = command ? command->length : response->length;\n#if MICROBIT_CODAL\n p->transfer(command ? command->data : NULL, command ? len : 0,\n response ? response->data : NULL, response ? len : 0);\n#else\n for (unsigned i = 0; i < len; ++i) {\n int v = p->write(command ? command->data[i] : 0);\n if (response) response->data[i] = v;\n }\n#endif\n }\n\n /**\n * Set the SPI frequency\n * @param frequency the clock frequency, eg: 1000000\n */\n //% help=pins/spi-frequency advanced=true\n //% blockId=spi_frequency block=\"spi frequency %frequency\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=55\n void spiFrequency(int frequency) {\n auto p = allocSPI();\n p->frequency(frequency);\n }\n\n /**\n * Set the SPI bits and mode\n * @param bits the number of bits, eg: 8\n * @param mode the mode, eg: 3\n */\n //% help=pins/spi-format advanced=true\n //% blockId=spi_format block=\"spi format|bits %bits|mode %mode\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=54\n void spiFormat(int bits, int mode) {\n auto p = allocSPI();\n p->format(bits, mode);\n }\n\n#if MICROBIT_CODAL\n#define PIN_ARG(pin) *(getPin((int)(pin)))\n#else\n#define PIN_ARG(pin) (getPin((int)(pin)))->name\n#endif\n\n /**\n * Set the MOSI, MISO, SCK pins used by the SPI connection\n *\n */\n //% help=pins/spi-pins advanced=true\n //% blockId=spi_pins block=\"spi set pins|MOSI %mosi|MISO %miso|SCK %sck\"\n //% mosi.fieldEditor=\"gridpicker\" mosi.fieldOptions.columns=4\n //% mosi.fieldOptions.tooltips=\"false\" mosi.fieldOptions.width=\"250\"\n //% miso.fieldEditor=\"gridpicker\" miso.fieldOptions.columns=4\n //% miso.fieldOptions.tooltips=\"false\" miso.fieldOptions.width=\"250\"\n //% sck.fieldEditor=\"gridpicker\" sck.fieldOptions.columns=4\n //% sck.fieldOptions.tooltips=\"false\" sck.fieldOptions.width=\"250\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=51\n void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) {\n if (NULL != spi) {\n delete spi;\n spi = NULL;\n }\n spi = new SPI(PIN_ARG(mosi), PIN_ARG(miso), PIN_ARG(sck));\n }\n\n /**\n * Mounts a push button on the given pin\n */\n //% help=pins/push-button advanced=true\n void pushButton(DigitalPin pin) {\n new MicroBitButton((PinName)getPin((int)(pin))->name, (int)pin, MICROBIT_BUTTON_ALL_EVENTS, PinMode::PullUp);\n }\n\n /**\n * Set the pin used when producing sounds and melodies. Default is P0.\n * @param name pin to modulate pitch from\n */\n //% blockId=pin_set_audio_pin block=\"set audio pin $name\"\n //% help=pins/set-audio-pin weight=3\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% weight=1\n void setAudioPin(AnalogPin name) {\n#if MICROBIT_CODAL\n uBit.audio.setPin(*getPin((int)name));\n uBit.audio.setPinEnabled(true);\n#else\n // v1 behavior\n pins::analogSetPitchPin(name);\n#endif\n }\n}\n",
2759
+ "pins.ts": "/**\n * Control currents in Pins for analog/digital signals, servos, i2c, ...\n */\n//% color=#B22222 weight=30 icon=\"\\uf140\"\n//% advanced=true\n//% groups='[\"Pins\", \"Pulse\", \"I2C\", \"SPI\", \"micro:bit (V2)\"]'\nnamespace pins {\n /**\n * Map a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.\n * @param value value to map in ranges\n * @param fromLow the lower bound of the value's current range\n * @param fromHigh the upper bound of the value's current range, eg: 1023\n * @param toLow the lower bound of the value's target range\n * @param toHigh the upper bound of the value's target range, eg: 4\n */\n //% help=pins/map weight=23\n //% blockId=pin_map block=\"map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh\"\n export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {\n return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;\n }\n\n /**\n * Read one number from 7-bit I2C address.\n */\n //% help=pins/i2c-read-number blockGap=8 advanced=true\n //% blockId=pins_i2c_readnumber block=\"i2c read number|at address %address|of format %format|repeated %repeat\" weight=7\n //% group=\"I2C\"\n //% weight=45\n export function i2cReadNumber(address: number, format: NumberFormat, repeated?: boolean): number {\n let buf = pins.i2cReadBuffer(address, pins.sizeOf(format), repeated)\n return buf.getNumber(format, 0)\n }\n\n /**\n * Write one number to a 7-bit I2C address.\n */\n //% help=pins/i2c-write-number blockGap=8 advanced=true\n //% blockId=i2c_writenumber block=\"i2c write number|at address %address|with value %value|of format %format|repeated %repeat\" weight=6\n //% group=\"I2C\"\n //% weight=44\n export function i2cWriteNumber(address: number, value: number, format: NumberFormat, repeated?: boolean): void {\n let buf = createBuffer(pins.sizeOf(format))\n buf.setNumber(format, 0, value)\n pins.i2cWriteBuffer(address, buf, repeated)\n }\n}\n",
2760
2760
  "pinscompat.ts": "enum PinEvent {\n //% block=\"pulse high\"\n PulseHigh = DAL.MICROBIT_PIN_EVT_PULSE_HI, // DEVICE_PIN_EVT_PULSE_HI\n //% block=\"pulse low\"\n PulseLow = DAL.MICROBIT_PIN_EVT_PULSE_LO, // DEVICE_PIN_EVT_PULSE_LO\n //% block=\"rise\"\n Rise = DAL.MICROBIT_PIN_EVT_RISE, // DEVICE_PIN_EVT_RISE\n //% block=\"fall\"\n Fall = DAL.MICROBIT_PIN_EVT_FALL, // DEVICE_PIN_EVT_FALL\n}\n\n//% noRefCounting fixedInstances\ninterface DigitalInOutPin {\n digitalRead(): boolean;\n\n digitalWrite(value: boolean): void;\n\n onPulsed(pulse: PulseValue, body: () => void): void;\n\n onEvent(event: PinEvent, body: () => void): void;\n\n pulseIn(value: PulseValue, maxDuration?: number): number;\n\n setPull(pull: PinPullMode): void;\n}\n\n//% noRefCounting fixedInstances\ninterface AnalogInPin extends DigitalInOutPin {\n analogRead(): number;\n}\n\n//% noRefCounting fixedInstances\ninterface AnalogOutPin extends DigitalInOutPin {\n analogWrite(value: number): void;\n}\n\n//% noRefCounting fixedInstances\ninterface AnalogInOutPin extends AnalogInPin, AnalogOutPin {\n}\n\n//% noRefCounting fixedInstances\ninterface PwmOnlyPin extends DigitalInOutPin, AnalogOutPin {\n //% parts=microservo trackArgs=0\n analogSetPeriod(period: number): void;\n\n //% parts=microservo trackArgs=0\n servoWrite(value: number): void;\n\n //% parts=microservo trackArgs=0\n servoSetPulse(duration: number): void;\n\n //% parts=microservo tracArgs=0\n servoSetContinuous(value: boolean): void;\n}\n\n//% noRefCounting fixedInstances\ninterface PwmPin extends PwmOnlyPin, DigitalInOutPin, AnalogInPin {\n}\n\n//% noRefCounting fixedInstances\nclass MicrobitPin implements AnalogInPin, AnalogOutPin, AnalogInOutPin, PwmOnlyPin {\n public id: number;\n constructor(id: number) {\n this.id = id;\n }\n\n protected digitalId(): DigitalPin {\n return <DigitalPin>this.id;\n }\n\n protected analogId(): AnalogPin {\n return <AnalogPin>this.id;\n }\n\n digitalRead(): boolean {\n return pins.digitalReadPin(this.digitalId()) != 0;\n }\n\n digitalWrite(value: boolean): void {\n pins.digitalWritePin(this.digitalId(), value ? 1 : 0);\n }\n\n onPulsed(pulse: PulseValue, body: () => void): void {\n pins.onPulsed(this.digitalId(), pulse, body);\n }\n\n onEvent(event: PinEvent, body: () => void): void {\n // TODO\n }\n\n pulseIn(value: PulseValue, maxDuration?: number): number {\n return pins.pulseIn(this.digitalId(), value, maxDuration);\n }\n\n setPull(pull: PinPullMode): void {\n pins.setPull(this.digitalId(), pull);\n }\n\n analogRead(): number {\n return pins.analogReadPin(this.analogId());\n }\n\n analogWrite(value: number): void {\n pins.analogWritePin(this.analogId(), value);\n }\n\n analogSetPeriod(period: number): void {\n pins.analogSetPeriod(this.analogId(), period);\n }\n\n servoWrite(value: number): void {\n pins.servoWritePin(this.analogId(), value);\n }\n\n servoSetContinuous(value: boolean): void {\n pins.servoSetContinuous(this.analogId(), value);\n }\n\n servoSetPulse(duration: number): void {\n pins.servoSetPulse(this.analogId(), duration);\n }\n}\n\nnamespace pins {\n /**\n * Pin P0\n */\n //% fixedInstance whenUsed\n export const P0: PwmPin = new MicrobitPin(DigitalPin.P0);\n\n /**\n * Pin P1\n */\n //% fixedInstance whenUsed\n export const P1: PwmPin = new MicrobitPin(DigitalPin.P1);\n\n /**\n * Pin P2\n */\n //% fixedInstance whenUsed\n export const P2: PwmPin = new MicrobitPin(DigitalPin.P2);\n\n /**\n * Pin P3\n */\n //% fixedInstance whenUsed\n export const P3: AnalogInPin = new MicrobitPin(DigitalPin.P3);\n\n /**\n * Pin P4\n */\n //% fixedInstance whenUsed\n export const P4: AnalogInPin = new MicrobitPin(DigitalPin.P4);\n\n /**\n * Pin P5\n */\n //% fixedInstance whenUsed\n export const P5: DigitalInOutPin = new MicrobitPin(DigitalPin.P5);\n\n /**\n * Pin P6\n */\n //% fixedInstance whenUsed\n export const P6: DigitalInOutPin = new MicrobitPin(DigitalPin.P6);\n\n /**\n * Pin P7\n */\n //% fixedInstance whenUsed\n export const P7: DigitalInOutPin = new MicrobitPin(DigitalPin.P7);\n\n /**\n * Pin P8\n */\n //% fixedInstance whenUsed\n export const P8: DigitalInOutPin = new MicrobitPin(DigitalPin.P8);\n\n /**\n * Pin P9\n */\n //% fixedInstance whenUsed\n export const P9: DigitalInOutPin = new MicrobitPin(DigitalPin.P9);\n\n /**\n * Pin P10\n */\n //% fixedInstance whenUsed\n export const P10: AnalogInPin = new MicrobitPin(DigitalPin.P10);\n\n /**\n * Pin P3\n */\n //% fixedInstance whenUsed\n export const P11: DigitalInOutPin = new MicrobitPin(DigitalPin.P11);\n\n /**\n * Pin P12\n */\n //% fixedInstance whenUsed\n export const P12: DigitalInOutPin = new MicrobitPin(DigitalPin.P12);\n\n /**\n * Pin P13\n */\n //% fixedInstance whenUsed\n export const P13: DigitalInOutPin = new MicrobitPin(DigitalPin.P13);\n\n /**\n * Pin P14\n */\n //% fixedInstance whenUsed\n export const P14: DigitalInOutPin = new MicrobitPin(DigitalPin.P14);\n\n /**\n * Pin P15\n */\n //% fixedInstance whenUsed\n export const P15: DigitalInOutPin = new MicrobitPin(DigitalPin.P15);\n\n /**\n * Pin P16\n */\n //% fixedInstance whenUsed\n export const P16: DigitalInOutPin = new MicrobitPin(DigitalPin.P16);\n\n /**\n * Pin P19\n */\n //% fixedInstance whenUsed\n export const P19: DigitalInOutPin = new MicrobitPin(DigitalPin.P19);\n\n /**\n * Pin P19\n */\n //% fixedInstance whenUsed\n export const P20: DigitalInOutPin = new MicrobitPin(DigitalPin.P20);\n}\n",
2761
2761
  "platform.h": "#include \"nrf.h\"\n\n// helpful define to handle C++ differences in package\n#define PXT_MICROBIT_TAGGED_INT 1\n#define PXT_POWI 1\n",
2762
2762
  "poll.ts": "namespace control {\n class PollEvent {\n public eid: number;\n public vid: number;\n public start: number;\n public timeOut: number;\n public condition: () => boolean;\n public once: boolean;\n constructor(eid: number, vid: number, start: number, timeOut: number, condition: () => boolean, once: boolean) {\n this.eid = eid;\n this.vid = vid;\n this.start = start;\n this.timeOut = timeOut;\n this.condition = condition;\n this.once = once;\n }\n }\n\n let _pollEventQueue: PollEvent[] = undefined;\n\n function pollEvents() {\n while (_pollEventQueue.length > 0) {\n const now = control.millis();\n for (let i = 0; i < _pollEventQueue.length; ++i) {\n const ev = _pollEventQueue[i];\n if (ev.condition() || (ev.timeOut > 0 && now - ev.start > ev.timeOut)) {\n control.raiseEvent(ev.eid, ev.vid);\n if (ev.once) {\n _pollEventQueue.splice(i, 1);\n --i;\n }\n }\n }\n pause(50);\n }\n // release fiber\n _pollEventQueue = undefined;\n }\n\n export function __queuePollEvent(timeOut: number, condition: () => boolean, handler: () => void) {\n const ev = new PollEvent(\n DAL.DEVICE_ID_NOTIFY,\n control.allocateNotifyEvent(),\n control.millis(),\n timeOut,\n condition,\n !handler\n );\n\n // start polling fiber if needed\n if (!_pollEventQueue) {\n _pollEventQueue = [ev];\n control.runInParallel(pollEvents);\n }\n else {\n // add to the queue\n _pollEventQueue.push(ev)\n }\n\n // register event\n if (handler)\n control.onEvent(ev.eid, ev.vid, handler);\n else // or wait\n control.waitForEvent(ev.eid, ev.vid);\n } \n}\n\n/**\n * Busy wait for a condition to be true\n * @param condition condition to test for\n * @param timeOut if positive, maximum duration to wait for in milliseconds\n */\n//% blockId=\"pxt_pause_until\"\nfunction pauseUntil(condition: () => boolean, timeOut?: number): void {\n if (!condition || condition()) return; // optimistic path\n if (!timeOut) timeOut = 0;\n control.__queuePollEvent(timeOut, condition, undefined);\n}\n",
@@ -2766,7 +2766,7 @@ var pxtTargetBundle = {
2766
2766
  "pxt-python.d.ts": "/// <reference no-default-lib=\"true\"/>\n\ndeclare namespace _py {\n interface Array {\n //% py2tsOverride=\"push($0)\"\n append(value: any): void;\n\n //% py2tsOverride=\"concat($0)\"\n extend(other: Array): void;\n\n //% py2tsOverride=\"insertAt($0, $1)\"\n insert(index: number, value: any): void;\n\n //% py2tsOverride=\"removeElement($0)\"\n remove(value: any): void;\n\n //% py2tsOverride=\"sort($0?)\"\n sort(sorter?: (a: any, b: any) => number): void;\n\n //% py2tsOverride=\"reverse()\"\n reverse(): void;\n\n //% py2tsOverride=\"slice()\"\n copy(): void;\n\n //% pyHelper=\"py_array_pop\"\n pop(index?: number): any;\n\n //% pyHelper=\"py_array_clear\"\n clear(): void;\n\n //% pyHelper=\"py_array_index\"\n index(value: any, start?: number, end?: number): number;\n\n //% pyHelper=\"py_array_count\"\n count(value: any): number;\n }\n\n interface String {\n //% pyHelper=\"py_string_capitalize\"\n capitalize(): string;\n\n //% pyHelper=\"py_string_casefold\"\n casefold(): string;\n\n //% pyHelper=\"py_string_center\"\n center(width: number, fillChar?: string): string;\n\n //% pyHelper=\"py_string_count\"\n count(sub: string, start?: number, end?: number): number;\n\n //% pyHelper=\"py_string_endswith\"\n endswith(suffix: string, start?: number, end?: number): boolean;\n\n //% pyHelper=\"py_string_find\"\n find(sub: string, start?: number, end?: number): number;\n\n //% pyHelper=\"py_string_index\"\n index(sub: string, start?: number, end?: number): number;\n\n //% pyHelper=\"py_string_isalnum\"\n isalnum(): boolean;\n\n //% pyHelper=\"py_string_isalpha\"\n isalpha(): boolean;\n\n //% pyHelper=\"py_string_isascii\"\n isascii(): boolean;\n\n //% pyHelper=\"py_string_isdigit\"\n isdigit(): boolean;\n\n //% pyHelper=\"py_string_isnumeric\"\n isnumeric(): boolean;\n\n //% pyHelper=\"py_string_isspace\"\n isspace(): boolean;\n\n //% pyHelper=\"py_string_isdecimal\"\n isdecimal(): boolean;\n\n //% pyHelper=\"py_string_isidentifier\"\n isidentifier(): boolean;\n\n //% pyHelper=\"py_string_islower\"\n islower(): boolean;\n\n //% pyHelper=\"py_string_isprintable\"\n isprintable(): boolean;\n\n //% pyHelper=\"py_string_istitle\"\n istitle(): boolean;\n\n //% pyHelper=\"py_string_isupper\"\n isupper(): boolean;\n\n //% pyHelper=\"py_string_join\"\n join(iterable: any[]): string;\n\n //% pyHelper=\"py_string_ljust\"\n ljust(width: number, fillChar?: string): string;\n\n //% pyHelper=\"py_string_lower\"\n lower(): string;\n\n //% pyHelper=\"py_string_lstrip\"\n lstrip(chars?: string): string;\n\n //% py2tsOverride=\"replace($0, $1)\"\n replace(oldString: string, newString: string): string;\n\n //% pyHelper=\"py_string_rfind\"\n rfind(sub: string, start?: number, end?: number): number;\n\n //% pyHelper=\"py_string_rindex\"\n rindex(sub: string, start?: number, end?: number): number;\n\n //% pyHelper=\"py_string_rjust\"\n rjust(width: number, fillChar?: string): string;\n\n //% pyHelper=\"py_string_rsplit\"\n rsplit(sep?: string, maxSplit?: number): string[];\n\n //% pyHelper=\"py_string_rstrip\"\n rstrip(chars?: string): string;\n\n //% pyHelper=\"py_string_split\"\n split(sep?: string, maxsplit?: number): string[];\n\n //% pyHelper=\"py_string_splitlines\"\n splitlines(keepends?: boolean): string[];\n\n //% pyHelper=\"py_string_startswith\"\n startswith(prefix: string, start?: number, end?: number): boolean;\n\n //% pyHelper=\"py_string_strip\"\n strip(chars?: string): string;\n\n //% pyHelper=\"py_string_swapcase\"\n swapcase(): string;\n\n //% pyHelper=\"py_string_title\"\n title(): string;\n\n //% pyHelper=\"py_string_upper\"\n upper(): string;\n\n //% pyHelper=\"py_string_zfill\"\n zfill(width: number): string;\n }\n\n interface Dict {\n clear(): void;\n copy(): void;\n get(key: string, defaultValue?: any): any;\n // items(): [string, any][];\n keys(): string[];\n pop(key: string, defaultValue?: any): any;\n // popitem(): [string, any];\n setdefault(key: string, defaultValue?: any): any;\n update(other: Dict): void;\n values(): any[];\n }\n\n interface Set {\n isdisjoint(other: Set): boolean;\n issubset(other: Set): boolean;\n issuperset(other: Set): boolean;\n union(other: Set): Set;\n intersection(other: Set): Set;\n difference(other: Set): Set;\n symmetric_difference(other: Set): Set;\n copy(): Set;\n update(other: Set): void;\n intersection_update(other: Set): void;\n difference_update(other: Set): void;\n symmetric_difference_update(other: Set): void;\n add(elem: any): void;\n remove(elem: any): void;\n discard(elem: any): void;\n pop(): any;\n clear(): void;\n }\n}",
2767
2767
  "pxt.cpp": "#include \"pxtbase.h\"\n\nusing namespace std;\n\nnamespace pxt {\n\nAction mkAction(int totallen, RefAction *act) {\n check(getVTable(act)->classNo == BuiltInType::RefAction, PANIC_INVALID_BINARY_HEADER, 1);\n#ifdef PXT_VM\n check(act->initialLen <= totallen, PANIC_INVALID_BINARY_HEADER, 13);\n#endif\n\n if (totallen == 0) {\n return (TValue)act; // no closure needed\n }\n\n void *ptr = gcAllocate(sizeof(RefAction) + totallen * sizeof(void *));\n RefAction *r = new (ptr) RefAction();\n r->len = totallen;\n#ifdef PXT_VM\n r->numArgs = act->numArgs;\n r->initialLen = act->initialLen;\n r->flags = 0;\n#endif\n r->func = act->func;\n memset(r->fields, 0, r->len * sizeof(void *));\n\n MEMDBG(\"mkAction: start=%p => %p\", act, r);\n\n return (Action)r;\n}\n\nRefRecord *mkClassInstance(VTable *vtable) {\n intcheck(vtable->methods[0] == &RefRecord_destroy, PANIC_SIZE, 3);\n // intcheck(vtable->methods[1] == &RefRecord_print, PANIC_SIZE, 4);\n\n void *ptr = gcAllocate(vtable->numbytes);\n RefRecord *r = new (ptr) RefRecord(vtable);\n memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord));\n MEMDBG(\"mkClass: vt=%p => %p\", vtable, r);\n return r;\n}\n\nTValue RefRecord::ld(int idx) {\n // intcheck((reflen == 255 ? 0 : reflen) <= idx && idx < len, PANIC_OUT_OF_BOUNDS, 1);\n return fields[idx];\n}\n\nTValue RefRecord::ldref(int idx) {\n // DMESG(\"LD %p len=%d reflen=%d idx=%d\", this, len, reflen, idx);\n // intcheck(0 <= idx && idx < reflen, PANIC_OUT_OF_BOUNDS, 2);\n return fields[idx];\n}\n\nvoid RefRecord::st(int idx, TValue v) {\n // intcheck((reflen == 255 ? 0 : reflen) <= idx && idx < len, PANIC_OUT_OF_BOUNDS, 3);\n fields[idx] = v;\n}\n\nvoid RefRecord::stref(int idx, TValue v) {\n // DMESG(\"ST %p len=%d reflen=%d idx=%d\", this, len, reflen, idx);\n // intcheck(0 <= idx && idx < reflen, PANIC_OUT_OF_BOUNDS, 4);\n fields[idx] = v;\n}\n\nvoid RefObject::destroyVT() {\n ((RefObjectMethod)getVTable(this)->methods[0])(this);\n}\n\n//%\nvoid deleteRefObject(RefObject *obj) {\n obj->destroyVT();\n}\n\nvoid RefObject::printVT() {\n ((RefObjectMethod)getVTable(this)->methods[1])(this);\n}\n\nvoid RefRecord_destroy(RefRecord *) {}\n\nvoid RefRecord_print(RefRecord *r) {\n DMESG(\"RefRecord %p size=%d bytes\", r, getVTable(r)->numbytes);\n}\n\nvoid Segment::set(unsigned i, TValue value) {\n if (i < size) {\n data[i] = value;\n } else if (i < Segment::MaxSize) {\n growByMin(i + 1);\n data[i] = value;\n } else {\n return;\n }\n if (length <= i) {\n length = i + 1;\n }\n\n#ifdef DEBUG_BUILD\n DMESG(\"In Segment::set\");\n this->print();\n#endif\n\n return;\n}\n\nstatic inline int growthFactor(int size) {\n if (size == 0) {\n return 4;\n }\n if (size < 64) {\n return size * 2; // Double\n }\n if (size < 512) {\n return size * 5 / 3; // Grow by 1.66 rate\n }\n // Grow by constant rate\n if ((unsigned)size + 256 < Segment::MaxSize)\n return size + 256;\n else\n return Segment::MaxSize;\n}\n\nvoid LLSegment::setLength(unsigned newLen) {\n if (newLen > Segment::MaxSize)\n return;\n\n if (newLen > size) {\n int newSize = growthFactor(size);\n if (newSize < (int)newLen)\n newSize = newLen;\n\n // this will throw if unable to allocate\n TValue *tmp = (TValue *)(xmalloc(newSize * sizeof(TValue)));\n\n // Copy existing data\n if (size) {\n memcpy(tmp, data, size * sizeof(TValue));\n }\n // fill the rest with default value\n memset(tmp + size, 0, (newSize - size) * sizeof(TValue));\n\n // free older segment;\n xfree(data);\n\n data = tmp;\n size = newSize;\n } else if (newLen < length) {\n memset(data + newLen, 0, (length - newLen) * sizeof(TValue));\n }\n\n length = newLen;\n}\n\nvoid LLSegment::set(unsigned idx, TValue v) {\n if (idx >= Segment::MaxSize)\n return;\n if (idx >= length)\n setLength(idx + 1);\n data[idx] = v;\n}\n\nTValue LLSegment::pop() {\n if (length > 0) {\n --length;\n TValue value = data[length];\n data[length] = 0;\n return value;\n }\n return 0;\n}\n\nvoid LLSegment::destroy() {\n length = size = 0;\n xfree(data);\n data = nullptr;\n}\n\nvoid Segment::growByMin(ramint_t minSize) {\n ramint_t newSize = max(minSize, (ramint_t)growthFactor(size));\n\n if (size < newSize) {\n // this will throw if unable to allocate\n TValue *tmp = (TValue *)(gcAllocateArray(newSize * sizeof(TValue)));\n\n // Copy existing data\n if (size)\n memcpy(tmp, data, size * sizeof(TValue));\n // fill the rest with default value\n memset(tmp + size, 0, (newSize - size) * sizeof(TValue));\n\n data = tmp;\n size = newSize;\n\n#ifdef DEBUG_BUILD\n DMESG(\"growBy - after reallocation\");\n this->print();\n#endif\n }\n // else { no shrinking yet; }\n return;\n}\n\nvoid Segment::ensure(ramint_t newSize) {\n if (newSize < size) {\n return;\n }\n growByMin(newSize);\n}\n\nvoid Segment::setLength(unsigned newLength) {\n if (newLength > size) {\n ensure(newLength);\n }\n length = newLength;\n return;\n}\n\nTValue Segment::pop() {\n#ifdef DEBUG_BUILD\n DMESG(\"In Segment::pop\");\n this->print();\n#endif\n\n if (length > 0) {\n --length;\n TValue value = data[length];\n data[length] = Segment::DefaultValue;\n return value;\n }\n return Segment::DefaultValue;\n}\n\n// this function removes an element at index i and shifts the rest of the elements to\n// left to fill the gap\nTValue Segment::remove(unsigned i) {\n#ifdef DEBUG_BUILD\n DMESG(\"In Segment::remove index:%d\", i);\n this->print();\n#endif\n if (i < length) {\n // value to return\n TValue ret = data[i];\n if (i + 1 < length) {\n // Move the rest of the elements to fill in the gap.\n memmove(data + i, data + i + 1, (length - i - 1) * sizeof(void *));\n }\n length--;\n data[length] = Segment::DefaultValue;\n#ifdef DEBUG_BUILD\n DMESG(\"After Segment::remove index:%d\", i);\n this->print();\n#endif\n return ret;\n }\n return Segment::DefaultValue;\n}\n\n// this function inserts element value at index i by shifting the rest of the elements right.\nvoid Segment::insert(unsigned i, TValue value) {\n#ifdef DEBUG_BUILD\n DMESG(\"In Segment::insert index:%d value:%d\", i, value);\n this->print();\n#endif\n\n if (i < length) {\n ensure(length + 1);\n\n // Move the rest of the elements to fill in the gap.\n memmove(data + i + 1, data + i, (length - i) * sizeof(void *));\n\n data[i] = value;\n length++;\n } else {\n // This is insert beyond the length, just call set which will adjust the length\n set(i, value);\n }\n#ifdef DEBUG_BUILD\n DMESG(\"After Segment::insert index:%d\", i);\n this->print();\n#endif\n}\n\nvoid Segment::print() {\n DMESG(\"Segment: %p, length: %d, size: %d\", data, (unsigned)length, (unsigned)size);\n for (unsigned i = 0; i < size; i++) {\n DMESG(\"-> %d\", (unsigned)(uintptr_t)data[i]);\n }\n}\n\nvoid Segment::destroy() {\n#ifdef DEBUG_BUILD\n DMESG(\"In Segment::destroy\");\n this->print();\n#endif\n length = size = 0;\n data = nullptr;\n}\n\nPXT_VTABLE_CTOR(RefCollection) {}\n\nvoid RefCollection::destroy(RefCollection *t) {\n t->head.destroy();\n}\n\nvoid RefCollection::print(RefCollection *t) {\n DMESG(\"RefCollection %p size=%d\", t, t->head.getLength());\n t->head.print();\n}\n\nPXT_VTABLE(RefAction, ValType::Function)\nRefAction::RefAction() : PXT_VTABLE_INIT(RefAction) {}\n\n// fields[] contain captured locals\nvoid RefAction::destroy(RefAction *t) {}\n\nvoid RefAction::print(RefAction *t) {\n#ifdef PXT_VM\n DMESG(\"RefAction %p pc=%X size=%d\", t, (uint32_t)t->func, t->len);\n#else\n DMESG(\"RefAction %p pc=%X size=%d\", t, (const uint8_t *)t->func - (const uint8_t *)bytecode,\n t->len);\n#endif\n}\n\nPXT_VTABLE_CTOR(RefRefLocal) {\n v = 0;\n}\n\nvoid RefRefLocal::print(RefRefLocal *t) {\n DMESG(\"RefRefLocal %p v=%p\", t, (void *)t->v);\n}\n\nvoid RefRefLocal::destroy(RefRefLocal *t) {\n decr(t->v);\n}\n\nPXT_VTABLE_CTOR(RefMap) {}\n\nvoid RefMap::destroy(RefMap *t) {\n t->keys.destroy();\n t->values.destroy();\n}\n\nint RefMap::findIdx(String key) {\n auto len = keys.getLength();\n auto data = (String *)keys.getData();\n\n // fast path\n for (unsigned i = 0; i < len; ++i) {\n if (data[i] == key)\n return i;\n }\n\n // slow path\n auto keylen = key->getUTF8Size();\n auto keydata = key->getUTF8Data();\n for (unsigned i = 0; i < len; ++i) {\n auto s = data[i];\n if (s->getUTF8Size() == keylen && memcmp(keydata, s->getUTF8Data(), keylen) == 0)\n return i;\n }\n\n return -1;\n}\n\nvoid RefMap::print(RefMap *t) {\n DMESG(\"RefMap %p size=%d\", t, t->keys.getLength());\n}\n\nvoid debugMemLeaks() {}\n\nvoid error(PXT_PANIC code, int subcode) {\n DMESG(\"Error: %d [%d]\", code, subcode);\n target_panic(code);\n}\n\n#ifndef PXT_VM\nuint16_t *bytecode;\n#endif\nTValue *globals;\n\nvoid checkStr(bool cond, const char *msg) {\n if (!cond) {\n while (true) {\n // uBit.display.scroll(msg, 100);\n // uBit.sleep(100);\n }\n }\n}\n\n#ifdef PXT_VM\nint templateHash() {\n return *(int*)&vmImg->infoHeader->hexHash;\n}\n\nint programHash() {\n return *(int*)&vmImg->infoHeader->programHash;\n}\n\nint getNumGlobals() {\n return (int)vmImg->infoHeader->allocGlobals;\n}\n\nString programName() {\n return mkString((char *)vmImg->infoHeader->name);\n}\n#else\nint templateHash() {\n return ((int *)bytecode)[4];\n}\n\nint programHash() {\n return ((int *)bytecode)[6];\n}\n\nint getNumGlobals() {\n return bytecode[16];\n}\n\nString programName() {\n return ((String *)bytecode)[15];\n}\n#endif\n\n#ifndef PXT_VM\nvoid variantNotSupported(const char *v) {\n DMESG(\"variant not supported: %s\", v);\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n}\n\nvoid exec_binary(unsigned *pc) {\n // XXX re-enable once the calibration code is fixed and [editor/embedded.ts]\n // properly prepends a call to [internal_main].\n // ::touch_develop::internal_main();\n\n // unique group for radio based on source hash\n // ::touch_develop::micro_bit::radioDefaultGroup = programHash();\n\n unsigned ver = *pc++;\n checkStr(ver == 0x4210, \":( Bad runtime version\");\n\n bytecode = *((uint16_t **)pc++); // the actual bytecode is here\n\n if (((uint32_t *)bytecode)[0] == 0x923B8E71) {\n variantNotSupported((const char *)bytecode + 16);\n return;\n }\n\n globals = (TValue *)app_alloc(sizeof(TValue) * getNumGlobals());\n memset(globals, 0, sizeof(TValue) * getNumGlobals());\n\n // can be any valid address, best in RAM for speed\n globals[0] = (TValue)&globals;\n\n // just compare the first word\n // TODO\n checkStr(((uint32_t *)bytecode)[0] == 0x923B8E70 && (unsigned)templateHash() == *pc,\n \":( Failed partial flash\");\n\n uintptr_t startptr = (uintptr_t)bytecode;\n\n startptr += 64; // header\n\n initPerfCounters();\n\n initRuntime();\n\n runAction0((Action)startptr);\n\n pxt::releaseFiber();\n}\n\nvoid start() {\n exec_binary((unsigned *)functionsAndBytecode);\n}\n#endif\n\n} // namespace pxt\n\nnamespace Array_ {\n//%\nbool isArray(TValue arr) {\n auto vt = getAnyVTable(arr);\n return vt && vt->classNo == BuiltInType::RefCollection;\n}\n} // namespace Array_\n\nnamespace pxtrt {\n//% expose\nRefCollection *keysOf(TValue v) {\n auto r = NEW_GC(RefCollection);\n MEMDBG(\"mkColl[keys]: => %p\", r);\n if (getAnyVTable(v) != &RefMap_vtable)\n return r;\n auto rm = (RefMap *)v;\n auto len = rm->keys.getLength();\n if (!len)\n return r;\n registerGCObj(r);\n r->setLength(len);\n auto dst = r->getData();\n memcpy(dst, rm->keys.getData(), len * sizeof(TValue));\n unregisterGCObj(r);\n return r;\n}\n//% expose\nTValue mapDeleteByString(RefMap *map, String key) {\n if (getAnyVTable((TValue)map) != &RefMap_vtable)\n soft_panic(PANIC_DELETE_ON_CLASS);\n int i = map->findIdx(key);\n if (i >= 0) {\n map->keys.remove(i);\n map->values.remove(i);\n }\n return TAG_TRUE;\n}\n\n} // namespace pxtrt\n",
2768
2768
  "pxt.h": "#ifndef __PXT_H\n#define __PXT_H\n\n//#define DEBUG_MEMLEAKS 1\n\n#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n\n#include \"pxtbase.h\"\n\nnamespace pxt {\n\nclass RefMImage : public RefObject {\n public:\n ImageData *img;\n\n RefMImage(ImageData *d);\n void makeWritable();\n static void destroy(RefMImage *map);\n static void print(RefMImage *map);\n static void scan(RefMImage *t);\n static unsigned gcsize(RefMImage *t);\n};\n\n#define MSTR(s) ManagedString((s)->getUTF8Data(), (s)->getUTF8Size())\n\nstatic inline String PSTR(ManagedString s) {\n return mkString(s.toCharArray(), s.length());\n}\n\ntypedef uint32_t ImageLiteral_;\n\nstatic inline ImageData *imageBytes(ImageLiteral_ lit) {\n return (ImageData *)lit;\n}\n\n#if MICROBIT_CODAL\n// avoid clashes with codal-defined classes\n#define Image MImage\n#define Button MButton\n#endif\n\ntypedef MicroBitPin DevicePin;\n\ntypedef RefMImage *Image;\n\nextern MicroBit uBit;\nextern MicroBitEvent lastEvent;\nextern bool serialLoggingDisabled;\n\nMicroBitPin *getPin(int id);\n\nstatic inline int min_(int a, int b) {\n if (a < b)\n return a;\n else\n return b;\n}\n\nstatic inline int max_(int a, int b) {\n if (a > b)\n return a;\n else\n return b;\n}\n\nvoid initMicrobitGC();\n\n} // namespace pxt\n\nusing namespace pxt;\n\n#define DEVICE_EVT_ANY 0\n\n#undef PXT_MAIN\n#define PXT_MAIN \\\n int main() { \\\n pxt::initMicrobitGC(); \\\n pxt::start(); \\\n return 0; \\\n }\n\n#endif\n\n// vim: ts=2 sw=2 expandtab\n",
2769
- "pxt.json": "{\n \"name\": \"core\",\n \"description\": \"The microbit core library\",\n \"dependencies\": {},\n \"files\": [\n \"README.md\",\n \"platform.h\",\n \"pxt.cpp\",\n \"pxt.h\",\n \"pxtbase.h\",\n \"pxtcore.h\",\n \"math.ts\",\n \"dal.d.ts\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"pxt-core.d.ts\",\n \"core.cpp\",\n \"pxt-helpers.ts\",\n \"helpers.ts\",\n \"pxt-python.d.ts\",\n \"pxt-python-helpers.ts\",\n \"pinscompat.ts\",\n \"configkeys.h\",\n \"gc.cpp\",\n \"codal.cpp\",\n \"images.cpp\",\n \"basic.cpp\",\n \"basic.ts\",\n \"icons.ts\",\n \"icons.jres\",\n \"input.cpp\",\n \"input.ts\",\n \"gestures.jres\",\n \"control.ts\",\n \"control.cpp\",\n \"controlgc.cpp\",\n \"perfcounters.ts\",\n \"interval.ts\",\n \"gcstats.ts\",\n \"console.ts\",\n \"game.ts\",\n \"led.cpp\",\n \"led.ts\",\n \"music.cpp\",\n \"music.ts\",\n \"melodies.ts\",\n \"pins.cpp\",\n \"pins.ts\",\n \"serial.cpp\",\n \"serial.ts\",\n \"buffer.cpp\",\n \"buffer.ts\",\n \"json.ts\",\n \"poll.ts\",\n \"controlmessage.ts\",\n \"pxtparts.json\",\n \"advmath.cpp\",\n \"trig.cpp\",\n \"fixed.ts\",\n \"templates.ts\",\n \"sendbuffer.s\",\n \"sendbuffernrf52.s\",\n \"sendbufferbrightness.s\",\n \"light.cpp\",\n \"logo.cpp\",\n \"loops.ts\",\n \"touchmode.cpp\",\n \"soundexpressions.ts\",\n \"soundexpressions.cpp\",\n \"parts/speaker.svg\",\n \"parts/headphone.svg\"\n ],\n \"testFiles\": [],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"dalDTS\": {\n \"compileServiceVariant\": \"mbcodal\",\n \"includeDirs\": [\n \"libraries/codal-core/inc\",\n \"libraries/codal-microbit-v2/inc\",\n \"libraries/codal-microbit-v2/model\",\n \"libraries/codal-microbit-v2/inc/compat\",\n \"pxtapp\"\n ],\n \"excludePrefix\": [\n \"USB_\",\n \"REQUEST_\",\n \"LIS3DH_\",\n \"FXOS8700_\",\n \"MMA8\",\n \"LSM303_\",\n \"MAG_\",\n \"MPU6050_\",\n \"REF_TAG_\",\n \"HF2_\",\n \"PXT_REF_TAG_\",\n \"MS_\",\n \"SCSI_\"\n ]\n },\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"fiber_user_data\": 1,\n \"pxt\": 1\n }\n },\n \"optionalConfig\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"private_addressing\": 0,\n \"advertising_timeout\": 0,\n \"tx_power\": 6,\n \"dfu_service\": 1,\n \"event_service\": 1,\n \"device_info_service\": 1,\n \"eddystone_url\": 1,\n \"eddystone_uid\": 1,\n \"open\": 0,\n \"pairing_mode\": 1,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_NO_MITM\",\n \"partial_flashing\": 1\n }\n }\n },\n \"userConfigs\": [\n {\n \"description\": \"No Pairing Required: Anyone can connect via Bluetooth.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 1,\n \"whitelist\": 0,\n \"security_level\": null\n }\n }\n }\n },\n {\n \"description\": \"JustWorks pairing (default): Pairing is automatic once the pairing is initiated.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 0,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_NO_MITM\"\n }\n }\n }\n },\n {\n \"description\": \"Passkey pairing: Pairing requires 6 digit key to pair.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 0,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_WITH_MITM\"\n }\n }\n }\n }\n ]\n },\n \"partial\": true\n}\n",
2769
+ "pxt.json": "{\n \"name\": \"core\",\n \"description\": \"The microbit core library\",\n \"dependencies\": {},\n \"files\": [\n \"README.md\",\n \"platform.h\",\n \"pxt.cpp\",\n \"pxt.h\",\n \"pxtbase.h\",\n \"pxtcore.h\",\n \"math.ts\",\n \"dal.d.ts\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"pxt-core.d.ts\",\n \"core.cpp\",\n \"pxt-helpers.ts\",\n \"helpers.ts\",\n \"pxt-python.d.ts\",\n \"pxt-python-helpers.ts\",\n \"pinscompat.ts\",\n \"configkeys.h\",\n \"gc.cpp\",\n \"codal.cpp\",\n \"images.cpp\",\n \"basic.cpp\",\n \"basic.ts\",\n \"icons.ts\",\n \"icons.jres\",\n \"input.cpp\",\n \"input.ts\",\n \"gestures.jres\",\n \"control.ts\",\n \"control.cpp\",\n \"controlgc.cpp\",\n \"perfcounters.ts\",\n \"interval.ts\",\n \"gcstats.ts\",\n \"console.ts\",\n \"game.ts\",\n \"led.cpp\",\n \"led.ts\",\n \"music.cpp\",\n \"music.ts\",\n \"melodies.ts\",\n \"pins.cpp\",\n \"pins.ts\",\n \"serial.cpp\",\n \"serial.ts\",\n \"buffer.cpp\",\n \"buffer.ts\",\n \"json.ts\",\n \"poll.ts\",\n \"controlmessage.ts\",\n \"pxtparts.json\",\n \"advmath.cpp\",\n \"trig.cpp\",\n \"fixed.ts\",\n \"templates.ts\",\n \"sendbuffer.s\",\n \"sendbuffernrf52.s\",\n \"sendbufferbrightness.s\",\n \"light.cpp\",\n \"logo.cpp\",\n \"loops.ts\",\n \"touchmode.cpp\",\n \"soundexpressions.ts\",\n \"soundexpressions.cpp\",\n \"parts/speaker.svg\",\n \"parts/headphone.svg\"\n ],\n \"testFiles\": [],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"dalDTS\": {\n \"compileServiceVariant\": \"mbcodal\",\n \"includeDirs\": [\n \"libraries/codal-core/inc\",\n \"libraries/codal-microbit-v2/inc\",\n \"libraries/codal-microbit-v2/model\",\n \"libraries/codal-microbit-v2/inc/compat\",\n \"pxtapp\"\n ],\n \"excludePrefix\": [\n \"USB_\",\n \"REQUEST_\",\n \"LIS3DH_\",\n \"FXOS8700_\",\n \"MMA8\",\n \"LSM303_\",\n \"MAG_\",\n \"MPU6050_\",\n \"REF_TAG_\",\n \"HF2_\",\n \"PXT_REF_TAG_\",\n \"MS_\",\n \"SCSI_\"\n ]\n },\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"fiber_user_data\": 1,\n \"pxt\": 1\n }\n },\n \"optionalConfig\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"private_addressing\": 0,\n \"advertising_timeout\": 0,\n \"tx_power\": 6,\n \"dfu_service\": 1,\n \"event_service\": 1,\n \"device_info_service\": 1,\n \"eddystone_url\": 1,\n \"eddystone_uid\": 1,\n \"open\": 0,\n \"pairing_mode\": 1,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_NO_MITM\",\n \"partial_flashing\": 1\n }\n }\n },\n \"userConfigs\": [\n {\n \"description\": \"No Pairing Required: Anyone can connect via Bluetooth.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 1,\n \"whitelist\": 0,\n \"security_level\": null\n }\n }\n }\n },\n {\n \"description\": \"JustWorks pairing (default): Pairing is automatic once the pairing is initiated.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 0,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_NO_MITM\"\n }\n }\n }\n },\n {\n \"description\": \"Passkey pairing: Pairing requires 6 digit key to pair.\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"open\": 0,\n \"whitelist\": 1,\n \"security_level\": \"SECURITY_MODE_ENCRYPTION_WITH_MITM\"\n }\n }\n }\n }\n ]\n },\n \"partial\": true\n}\n",
2770
2770
  "pxtbase.h": "#ifndef __PXTBASE_H\n#define __PXTBASE_H\n\n#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n#pragma GCC diagnostic ignored \"-Wformat\"\n#pragma GCC diagnostic ignored \"-Warray-bounds\"\n\n// needed for gcc6; not sure why\n#undef min\n#undef max\n\n#define NOLOG(...) \\\n do { \\\n } while (0)\n\n#define MEMDBG NOLOG\n//#define MEMDBG DMESG\n#define MEMDBG2 NOLOG\n\n#include \"pxtconfig.h\"\n#include \"configkeys.h\"\n\n#ifndef PXT_UTF8\n#define PXT_UTF8 0\n#endif\n\n#if defined(PXT_VM)\n#include <stdint.h>\n#if UINTPTR_MAX == 0xffffffff\n#define PXT32 1\n#elif UINTPTR_MAX == 0xffffffffffffffff\n#define PXT64 1\n#else\n#error \"UINTPTR_MAX has invalid value\"\n#endif\n#endif\n\n#define intcheck(...) check(__VA_ARGS__)\n//#define intcheck(...) do {} while (0)\n\n#ifdef PXT_USE_FLOAT\n#define NUMBER float\n#else\n#define NUMBER double\n#endif\n\n#include <string.h>\n#include <stdint.h>\n#include <math.h>\n\n#ifdef POKY\nvoid *operator new(size_t size, void *ptr);\nvoid *operator new(size_t size);\n#else\n#include <new>\n#endif\n\n#include \"platform.h\"\n#include \"pxtcore.h\"\n\n#ifndef PXT_REGISTER_RESET\n#define PXT_REGISTER_RESET(fn) ((void)0)\n#endif\n\n#define PXT_REFCNT_FLASH 0xfffe\n\n#define CONCAT_1(a, b) a##b\n#define CONCAT_0(a, b) CONCAT_1(a, b)\n// already provided in some platforms, like mbedos\n#ifndef STATIC_ASSERT\n#define STATIC_ASSERT(e) enum { CONCAT_0(_static_assert_, __LINE__) = 1 / ((e) ? 1 : 0) };\n#endif\n\n#ifndef ramint_t\n// this type limits size of arrays\n#if defined(__linux__) || defined(PXT_VM)\n// TODO fix the inline array accesses to take note of this!\n#define ramint_t uint32_t\n#else\n#define ramint_t uint16_t\n#endif\n#endif\n\n#ifndef PXT_IN_ISR\n#define PXT_IN_ISR() (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)\n#endif\n\n#ifdef POKY\ninline void *operator new(size_t, void *p) {\n return p;\n}\ninline void *operator new[](size_t, void *p) {\n return p;\n}\n#endif\n\nnamespace pxt {\n\ntemplate <typename T> inline const T &max(const T &a, const T &b) {\n if (a < b)\n return b;\n return a;\n}\n\ntemplate <typename T> inline const T &min(const T &a, const T &b) {\n if (a < b)\n return a;\n return b;\n}\n\ntemplate <typename T> inline void swap(T &a, T &b) {\n T tmp = a;\n a = b;\n b = tmp;\n}\n\n//\n// Tagged values (assume 4 bytes for now, Cortex-M0)\n//\nstruct TValueStruct {};\ntypedef TValueStruct *TValue;\n\ntypedef TValue TNumber;\ntypedef TValue Action;\ntypedef TValue ImageLiteral;\n\n// To be implemented by the target\nextern \"C\" void target_panic(int error_code);\nextern \"C\" void target_reset();\nvoid sleep_ms(unsigned ms);\nvoid sleep_us(uint64_t us);\nvoid releaseFiber();\nuint64_t current_time_us();\nint current_time_ms();\nvoid initRuntime();\nvoid initSystemTimer();\nvoid sendSerial(const char *data, int len);\nvoid setSendToUART(void (*f)(const char *, int));\nuint64_t getLongSerialNumber();\nvoid registerWithDal(int id, int event, Action a, int flags = 16); // EVENT_LISTENER_DEFAULT_FLAGS\nvoid runInParallel(Action a);\nvoid runForever(Action a);\nvoid waitForEvent(int id, int event);\n//%\nunsigned afterProgramPage();\n//%\nvoid dumpDmesg();\nuint32_t hash_fnv1(const void *data, unsigned len);\n\n// also defined DMESG macro\n// end\n\n#define TAGGED_SPECIAL(n) (TValue)(void *)((n << 2) | 2)\n#define TAG_FALSE TAGGED_SPECIAL(2) // 10\n#define TAG_TRUE TAGGED_SPECIAL(16) // 66\n#define TAG_UNDEFINED (TValue)0\n#define TAG_NULL TAGGED_SPECIAL(1) // 6\n#define TAG_NAN TAGGED_SPECIAL(3) // 14\n#define TAG_NUMBER(n) (TNumber)(void *)(((uintptr_t)(uint32_t)(n) << 1) | 1)\n#define TAG_NON_VALUE TAGGED_SPECIAL(4) // 18; doesn't represent any JS value\n\n#ifdef PXT_VM\ninline bool isEncodedDouble(uint64_t v) {\n return (v >> 48) != 0;\n}\n#endif\n\ninline bool isDouble(TValue v) {\n#ifdef PXT64\n return ((uintptr_t)v >> 48) != 0;\n#else\n (void)v;\n return false;\n#endif\n}\n\ninline bool isPointer(TValue v) {\n return !isDouble(v) && v != 0 && ((intptr_t)v & 3) == 0;\n}\n\ninline bool isTagged(TValue v) {\n return (!isDouble(v) && ((intptr_t)v & 3)) || !v;\n}\n\ninline bool isInt(TValue v) {\n return !isDouble(v) && ((intptr_t)v & 1);\n}\n\ninline bool isSpecial(TValue v) {\n return !isDouble(v) && ((intptr_t)v & 2);\n}\n\ninline bool bothNumbers(TValue a, TValue b) {\n return !isDouble(a) && !isDouble(b) && ((intptr_t)a & (intptr_t)b & 1);\n}\n\ninline int numValue(TValue n) {\n return (int)((intptr_t)n >> 1);\n}\n\ninline bool canBeTagged(int v) {\n (void)v;\n#ifdef PXT_BOX_DEBUG\n return false;\n#elif defined(PXT64)\n return true;\n#else\n return (v << 1) >> 1 == v;\n#endif\n}\n\n// see https://anniecherkaev.com/the-secret-life-of-nan\n\n#define NanBoxingOffset 0x1000000000000LL\n\ntemplate <typename TO, typename FROM> TO bitwise_cast(FROM in) {\n STATIC_ASSERT(sizeof(TO) == sizeof(FROM));\n union {\n FROM from;\n TO to;\n } u;\n u.from = in;\n return u.to;\n}\n\ninline double decodeDouble(uint64_t v) {\n return bitwise_cast<double>(v - NanBoxingOffset);\n}\n\n#ifdef PXT64\nSTATIC_ASSERT(sizeof(void *) == 8);\ninline double doubleVal(TValue v) {\n return bitwise_cast<double>((uint64_t)v - NanBoxingOffset);\n}\n\ninline TValue tvalueFromDouble(double d) {\n return (TValue)(bitwise_cast<uint64_t>(d) + NanBoxingOffset);\n}\n#else\nSTATIC_ASSERT(sizeof(void *) == 4);\n#endif\n\n// keep in sym with sim/control.ts\ntypedef enum {\n PANIC_CODAL_OOM = 20,\n PANIC_GC_OOM = 21,\n PANIC_GC_TOO_BIG_ALLOCATION = 22,\n PANIC_CODAL_HEAP_ERROR = 30,\n PANIC_CODAL_NULL_DEREFERENCE = 40,\n PANIC_CODAL_USB_ERROR = 50,\n PANIC_CODAL_HARDWARE_CONFIGURATION_ERROR = 90,\n\n PANIC_INVALID_BINARY_HEADER = 901,\n PANIC_OUT_OF_BOUNDS = 902,\n PANIC_REF_DELETED = 903,\n PANIC_SIZE = 904,\n PANIC_INVALID_VTABLE = 905,\n PANIC_INTERNAL_ERROR = 906,\n PANIC_NO_SUCH_CONFIG = 907,\n PANIC_NO_SUCH_PIN = 908,\n PANIC_INVALID_ARGUMENT = 909,\n PANIC_MEMORY_LIMIT_EXCEEDED = 910,\n PANIC_SCREEN_ERROR = 911,\n PANIC_MISSING_PROPERTY = 912,\n PANIC_INVALID_IMAGE = 913,\n PANIC_CALLED_FROM_ISR = 914,\n PANIC_HEAP_DUMPED = 915,\n PANIC_STACK_OVERFLOW = 916,\n PANIC_BLOCKING_TO_STRING = 917,\n PANIC_VM_ERROR = 918,\n PANIC_SETTINGS_CLEARED = 920,\n PANIC_SETTINGS_OVERLOAD = 921,\n PANIC_SETTINGS_SECRET_MISSING = 922,\n PANIC_DELETE_ON_CLASS = 923,\n PANIC_OUT_OF_TIMERS = 924,\n PANIC_JACDAC = 925,\n PANIC_MICROPHONE_MISSING = 926,\n PANIC_VARIANT_NOT_SUPPORTED = 927,\n\n PANIC_CAST_FIRST = 980,\n PANIC_CAST_FROM_UNDEFINED = 980,\n PANIC_CAST_FROM_BOOLEAN = 981,\n PANIC_CAST_FROM_NUMBER = 982,\n PANIC_CAST_FROM_STRING = 983,\n PANIC_CAST_FROM_OBJECT = 984,\n PANIC_CAST_FROM_FUNCTION = 985,\n PANIC_CAST_FROM_NULL = 989,\n\n PANIC_UNHANDLED_EXCEPTION = 999,\n\n} PXT_PANIC;\n\nextern const uintptr_t functionsAndBytecode[];\nextern TValue *globals;\nextern uint16_t *bytecode;\nclass RefRecord;\n\n// Utility functions\n\ntypedef TValue (*RunActionType)(Action a, TValue arg0, TValue arg1, TValue arg2);\n\n#define asmRunAction3 ((RunActionType)(((uintptr_t *)bytecode)[12]))\n\nstatic inline TValue runAction3(Action a, TValue arg0, TValue arg1, TValue arg2) {\n return asmRunAction3(a, arg0, arg1, 0);\n}\nstatic inline TValue runAction2(Action a, TValue arg0, TValue arg1) {\n return asmRunAction3(a, arg0, arg1, 0);\n}\nstatic inline TValue runAction1(Action a, TValue arg0) {\n return asmRunAction3(a, arg0, 0, 0);\n}\nstatic inline TValue runAction0(Action a) {\n return asmRunAction3(a, 0, 0, 0);\n}\n\nclass RefAction;\nclass BoxedString;\nstruct VTable;\n\n//%\nAction mkAction(int totallen, RefAction *act);\n//% expose\nint templateHash();\n//% expose\nint programHash();\n//% expose\nBoxedString *programName();\n//% expose\nunsigned programSize();\n//%\nint getNumGlobals();\n//%\nRefRecord *mkClassInstance(VTable *vt);\n//%\nvoid debugMemLeaks();\n//%\nvoid anyPrint(TValue v);\n\n//%\nint getConfig(int key, int defl = -1);\n\n//%\nint toInt(TNumber v);\n//%\nunsigned toUInt(TNumber v);\n//%\nNUMBER toDouble(TNumber v);\n//%\nfloat toFloat(TNumber v);\n//%\nTNumber fromDouble(NUMBER r);\n//%\nTNumber fromFloat(float r);\n\n//%\nTNumber fromInt(int v);\n//%\nTNumber fromUInt(unsigned v);\n//%\nTValue fromBool(bool v);\n//%\nbool eq_bool(TValue a, TValue b);\n//%\nbool eqq_bool(TValue a, TValue b);\n\n//%\nvoid failedCast(TValue v, void *addr = NULL);\n//%\nvoid missingProperty(TValue v);\n\nvoid error(PXT_PANIC code, int subcode = 0);\nvoid exec_binary(unsigned *pc);\nvoid start();\n\nstruct HandlerBinding {\n HandlerBinding *next;\n int source;\n int value;\n Action action;\n#ifndef PXT_CODAL\n uint32_t flags;\n struct Event *pending;\n#endif\n};\nHandlerBinding *findBinding(int source, int value);\nHandlerBinding *nextBinding(HandlerBinding *curr, int source, int value);\nvoid setBinding(int source, int value, Action act);\n\n// Legacy stuff; should no longer be used\n//%\nTValue incr(TValue e);\n//%\nvoid decr(TValue e);\n\ninline TValue incr(TValue e) {\n return e;\n}\ninline void decr(TValue e) {}\n\nclass RefObject;\n\nstatic inline RefObject *incrRC(RefObject *r) {\n return r;\n}\nstatic inline void decrRC(RefObject *) {}\n\ninline void *ptrOfLiteral(int offset) {\n return &bytecode[offset];\n}\n\n// Checks if object is ref-counted, and has a custom PXT vtable in front\n// TODO\ninline bool isRefCounted(TValue e) {\n return isPointer(e);\n}\n\ninline void check(int cond, PXT_PANIC code, int subcode = 0) {\n if (!cond)\n error(code, subcode);\n}\n\ninline void oops(int subcode = 0) {\n target_panic(800 + subcode);\n}\n\nclass RefObject;\n\ntypedef void (*RefObjectMethod)(RefObject *self);\ntypedef unsigned (*RefObjectSizeMethod)(RefObject *self);\ntypedef void *PVoid;\ntypedef void **PPVoid;\n\ntypedef void *Object_;\n\n#define VTABLE_MAGIC 0xF9\n#define VTABLE_MAGIC2 0xF8\n\nenum class ValType : uint8_t {\n Undefined,\n Boolean,\n Number,\n String,\n Object,\n Function,\n};\n\n// keep in sync with pxt-core (search for the type name)\nenum class BuiltInType : uint16_t {\n BoxedString = 1,\n BoxedNumber = 2,\n BoxedBuffer = 3,\n RefAction = 4,\n RefImage = 5,\n RefCollection = 6,\n RefRefLocal = 7,\n RefMap = 8,\n RefMImage = 9, // microbit-specific\n MMap = 10, // linux, mostly ev3\n BoxedString_SkipList = 11, // used by VM bytecode representation only\n BoxedString_ASCII = 12, // ditto\n ZPin = 13,\n User0 = 16,\n};\n\nstruct VTable {\n uint16_t numbytes;\n ValType objectType;\n uint8_t magic;\n#ifdef PXT_VM\n uint16_t ifaceHashEntries;\n BuiltInType lastClassNo;\n#else\n PVoid *ifaceTable;\n#endif\n BuiltInType classNo;\n uint16_t reserved;\n uint32_t ifaceHashMult;\n\n // we only use the first few methods here; pxt will generate more\n PVoid methods[8];\n};\n\n//%\nextern const VTable string_inline_ascii_vt;\n#if PXT_UTF8\n//%\nextern const VTable string_inline_utf8_vt;\n//%\nextern const VTable string_cons_vt;\n//%\nextern const VTable string_skiplist16_vt;\n//%\nextern const VTable string_skiplist16_packed_vt;\n#endif\n//%\nextern const VTable buffer_vt;\n//%\nextern const VTable number_vt;\n//%\nextern const VTable RefAction_vtable;\n\n#ifndef PXT_IS_READONLY\n// assume ARM - ram addresses are 0x2000_0000+; flash is either 0x0+ or 0x0800_0000+\n#define PXT_IS_READONLY(v) (isTagged(v) || !((uintptr_t)v >> 28))\n#endif\n\ninline bool isReadOnly(TValue v) {\n return PXT_IS_READONLY(v);\n}\n\n// A base abstract class for ref-counted objects.\nclass RefObject {\n public:\n const VTable *vtable;\n\n RefObject(const VTable *vt) {\n#if defined(PXT32) && defined(PXT_VM) && !defined(PXT_ESP32)\n if ((uint32_t)vt & 0xf0000000)\n target_panic(PANIC_INVALID_VTABLE);\n#endif\n vtable = vt;\n }\n\n void destroyVT();\n void printVT();\n\n inline uintptr_t vt() { return (uintptr_t)vtable; }\n inline void setVT(uintptr_t v) { vtable = (const VTable *)v; }\n\n inline void ref() {}\n inline void unref() {}\n inline bool isReadOnly() { return pxt::isReadOnly((TValue)this); }\n};\n\nclass Segment {\n private:\n TValue *data;\n ramint_t length;\n ramint_t size;\n\n // this just gives max value of ramint_t\n void growByMin(ramint_t minSize);\n void ensure(ramint_t newSize);\n\n public:\n static constexpr ramint_t MaxSize = (((1U << (8 * sizeof(ramint_t) - 1)) - 1) << 1) + 1;\n static constexpr TValue DefaultValue = TAG_UNDEFINED; // == NULL\n\n Segment() : data(nullptr), length(0), size(0) {}\n\n TValue get(unsigned i) { return i < length ? data[i] : NULL; }\n void set(unsigned i, TValue value);\n\n unsigned getLength() { return length; };\n void setLength(unsigned newLength);\n\n void push(TValue value) { set(length, value); }\n TValue pop();\n\n TValue remove(unsigned i);\n void insert(unsigned i, TValue value);\n\n void destroy();\n\n void print();\n\n TValue *getData() { return data; }\n};\n\n// Low-Level segment using system malloc\nclass LLSegment {\n private:\n TValue *data;\n ramint_t length;\n ramint_t size;\n\n public:\n LLSegment() : data(nullptr), length(0), size(0) {}\n\n void set(unsigned idx, TValue v);\n void push(TValue value) { set(length, value); }\n TValue pop();\n void destroy();\n void setLength(unsigned newLen);\n\n TValue get(unsigned i) { return i < length ? data[i] : NULL; }\n unsigned getLength() { return length; };\n TValue *getData() { return data; }\n};\n\n// A ref-counted collection of either primitive or ref-counted objects (String, Image,\n// user-defined record, another collection)\nclass RefCollection : public RefObject {\n public:\n Segment head;\n\n RefCollection();\n\n static void destroy(RefCollection *coll);\n static void scan(RefCollection *coll);\n static unsigned gcsize(RefCollection *coll);\n static void print(RefCollection *coll);\n\n unsigned length() { return head.getLength(); }\n void setLength(unsigned newLength) { head.setLength(newLength); }\n TValue getAt(int i) { return head.get(i); }\n TValue *getData() { return head.getData(); }\n};\n\nclass RefMap : public RefObject {\n public:\n Segment keys;\n Segment values;\n\n RefMap();\n static void destroy(RefMap *map);\n static void scan(RefMap *map);\n static unsigned gcsize(RefMap *coll);\n static void print(RefMap *map);\n int findIdx(BoxedString *key);\n};\n\n// A ref-counted, user-defined JS object.\nclass RefRecord : public RefObject {\n public:\n // The object is allocated, so that there is space at the end for the fields.\n TValue fields[];\n\n RefRecord(VTable *v) : RefObject(v) {}\n\n TValue ld(int idx);\n TValue ldref(int idx);\n void st(int idx, TValue v);\n void stref(int idx, TValue v);\n};\n\nstatic inline VTable *getVTable(RefObject *r) {\n return (VTable *)(r->vt() & ~1);\n}\n\nstatic inline VTable *getAnyVTable(TValue v) {\n if (!isRefCounted(v))\n return NULL;\n auto vt = getVTable((RefObject *)v);\n if (vt->magic == VTABLE_MAGIC)\n return vt;\n return NULL;\n}\n\n// these are needed when constructing vtables for user-defined classes\n//%\nvoid RefRecord_destroy(RefRecord *r);\n//%\nvoid RefRecord_print(RefRecord *r);\n//%\nvoid RefRecord_scan(RefRecord *r);\n//%\nunsigned RefRecord_gcsize(RefRecord *r);\n\ntypedef TValue (*ActionCB)(TValue *captured, TValue arg0, TValue arg1, TValue arg2);\n\n// Ref-counted function pointer.\nclass RefAction : public RefObject {\n public:\n uint16_t len;\n uint16_t numArgs;\n#ifdef PXT_VM\n uint16_t initialLen;\n uint16_t flags;\n uintptr_t func;\n#else\n ActionCB func; // The function pointer\n#endif\n // fields[] contain captured locals\n TValue fields[];\n\n static void destroy(RefAction *act);\n static void scan(RefAction *act);\n static unsigned gcsize(RefAction *coll);\n static void print(RefAction *act);\n\n RefAction();\n\n inline void stCore(int idx, TValue v) {\n // DMESG(\"ST [%d] = %d \", idx, v); this->print();\n intcheck(0 <= idx && idx < len, PANIC_OUT_OF_BOUNDS, 10);\n intcheck(fields[idx] == 0, PANIC_OUT_OF_BOUNDS, 11); // only one assignment permitted\n fields[idx] = v;\n }\n};\n\n// These two are used to represent locals written from inside inline functions\nclass RefRefLocal : public RefObject {\n public:\n TValue v;\n static void destroy(RefRefLocal *l);\n static void scan(RefRefLocal *l);\n static unsigned gcsize(RefRefLocal *l);\n static void print(RefRefLocal *l);\n RefRefLocal();\n};\n\ntypedef int color;\n\n// note: this is hardcoded in PXT (hexfile.ts)\n\nclass BoxedNumber : public RefObject {\n public:\n NUMBER num;\n BoxedNumber() : RefObject(&number_vt) {}\n} __attribute__((packed));\n\nclass BoxedString : public RefObject {\n public:\n union {\n struct {\n uint16_t length; // ==size\n char data[0];\n } ascii;\n#if PXT_UTF8\n struct {\n uint16_t size;\n char data[0];\n } utf8;\n struct {\n BoxedString *left;\n BoxedString *right;\n } cons;\n struct {\n uint16_t size; // in bytes\n uint16_t length; // in characters\n uint16_t *list;\n } skip;\n struct {\n uint16_t size; // in bytes\n uint16_t length; // in characters\n uint16_t list[0];\n } skip_pack;\n#endif\n };\n\n#if PXT_UTF8\n uintptr_t runMethod(int idx) {\n return ((uintptr_t(*)(BoxedString *))vtable->methods[idx])(this);\n }\n const char *getUTF8Data() { return (const char *)runMethod(4); }\n uint32_t getUTF8Size() { return (uint32_t)runMethod(5); }\n // in characters\n uint32_t getLength() { return (uint32_t)runMethod(6); }\n const char *getUTF8DataAt(uint32_t pos) {\n auto meth = ((const char *(*)(BoxedString *, uint32_t))vtable->methods[7]);\n return meth(this, pos);\n }\n#else\n const char *getUTF8Data() { return ascii.data; }\n uint32_t getUTF8Size() { return ascii.length; }\n uint32_t getLength() { return ascii.length; }\n const char *getUTF8DataAt(uint32_t pos) { return pos < ascii.length ? ascii.data + pos : NULL; }\n#endif\n\n TNumber charCodeAt(int pos);\n\n BoxedString(const VTable *vt) : RefObject(vt) {}\n};\n\n// cross version compatible way of accessing string data\n#ifndef PXT_STRING_DATA\n#define PXT_STRING_DATA(str) str->getUTF8Data()\n#endif\n\n// cross version compatible way of accessing string length\n#ifndef PXT_STRING_DATA_LENGTH\n#define PXT_STRING_DATA_LENGTH(str) str->getUTF8Size()\n#endif\n\nclass BoxedBuffer : public RefObject {\n public:\n // data needs to be word-aligned, so we use 32 bits for length\n int length;\n uint8_t data[0];\n BoxedBuffer() : RefObject(&buffer_vt) {}\n\n static bool isInstance(TValue v);\n};\n\n// cross version compatible way of access data field\n#ifndef PXT_BUFFER_DATA\n#define PXT_BUFFER_DATA(buffer) buffer->data\n#endif\n\n// cross version compatible way of access data length\n#ifndef PXT_BUFFER_LENGTH\n#define PXT_BUFFER_LENGTH(buffer) buffer->length\n#endif\n\n#ifndef PXT_CREATE_BUFFER\n#define PXT_CREATE_BUFFER(data, len) pxt::mkBuffer(data, len)\n#endif\n\n// Legacy format:\n// the first byte of data indicates the format - currently 0xE1 or 0xE4 to 1 or 4 bit bitmaps\n// second byte indicates width in pixels\n// third byte indicates the height (which should also match the size of the buffer)\n// just like ordinary buffers, these can be layed out in flash\n\n// Current format:\n// 87 BB WW WW HH HH 00 00 DATA\n// that is: 0x87, 0x01 or 0x04 - bpp, width in little endian, height, 0x00, 0x00 followed by data\n// for 4 bpp images, rows are word-aligned (as in legacy)\n\n#define IMAGE_HEADER_MAGIC 0x87\n\nstruct ImageHeader {\n uint8_t magic;\n uint8_t bpp;\n uint16_t width;\n uint16_t height;\n uint16_t padding;\n uint8_t pixels[0];\n};\n\nclass RefImage : public RefObject {\n public:\n BoxedBuffer *buffer;\n uint32_t revision;\n\n RefImage(BoxedBuffer *buf);\n RefImage(uint32_t sz);\n\n void setBuffer(BoxedBuffer *b);\n\n uint8_t *data() { return buffer->data; }\n int length() { return (int)buffer->length; }\n\n ImageHeader *header() { return (ImageHeader *)buffer->data; }\n int pixLength() { return length() - sizeof(ImageHeader); }\n\n int width() { return header()->width; }\n int height() { return header()->height; }\n int wordHeight();\n int bpp() { return header()->bpp; }\n\n bool hasPadding() { return (height() & 0x7) != 0; }\n\n uint8_t *pix() { return header()->pixels; }\n\n int byteHeight() {\n if (bpp() == 1)\n return (height() + 7) >> 3;\n else if (bpp() == 4)\n return ((height() * 4 + 31) >> 5) << 2;\n else {\n oops(21);\n return -1;\n }\n }\n\n uint8_t *pix(int x, int y) {\n uint8_t *d = &pix()[byteHeight() * x];\n if (y) {\n if (bpp() == 1)\n d += y >> 3;\n else if (bpp() == 4)\n d += y >> 1;\n }\n return d;\n }\n\n uint8_t fillMask(color c);\n bool inRange(int x, int y);\n void clamp(int *x, int *y);\n void makeWritable();\n\n static void destroy(RefImage *t);\n static void scan(RefImage *t);\n static unsigned gcsize(RefImage *t);\n static void print(RefImage *t);\n};\n\nRefImage *mkImage(int w, int h, int bpp);\n\ntypedef BoxedBuffer *Buffer;\ntypedef BoxedString *String;\ntypedef RefImage *Image_;\n\nuint32_t toRealUTF8(String str, uint8_t *dst);\n\n// keep in sync with github/pxt/pxtsim/libgeneric.ts\nenum class NumberFormat {\n Int8LE = 1,\n UInt8LE,\n Int16LE,\n UInt16LE,\n Int32LE,\n Int8BE,\n UInt8BE,\n Int16BE,\n UInt16BE,\n Int32BE,\n\n UInt32LE,\n UInt32BE,\n Float32LE,\n Float64LE,\n Float32BE,\n Float64BE,\n};\n\n// this will, unlike mkStringCore, UTF8-canonicalize the data\nString mkString(const char *data, int len = -1);\n// data can be NULL in both cases\nBuffer mkBuffer(const void *data, int len);\nString mkStringCore(const char *data, int len = -1);\n\nTNumber getNumberCore(uint8_t *buf, int size, NumberFormat format);\nvoid setNumberCore(uint8_t *buf, int size, NumberFormat format, TNumber value);\n\nvoid seedRandom(unsigned seed);\nvoid seedAddRandom(unsigned seed);\n// max is inclusive\nunsigned getRandom(unsigned max);\n\nValType valType(TValue v);\n\n// this is equivalent to JS `throw v`; it will leave\n// the current function(s), all the way until the nearest try block and\n// ignore all destructors (think longjmp())\nvoid throwValue(TValue v);\n\nvoid registerGC(TValue *root, int numwords = 1);\nvoid unregisterGC(TValue *root, int numwords = 1);\nvoid registerGCPtr(TValue ptr);\nvoid unregisterGCPtr(TValue ptr);\nstatic inline void registerGCObj(RefObject *ptr) {\n registerGCPtr((TValue)ptr);\n}\nstatic inline void unregisterGCObj(RefObject *ptr) {\n unregisterGCPtr((TValue)ptr);\n}\nvoid gc(int flags);\n\nstruct StackSegment {\n void *top;\n void *bottom;\n StackSegment *next;\n};\n\n#define NUM_TRY_FRAME_REGS 3\nstruct TryFrame {\n TryFrame *parent;\n uintptr_t registers[NUM_TRY_FRAME_REGS];\n};\n\nstruct ThreadContext {\n TValue *globals;\n StackSegment stack;\n TryFrame *tryFrame;\n TValue thrownValue;\n#ifdef PXT_GC_THREAD_LIST\n ThreadContext *next;\n ThreadContext *prev;\n#endif\n};\n\n#ifdef PXT_GC_THREAD_LIST\nextern ThreadContext *threadContexts;\nvoid *threadAddressFor(ThreadContext *, void *sp);\n#endif\n\nvoid releaseThreadContext(ThreadContext *ctx);\nThreadContext *getThreadContext();\nvoid setThreadContext(ThreadContext *ctx);\n\n#ifndef PXT_GC_THREAD_LIST\nvoid gcProcessStacks(int flags);\n#endif\n\nvoid gcProcess(TValue v);\nvoid gcFreeze();\n\n#ifdef PXT_VM\nvoid gcStartup();\nvoid gcPreStartup();\n#endif\n\nvoid coreReset();\nvoid gcReset();\nvoid systemReset();\n\nvoid doNothing();\n\nvoid *gcAllocate(int numbytes);\nvoid *gcAllocateArray(int numbytes);\nextern \"C\" void *app_alloc(int numbytes);\nextern \"C\" void *app_free(void *ptr);\nextern \"C\" void *app_alloc_at(void *at, int numbytes);\nvoid gcPreAllocateBlock(uint32_t sz);\n\nint redirectSamples(int16_t *dst, int numsamples, int samplerate);\n\n#ifdef PXT64\n#define TOWORDS(bytes) (((bytes) + 7) >> 3)\n#else\n#define TOWORDS(bytes) (((bytes) + 3) >> 2)\n#endif\n\n#ifndef PXT_VM\n#define soft_panic target_panic\n#endif\n\nextern int debugFlags;\n\nenum class PerfCounters {\n GC,\n};\n\n#ifdef PXT_PROFILE\n#ifndef PERF_NOW\n#error \"missing platform timer support\"\n#endif\n\nstruct PerfCounter {\n uint32_t value;\n uint32_t numstops;\n uint32_t start;\n};\n\nextern struct PerfCounter *perfCounters;\n\nvoid initPerfCounters();\n//%\nvoid dumpPerfCounters();\n//%\nvoid startPerfCounter(PerfCounters n);\n//%\nvoid stopPerfCounter(PerfCounters n);\n#else\ninline void startPerfCounter(PerfCounters n) {}\ninline void stopPerfCounter(PerfCounters n) {}\ninline void initPerfCounters() {}\ninline void dumpPerfCounters() {}\n#endif\n\n// Handling of built-in string literals (like \"[Object]\", \"true\" etc.).\n\n// This has the same layout as BoxedString, but has statically allocated buffer\ntemplate <size_t N> struct BoxedStringLayout {\n const void *vtable;\n uint16_t size;\n const char data[N];\n};\n\ntemplate <size_t N> constexpr size_t _boxedStringLen(char const (&)[N]) {\n return N;\n}\n\n// strings defined here as used as (String)name\n#define PXT_DEF_STRING(name, val) \\\n const BoxedStringLayout<_boxedStringLen(val)> name[1] = { \\\n {&pxt::string_inline_ascii_vt, _boxedStringLen(val) - 1, val}};\n\n// bigger value - less memory, but slower\n// 16/20 keeps s.length and s.charCodeAt(i) at about 200 cycles (for actual unicode strings),\n// which is similar to amortized allocation time\n#define PXT_STRING_SKIP_INCR 16 // needs to be power of 2; needs to be kept in sync with compiler\n#define PXT_STRING_MIN_SKIP \\\n 20 // min. size of string to use skip list; static code has its own limit\n\n#define PXT_NUM_SKIP_ENTRIES(p) ((p)->skip.length / PXT_STRING_SKIP_INCR)\n#define PXT_SKIP_DATA_IND(p) ((const char *)(p->skip.list + PXT_NUM_SKIP_ENTRIES(p)))\n#define PXT_SKIP_DATA_PACK(p) ((const char *)(p->skip_pack.list + PXT_NUM_SKIP_ENTRIES(p)))\n\n} // namespace pxt\n\nusing namespace pxt;\n\nnamespace numops {\n//%\nString toString(TValue v);\n//%\nint toBool(TValue v);\n//%\nint toBoolDecr(TValue v);\n} // namespace numops\n\nnamespace pxt {\ninline bool toBoolQuick(TValue v) {\n if (v == TAG_TRUE)\n return true;\n if (v == TAG_FALSE || v == TAG_UNDEFINED || v == TAG_NULL)\n return false;\n return numops::toBool(v);\n}\n} // namespace pxt\n\nnamespace pxtrt {\n//%\nRefMap *mkMap();\n//%\nTValue mapGetByString(RefMap *map, String key);\n//%\nint lookupMapKey(String key);\n//%\nTValue mapGet(RefMap *map, unsigned key);\n//% expose\nvoid mapSetByString(RefMap *map, String key, TValue val);\n//%\nvoid mapSet(RefMap *map, unsigned key, TValue val);\n} // namespace pxtrt\n\nnamespace pins {\nBuffer createBuffer(int size);\n}\n\nnamespace String_ {\n//%\nint compare(String a, String b);\n} // namespace String_\n\nnamespace Array_ {\n//%\nRefCollection *mk();\n//%\nint length(RefCollection *c);\n//%\nvoid setLength(RefCollection *c, int newLength);\n//%\nvoid push(RefCollection *c, TValue x);\n//%\nTValue pop(RefCollection *c);\n//%\nTValue getAt(RefCollection *c, int x);\n//%\nvoid setAt(RefCollection *c, int x, TValue y);\n//%\nTValue removeAt(RefCollection *c, int x);\n//%\nvoid insertAt(RefCollection *c, int x, TValue value);\n//%\nint indexOf(RefCollection *c, TValue x, int start);\n//%\nbool removeElement(RefCollection *c, TValue x);\n} // namespace Array_\n\n#define NEW_GC(T, ...) new (gcAllocate(sizeof(T))) T(__VA_ARGS__)\n\n// The ARM Thumb generator in the JavaScript code is parsing\n// the hex file and looks for the magic numbers as present here.\n//\n// Then it fetches function pointer addresses from there.\n//\n// The vtable pointers are there, so that the ::emptyData for various types\n// can be patched with the right vtable.\n//\n#define PXT_SHIMS_BEGIN \\\n namespace pxt { \\\n const uintptr_t functionsAndBytecode[] \\\n __attribute__((aligned(0x20))) = {0x08010801, 0x42424242, 0x08010801, 0x8de9d83e,\n\n#define PXT_SHIMS_END \\\n } \\\n ; \\\n }\n\n#if !defined(X86_64) && !defined(PXT_VM)\n#pragma GCC diagnostic ignored \"-Wpmf-conversions\"\n#endif\n\n#ifdef PXT_VM\n#define DEF_VTABLE(name, tp, valtype, ...) \\\n const VTable name = {sizeof(tp), valtype, VTABLE_MAGIC, 0, BuiltInType::tp, BuiltInType::tp, \\\n 0, 0, {__VA_ARGS__}};\n#define DEF_VTABLE_EXT(name, tp, valtype, ...) \\\n const VTable name = {sizeof(tp), valtype, VTABLE_MAGIC2, 0, BuiltInType::tp, BuiltInType::tp, \\\n 0, 0, {__VA_ARGS__}};\n#else\n#define DEF_VTABLE(name, tp, valtype, ...) \\\n const VTable name = {sizeof(tp), valtype, VTABLE_MAGIC, 0, BuiltInType::tp, \\\n 0, 0, {__VA_ARGS__}};\n#define DEF_VTABLE_EXT(name, tp, valtype, ...) \\\n const VTable name = {sizeof(tp), valtype, VTABLE_MAGIC2, 0, BuiltInType::tp, \\\n 0, 0, {__VA_ARGS__}};\n#endif\n\n#define PXT_VTABLE(classname, valtp) \\\n DEF_VTABLE(classname##_vtable, classname, valtp, (void *)&classname::destroy, \\\n (void *)&classname::print, (void *)&classname::scan, (void *)&classname::gcsize)\n\n#define PXT_EXT_VTABLE(classname) \\\n static int classname##_gcsize() { return sizeof(classname); } \\\n DEF_VTABLE_EXT(classname##_vtable, classname, ValType::Object, (void *)&pxt::doNothing, \\\n (void *)&pxt::anyPrint, (void *)&pxt::doNothing, (void *)&classname##_gcsize)\n\n#define PXT_VTABLE_INIT(classname) RefObject(&classname##_vtable)\n\n#define PXT_VTABLE_CTOR(classname) \\\n PXT_VTABLE(classname, ValType::Object) \\\n classname::classname() : PXT_VTABLE_INIT(classname)\n\n#define PXT_MAIN \\\n int main() { \\\n pxt::start(); \\\n return 0; \\\n }\n\n#define PXT_FNPTR(x) (uintptr_t)(void *)(x)\n\n#define PXT_ABI(...)\n\n#define JOIN(a, b) a##b\n/// Defines getClassName() function to fetch the singleton\n#define SINGLETON(ClassName) \\\n static ClassName *JOIN(inst, ClassName); \\\n ClassName *JOIN(get, ClassName)() { \\\n if (!JOIN(inst, ClassName)) \\\n JOIN(inst, ClassName) = new ClassName(); \\\n return JOIN(inst, ClassName); \\\n }\n\n/// Defines getClassName() function to fetch the singleton if PIN present\n#define SINGLETON_IF_PIN(ClassName, pin) \\\n static ClassName *JOIN(inst, ClassName); \\\n ClassName *JOIN(get, ClassName)() { \\\n if (!JOIN(inst, ClassName) && LOOKUP_PIN(pin)) \\\n JOIN(inst, ClassName) = new ClassName(); \\\n return JOIN(inst, ClassName); \\\n }\n\n#ifdef PXT_VM\n#include \"vm.h\"\n#endif\n\n#endif\n",
2771
2771
  "pxtcore.h": "#ifndef __PXTCORE_H\n#define __PXTCORE_H\n\n#include \"MicroBit.h\"\n#include \"MicroBitImage.h\"\n#include \"ManagedString.h\"\n#include \"ManagedType.h\"\n\nnamespace pxt {\nvoid debuglog(const char *format, ...);\n}\n\n// #define GC_GET_HEAP_SIZE() device_heap_size(0)\n#define xmalloc malloc\n#define xfree free\n\n#define GC_MAX_ALLOC_SIZE 9000\n\n#define NON_GC_HEAP_RESERVATION 1024\n\n#ifdef CODAL_CONFIG_H\n#define MICROBIT_CODAL 1\n#else\n#define MICROBIT_CODAL 0\n#define GC_BLOCK_SIZE 256\n#endif\n\n#if !MICROBIT_CODAL\n#undef DMESG\n#define DMESG NOLOG\n#endif\n\n#undef BYTES_TO_WORDS\n\n#endif\n",
2772
2772
  "pxtparts.json": "{\n \"buttonpair\": {\n \"simulationBehavior\": \"buttonpair\",\n \"visual\": {\n \"builtIn\": \"buttonpair\",\n \"width\": 75,\n \"height\": 45,\n \"pinDistance\": 15,\n \"pinLocations\": [\n {\n \"x\": 0,\n \"y\": 0\n },\n {\n \"x\": 30,\n \"y\": 45\n },\n {\n \"x\": 45,\n \"y\": 0\n },\n {\n \"x\": 75,\n \"y\": 45\n }\n ]\n },\n \"numberOfPins\": 4,\n \"pinDefinitions\": [\n {\n \"target\": \"P14\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n },\n {\n \"target\": \"P15\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n }\n ],\n \"instantiation\": {\n \"kind\": \"singleton\"\n },\n \"assembly\": [\n {\n \"part\": true\n },\n {\n \"pinIndices\": [\n 0,\n 1\n ]\n },\n {\n \"pinIndices\": [\n 2,\n 3\n ]\n }\n ]\n },\n \"microservo\": {\n \"simulationBehavior\": \"microservo\",\n \"visual\": {\n \"builtIn\": \"microservo\",\n \"width\": 74.85,\n \"height\": 200,\n \"pinDistance\": 10,\n \"pinLocations\": [\n {\n \"x\": 30,\n \"y\": 5\n },\n {\n \"x\": 37,\n \"y\": 5\n },\n {\n \"x\": 45,\n \"y\": 5\n }\n ]\n },\n \"numberOfPins\": 3,\n \"pinDefinitions\": [\n {\n \"target\": {\n \"pinInstantiationIdx\": 0\n },\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n },\n {\n \"target\": \"threeVolt\",\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n }\n ],\n \"instantiations\": [\n {\n \"kind\": \"function\",\n \"fullyQualifiedName\": \"pins.servoWritePin,pins.servoSetPulse,PwmOnlyPin.servoWrite,PwmOnlyPin.servoSetPulse,servos.Servo.setAngle,servos.Servo.run,servos.Servo.setPulse\",\n \"argumentRoles\": [\n {\n \"pinInstantiationIdx\": 0,\n \"partParameter\": \"name\"\n }\n ]\n }\n ],\n \"assembly\": [\n {\n \"part\": true,\n \"pinIndices\": [\n 2\n ]\n },\n {\n \"pinIndices\": [\n 0,\n 1\n ]\n }\n ]\n },\n \"neopixel\": {\n \"simulationBehavior\": \"neopixel\",\n \"visual\": {\n \"builtIn\": \"neopixel\",\n \"width\": 58,\n \"height\": 113,\n \"pinDistance\": 9,\n \"pinLocations\": [\n {\n \"x\": 10,\n \"y\": 0\n },\n {\n \"x\": 19,\n \"y\": 0\n },\n {\n \"x\": 28,\n \"y\": 0\n }\n ]\n },\n \"numberOfPins\": 3,\n \"pinDefinitions\": [\n {\n \"target\": {\n \"pinInstantiationIdx\": 0\n },\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n },\n {\n \"target\": \"threeVolt\",\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"croc\",\n \"orientation\": \"+Z\"\n }\n ],\n \"instantiation\": {\n \"kind\": \"function\",\n \"fullyQualifiedName\": \"neopixel.create\",\n \"argumentRoles\": [\n {\n \"pinInstantiationIdx\": 0,\n \"partParameter\": \"pin\"\n },\n {\n \"partParameter\": \"mode\"\n }\n ]\n },\n \"assembly\": [\n {\n \"part\": true,\n \"pinIndices\": [\n 2\n ]\n },\n {\n \"pinIndices\": [\n 0,\n 1\n ]\n }\n ]\n },\n \"ledmatrix\": {\n \"visual\": {\n \"builtIn\": \"ledmatrix\",\n \"width\": 105,\n \"height\": 105,\n \"pinDistance\": 15,\n \"pinLocations\": [\n {\n \"x\": 0,\n \"y\": 0\n },\n {\n \"x\": 15,\n \"y\": 0\n },\n {\n \"x\": 30,\n \"y\": 0\n },\n {\n \"x\": 45,\n \"y\": 0\n },\n {\n \"x\": 105,\n \"y\": 105\n },\n {\n \"x\": 0,\n \"y\": 105\n },\n {\n \"x\": 15,\n \"y\": 105\n },\n {\n \"x\": 30,\n \"y\": 105\n },\n {\n \"x\": 45,\n \"y\": 105\n },\n {\n \"x\": 60,\n \"y\": 0\n }\n ]\n },\n \"simulationBehavior\": \"ledmatrix\",\n \"numberOfPins\": 10,\n \"instantiation\": {\n \"kind\": \"singleton\"\n },\n \"pinDefinitions\": [\n {\n \"target\": \"P6\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 0\n },\n {\n \"target\": \"P7\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 0\n },\n {\n \"target\": \"P8\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 0\n },\n {\n \"target\": \"P9\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 0\n },\n {\n \"target\": \"P10\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 0\n },\n {\n \"target\": \"P12\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 1\n },\n {\n \"target\": \"P13\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 1\n },\n {\n \"target\": \"P16\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 1\n },\n {\n \"target\": \"P19\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 1\n },\n {\n \"target\": \"P20\",\n \"style\": \"male\",\n \"orientation\": \"-Z\",\n \"colorGroup\": 1\n }\n ],\n \"assembly\": [\n {\n \"part\": true\n },\n {\n \"pinIndices\": [\n 0,\n 1,\n 2,\n 3,\n 4\n ]\n },\n {\n \"pinIndices\": [\n 5,\n 6,\n 7,\n 8,\n 9\n ]\n }\n ]\n },\n \"headphone\": {\n \"numberOfPins\": 2,\n \"visual\": {\n \"image\": \"parts/headphone.svg\",\n \"width\": 142,\n \"height\": 180,\n \"pinDistance\": 20,\n \"pinLocations\": [\n {\n \"x\": 17,\n \"y\": 11\n },\n {\n \"x\": 55,\n \"y\": 50\n }\n ]\n },\n \"pinDefinitions\": [\n {\n \"target\": \"P0\",\n \"style\": \"croc\",\n \"orientation\": \"Y\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"croc\",\n \"orientation\": \"Y\"\n }\n ],\n \"instantiation\": {\n \"kind\": \"singleton\"\n },\n \"assembly\": [\n {\n \"part\": true,\n \"pinIndices\": [\n 0\n ]\n },\n {\n \"pinIndices\": [\n 1\n ]\n }\n ]\n },\n \"speaker\": {\n \"numberOfPins\": 2,\n \"visual\": {\n \"image\": \"parts/speaker.svg\",\n \"width\": 500,\n \"height\": 500,\n \"pinDistance\": 70,\n \"pinLocations\": [\n {\n \"x\": 180,\n \"y\": 135\n },\n {\n \"x\": 320,\n \"y\": 135\n }\n ]\n },\n \"pinDefinitions\": [\n {\n \"target\": \"P0\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n },\n {\n \"target\": \"ground\",\n \"style\": \"male\",\n \"orientation\": \"-Z\"\n }\n ],\n \"instantiation\": {\n \"kind\": \"singleton\"\n },\n \"assembly\": [\n {\n \"part\": true,\n \"pinIndices\": [\n 0\n ]\n },\n {\n \"pinIndices\": [\n 1\n ]\n }\n ]\n }\n}",
@@ -2775,7 +2775,7 @@ var pxtTargetBundle = {
2775
2775
  "sendbuffernrf52.s": ".syntax unified\n\n#ifndef NRF51\n\n// put it in RAM\n.section .data.neopixel_send_buffer_nrf52\n.global neopixel_send_buffer_nrf52\n.thumb\n.type neopixel_send_buffer_nrf52, %function\n\n\n\n\nneopixel_send_buffer_nrf52:\n push {r4,r5,r6,r7,lr}\n \n lsrs r7, r1, #20 // r7 - brightness\n ands r1, #0xff\n movs r4, #1\n lsls r1, r4, r1 // r1 - mask\n\n mov r4, r2 // ptr\n mov r5, r3 // len\n mov r3, r0 // port+0x500\n \n b .start\n.nextbit:\n str r1, [r3, #0x8] // pin := hi\n\n movs r2, #8\n tst r6, r0\n it eq\n movseq r2, #3\n\n.d1:\n subs r2, #1\n bne .d1\n\n str r1, [r3, #0xC] // pin := lo\n\n movs r2, #4\n tst r6, r0\n it eq\n movseq r2, #6\n\n lsrs r6, r6, #1 // r6 >>= 1 \n beq .reload\n\n nop\n nop\n nop\n\n.d0:\n subs r2, #1\n bne .d0\n\n b .nextbit\n\n.reload: \n subs r2, #2 // offset following operations\n.d2:\n subs r2, #1\n bne .d2\n\n // not just a bit - need new byte\n adds r4, #1 // r4++ \n subs r5, #1 // r5-- \n ble .stop // if (r5<=0) goto .stop \n.start:\n movs r6, #0x80 // reset mask\n ldrb r0, [r4, #0] // r0 := *r4 \n muls r0, r7 \n lsrs r0, r0, #8 // r0 >>= 8\n str r1, [r3, #0xC] // pin := lo \n b .nextbit //\n\n.stop: \n str r1, [r3, #0xC] // pin := lo\n\n pop {r4,r5,r6,r7,pc}\n\n#endif\n",
2776
2776
  "serial.cpp": "#include \"pxt.h\"\n\n#define MICROBIT_SERIAL_READ_BUFFER_LENGTH 64\n\n// make sure USB_TX and USB_RX don't overlap with other pin ids\n// also, 1001,1002 need to be kept in sync with getPin() function\nenum SerialPin {\n P0 = MICROBIT_ID_IO_P0,\n P1 = MICROBIT_ID_IO_P1,\n P2 = MICROBIT_ID_IO_P2,\n P8 = MICROBIT_ID_IO_P8,\n P12 = MICROBIT_ID_IO_P12,\n P13 = MICROBIT_ID_IO_P13,\n P14 = MICROBIT_ID_IO_P14,\n P15 = MICROBIT_ID_IO_P15,\n P16 = MICROBIT_ID_IO_P16,\n USB_TX = 1001,\n USB_RX = 1002\n};\n\nenum BaudRate {\n //% block=115200\n BaudRate115200 = 115200,\n //% block=57600\n BaudRate57600 = 57600,\n //% block=38400\n BaudRate38400 = 38400,\n //% block=31250\n BaudRate31250 = 31250,\n //% block=28800\n BaudRate28800 = 28800,\n //% block=19200\n BaudRate19200 = 19200,\n //% block=14400\n BaudRate14400 = 14400,\n //% block=9600\n BaudRate9600 = 9600,\n //% block=4800\n BaudRate4800 = 4800,\n //% block=2400\n BaudRate2400 = 2400,\n //% block=1200\n BaudRate1200 = 1200\n};\n\n//% weight=2 color=#002050 icon=\"\\uf287\"\n//% advanced=true\nnamespace serial {\n // note that at least one // followed by % is needed per declaration!\n\n /**\n * Read a line of text from the serial port and return the buffer when the delimiter is met.\n * @param delimiter text delimiter that separates each text chunk\n */\n //% help=serial/read-until\n //% blockId=serial_read_until block=\"serial|read until %delimiter=serial_delimiter_conv\"\n //% weight=19\n String readUntil(String delimiter) {\n return PSTR(uBit.serial.readUntil(MSTR(delimiter)));\n }\n\n /**\n * Read the buffered received data as a string\n */\n //% help=serial/read-string\n //% blockId=serial_read_buffer block=\"serial|read string\"\n //% weight=18\n String readString() {\n int n = uBit.serial.getRxBufferSize();\n if (n == 0) return mkString(\"\", 0);\n return PSTR(uBit.serial.read(n, MicroBitSerialMode::ASYNC));\n }\n\n /**\n * Register an event to be fired when one of the delimiter is matched.\n * @param delimiters the characters to match received characters against.\n */\n //% help=serial/on-data-received\n //% weight=18 blockId=serial_on_data_received block=\"serial|on data received %delimiters=serial_delimiter_conv\"\n void onDataReceived(String delimiters, Action body) {\n uBit.serial.eventOn(MSTR(delimiters));\n registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body);\n // lazy initialization of serial buffers\n uBit.serial.read(MicroBitSerialMode::ASYNC);\n }\n\n /**\n * Send a piece of text through the serial connection.\n */\n //% help=serial/write-string\n //% weight=87 blockGap=8\n //% blockId=serial_writestring block=\"serial|write string %text\"\n //% text.shadowOptions.toString=true\n void writeString(String text) {\n if (!text) return;\n\n uBit.serial.send(MSTR(text));\n }\n\n /**\n * Send a buffer through serial connection\n */\n //% blockId=serial_writebuffer block=\"serial|write buffer %buffer=serial_readbuffer\"\n //% help=serial/write-buffer advanced=true weight=6\n void writeBuffer(Buffer buffer) {\n if (!buffer) return;\n\n uBit.serial.send(buffer->data, buffer->length);\n }\n\n /**\n * Read multiple characters from the receive buffer. \n * If length is positive, pauses until enough characters are present.\n * @param length default buffer length\n */\n //% blockId=serial_readbuffer block=\"serial|read buffer %length\"\n //% help=serial/read-buffer advanced=true weight=5\n Buffer readBuffer(int length) {\n auto mode = SYNC_SLEEP;\n if (length <= 0) {\n length = uBit.serial.getRxBufferSize();\n mode = ASYNC;\n }\n\n auto buf = mkBuffer(NULL, length);\n auto res = buf;\n registerGCObj(buf); // make sure buffer is pinned, while we wait for data\n int read = uBit.serial.read(buf->data, buf->length, mode);\n if (read != length) {\n res = mkBuffer(buf->data, read);\n }\n unregisterGCObj(buf);\n\n return res;\n }\n\n bool tryResolvePin(SerialPin p, PinName& name) {\n switch(p) {\n#if !MICROBIT_CODAL\n case SerialPin::USB_TX: name = USBTX; return true;\n case SerialPin::USB_RX: name = USBRX; return true;\n#endif\n default: \n auto pin = getPin(p); \n if (NULL != pin) {\n name = (PinName)pin->name;\n return true;\n }\n }\n return false;\n }\n\n /**\n * Set the serial input and output to use pins instead of the USB connection.\n * @param tx the new transmission pin, eg: SerialPin.P0\n * @param rx the new reception pin, eg: SerialPin.P1\n * @param rate the new baud rate. eg: 115200\n */\n //% weight=10\n //% help=serial/redirect\n //% blockId=serial_redirect block=\"serial|redirect to|TX %tx|RX %rx|at baud rate %rate\"\n //% blockExternalInputs=1\n //% tx.fieldEditor=\"gridpicker\" tx.fieldOptions.columns=3\n //% tx.fieldOptions.tooltips=\"false\"\n //% rx.fieldEditor=\"gridpicker\" rx.fieldOptions.columns=3\n //% rx.fieldOptions.tooltips=\"false\"\n //% blockGap=8\n void redirect(SerialPin tx, SerialPin rx, BaudRate rate) {\n#if MICROBIT_CODAL\n if (getPin(tx) && getPin(rx))\n uBit.serial.redirect(*getPin(tx), *getPin(rx));\n uBit.serial.setBaud(rate);\n#else\n PinName txn;\n PinName rxn;\n if (tryResolvePin(tx, txn) && tryResolvePin(rx, rxn))\n uBit.serial.redirect(txn, rxn);\n uBit.serial.baud((int)rate);\n#endif\n }\n\n /**\n Set the baud rate of the serial port\n */\n //% weight=10\n //% blockId=serial_setbaudrate block=\"serial|set baud rate %rate\"\n //% blockGap=8 inlineInputMode=inline\n //% help=serial/set-baud-rate\n //% group=\"Configuration\" advanced=true\n void setBaudRate(BaudRate rate) {\n#if MICROBIT_CODAL\n uBit.serial.setBaud(rate);\n#else\n uBit.serial.baud((int)rate);\n#endif\n }\n\n\n /**\n * Direct the serial input and output to use the USB connection.\n */\n //% weight=9 help=serial/redirect-to-usb\n //% blockId=serial_redirect_to_usb block=\"serial|redirect to USB\"\n void redirectToUSB() {\n#if MICROBIT_CODAL\n uBit.serial.redirect(uBit.io.usbTx, uBit.io.usbRx);\n uBit.serial.setBaud(115200);\n#else\n uBit.serial.redirect(USBTX, USBRX);\n uBit.serial.baud(115200);\n#endif\n }\n\n /**\n * Sets the size of the RX buffer in bytes\n * @param size length of the rx buffer in bytes, eg: 32\n */\n //% help=serial/set-rx-buffer-size\n //% blockId=serialSetRxBufferSize block=\"serial set rx buffer size to $size\"\n //% advanced=true\n void setRxBufferSize(uint8_t size) {\n uBit.serial.setRxBufferSize(size);\n }\n\n /**\n * Sets the size of the TX buffer in bytes\n * @param size length of the tx buffer in bytes, eg: 32\n */\n //% help=serial/set-tx-buffer-size\n //% blockId=serialSetTxBufferSize block=\"serial set tx buffer size to $size\"\n //% advanced=true\n void setTxBufferSize(uint8_t size) {\n uBit.serial.setTxBufferSize(size);\n }\n}\n",
2777
2777
  "serial.ts": "const enum Delimiters {\n //% block=\"new line (\\n)\"\n NewLine = 10,\n //% block=\",\"\n Comma = 44,\n //% block=\"$\"\n Dollar = 36,\n //% block=\":\"\n Colon = 58,\n //% block=\".\"\n Fullstop = 46,\n //% block=\"#\"\n Hash = 35,\n //% block=\"carriage return (\\r)\"\n CarriageReturn = 13,\n //% block=\"space\"\n Space = 32,\n //% block=\"tab (\\t)\"\n Tab = 9,\n //% block=\"|\"\n Pipe = 124,\n //% block=\";\"\n SemiColon = 59,\n}\n\n/**\n * Reading and writing data over a serial connection.\n */\n//% weight=2 color=#002050 icon=\"\\uf287\"\n//% advanced=true\nnamespace serial {\n /**\n * The string used to mark a new line, default is \\r\\n\n */\n export let NEW_LINE = \"\\r\\n\";\n export let NEW_LINE_DELIMITER: Delimiters = Delimiters.NewLine;\n let writeLinePadding = 32;\n\n /**\n * Print a line of text to the serial port\n * @param value to send over serial\n */\n //% weight=90\n //% help=serial/write-line blockGap=8\n //% blockId=serial_writeline block=\"serial|write line %text\"\n //% text.shadowOptions.toString=true\n export function writeLine(text: string): void {\n if (!text) text = \"\";\n serial.writeString(text);\n // pad data to the 32 byte boundary\n // to ensure apps receive the packet\n if (writeLinePadding > 0) {\n let r = (writeLinePadding - (text.length + NEW_LINE.length) % writeLinePadding) % writeLinePadding;\n for (let i = 0; i < r; ++i)\n serial.writeString(\" \");\n }\n serial.writeString(NEW_LINE);\n }\n\n /**\n * Sets the padding length for lines sent with \"write line\".\n * @param length the number of bytes alignment, eg: 0\n *\n */\n //% weight=1\n //% help=serial/set-write-line-padding\n //% blockId=serialWriteNewLinePadding block=\"serial set write line padding to $length\"\n //% advanced=true\n //% length.min=0 length.max=128\n export function setWriteLinePadding(length: number) {\n writeLinePadding = length | 0;\n }\n\n /**\n * Print a numeric value to the serial port\n */\n //% help=serial/write-number\n //% weight=89 blockGap=8\n //% blockId=serial_writenumber block=\"serial|write number %value\"\n export function writeNumber(value: number): void {\n writeString(value.toString());\n }\n\n /**\n * Print an array of numeric values as CSV to the serial port\n */\n //% help=serial/write-numbers\n //% weight=86\n //% blockId=serial_writenumbers block=\"serial|write numbers %values\"\n export function writeNumbers(values: number[]): void {\n if (!values) return;\n for (let i = 0; i < values.length; ++i) {\n if (i > 0) writeString(\",\");\n writeNumber(values[i]);\n }\n writeLine(\"\")\n }\n\n /**\n * Write a name:value pair as a line to the serial port.\n * @param name name of the value stream, eg: x\n * @param value to write\n */\n //% weight=88 blockGap=8\n //% help=serial/write-value\n //% blockId=serial_writevalue block=\"serial|write value %name|= %value\"\n export function writeValue(name: string, value: number): void {\n writeLine((name ? name + \":\" : \"\") + value);\n }\n\n /**\n * Read a line of text from the serial port.\n */\n //% help=serial/read-line\n //% blockId=serial_read_line block=\"serial|read line\"\n //% weight=20 blockGap=8\n export function readLine(): string {\n return serial.readUntil(delimiters(NEW_LINE_DELIMITER));\n }\n\n /**\n * Return the corresponding delimiter string\n */\n //% blockId=\"serial_delimiter_conv\" block=\"%del\"\n //% weight=1 blockHidden=true\n export function delimiters(del: Delimiters): string {\n return String.fromCharCode(del as number);\n }\n}\n",
2778
- "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n /**\n * Creation, manipulation and display of LED images.\n */\n //% color=#7600A8 weight=31 icon=\"\\uf03e\"\n //% advanced=true\ndeclare namespace images {\n\n /**\n * Creates an image that fits on the LED screen.\n */\n //% weight=75 help=images/create-image\n //% blockId=device_build_image block=\"create image\"\n //% parts=\"ledmatrix\" imageLiteral=1 shim=images::createImage\n function createImage(leds: string): Image;\n\n /**\n * Creates an image with 2 frames.\n */\n //% weight=74 help=images/create-big-image\n //% blockId=device_build_big_image block=\"create big image\" imageLiteral=2\n //% parts=\"ledmatrix\" shim=images::createBigImage\n function createBigImage(leds: string): Image;\n}\n\n\ndeclare interface Image {\n /**\n * Plots the image at a given column to the screen\n */\n //% help=images/plot-image\n //% parts=\"ledmatrix\" xOffset.defl=0 shim=ImageMethods::plotImage\n plotImage(xOffset?: int32): void;\n\n /**\n * Shows an frame from the image at offset ``x offset``.\n * @param xOffset column index to start displaying the image\n * @param interval time in milliseconds to pause after drawing\n */\n //% help=images/show-image weight=80 blockNamespace=images\n //% blockId=device_show_image_offset block=\"show image %sprite(myImage)|at offset %offset ||and interval (ms) %interval\"\n //%\n //% blockGap=8 parts=\"ledmatrix\" async interval.defl=400 shim=ImageMethods::showImage\n showImage(xOffset: int32, interval?: int32): void;\n\n /**\n * Draws the ``index``-th frame of the image on the screen.\n * @param xOffset column index to start displaying the image\n */\n //% help=images/plot-frame weight=80\n //% parts=\"ledmatrix\" shim=ImageMethods::plotFrame\n plotFrame(xOffset: int32): void;\n\n /**\n * Scrolls an image .\n * @param frameOffset x offset moved on each animation step, eg: 1, 2, 5\n * @param interval time between each animation step in milli seconds, eg: 200\n */\n //% help=images/scroll-image weight=79 async blockNamespace=images\n //% blockId=device_scroll_image\n //% block=\"scroll image %sprite(myImage)|with offset %frameoffset|and interval (ms) %delay\"\n //% blockGap=8 parts=\"ledmatrix\" shim=ImageMethods::scrollImage\n scrollImage(frameOffset: int32, interval: int32): void;\n\n /**\n * Sets all pixels off.\n */\n //% help=images/clear\n //% parts=\"ledmatrix\" shim=ImageMethods::clear\n clear(): void;\n\n /**\n * Sets a specific pixel brightness at a given position\n */\n //%\n //% parts=\"ledmatrix\" shim=ImageMethods::setPixelBrightness\n setPixelBrightness(x: int32, y: int32, value: int32): void;\n\n /**\n * Gets the pixel brightness ([0..255]) at a given position\n */\n //%\n //% parts=\"ledmatrix\" shim=ImageMethods::pixelBrightness\n pixelBrightness(x: int32, y: int32): int32;\n\n /**\n * Gets the width in columns\n */\n //% help=functions/width shim=ImageMethods::width\n width(): int32;\n\n /**\n * Gets the height in rows (always 5)\n */\n //% shim=ImageMethods::height\n height(): int32;\n\n /**\n * Set a pixel state at position ``(x,y)``\n * @param x pixel column\n * @param y pixel row\n * @param value pixel state\n */\n //% help=images/set-pixel\n //% parts=\"ledmatrix\" shim=ImageMethods::setPixel\n setPixel(x: int32, y: int32, value: boolean): void;\n\n /**\n * Get the pixel state at position ``(x,y)``\n * @param x pixel column\n * @param y pixel row\n */\n //% help=images/pixel\n //% parts=\"ledmatrix\" shim=ImageMethods::pixel\n pixel(x: int32, y: int32): boolean;\n\n /**\n * Show a particular frame of the image strip.\n * @param frame image frame to show\n */\n //% weight=70 help=images/show-frame\n //% parts=\"ledmatrix\" interval.defl=400 shim=ImageMethods::showFrame\n showFrame(frame: int32, interval?: int32): void;\n}\n\n\n /**\n * Provides access to basic micro:bit functionality.\n */\n //% color=#1E90FF weight=116 icon=\"\\uf00a\"\ndeclare namespace basic {\n\n /**\n * Draws an image on the LED screen.\n * @param leds the pattern of LED to turn on/off\n * @param interval time in milliseconds to pause after drawing\n */\n //% help=basic/show-leds\n //% weight=95 blockGap=8\n //% imageLiteral=1 async\n //% blockId=device_show_leds\n //% block=\"show leds\" icon=\"\\uf00a\"\n //% parts=\"ledmatrix\" interval.defl=400 shim=basic::showLeds\n function showLeds(leds: string, interval?: int32): void;\n\n /**\n * Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.\n * @param text the text to scroll on the screen, eg: \"Hello!\"\n * @param interval how fast to shift characters; eg: 150, 100, 200, -100\n */\n //% help=basic/show-string\n //% weight=87 blockGap=16\n //% block=\"show|string %text\"\n //% async\n //% blockId=device_print_message\n //% parts=\"ledmatrix\"\n //% text.shadowOptions.toString=true interval.defl=150 shim=basic::showString\n function showString(text: string, interval?: int32): void;\n\n /**\n * Turn off all LEDs\n */\n //% help=basic/clear-screen weight=79\n //% blockId=device_clear_display block=\"clear screen\"\n //% parts=\"ledmatrix\" shim=basic::clearScreen\n function clearScreen(): void;\n\n /**\n * Shows a sequence of LED screens as an animation.\n * @param leds pattern of LEDs to turn on/off\n * @param interval time in milliseconds between each redraw\n */\n //% help=basic/show-animation imageLiteral=1 async\n //% parts=\"ledmatrix\" interval.defl=400 shim=basic::showAnimation\n function showAnimation(leds: string, interval?: int32): void;\n\n /**\n * Draws an image on the LED screen.\n * @param leds pattern of LEDs to turn on/off\n */\n //% help=basic/plot-leds weight=80\n //% parts=\"ledmatrix\" imageLiteral=1 shim=basic::plotLeds\n function plotLeds(leds: string): void;\n\n /**\n * Repeats the code forever in the background. On each iteration, allows other codes to run.\n * @param body code to execute\n */\n //% help=basic/forever weight=55 blockGap=16 blockAllowMultiple=1 afterOnStart=true\n //% blockId=device_forever block=\"forever\" icon=\"\\uf01e\" shim=basic::forever\n function forever(a: () => void): void;\n\n /**\n * Pause for the specified time in milliseconds\n * @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000\n */\n //% help=basic/pause weight=54\n //% async block=\"pause (ms) %pause\" blockGap=16\n //% blockId=device_pause icon=\"\\uf110\"\n //% pause.shadow=timePicker shim=basic::pause\n function pause(ms: int32): void;\n}\n\n\n\n //% color=#D400D4 weight=111 icon=\"\\uf192\"\ndeclare namespace input {\n\n /**\n * Do something when a button (A, B or both A+B) is pushed down and released again.\n * @param button the button that needs to be pressed\n * @param body code to run when event is raised\n */\n //% help=input/on-button-pressed weight=85 blockGap=16\n //% blockId=device_button_event block=\"on button|%NAME|pressed\"\n //% parts=\"buttonpair\" shim=input::onButtonPressed\n function onButtonPressed(button: Button, body: () => void): void;\n\n /**\n * Do something when when a gesture is done (like shaking the micro:bit).\n * @param gesture the type of gesture to track, eg: Gesture.Shake\n * @param body code to run when gesture is raised\n */\n //% help=input/on-gesture weight=84 blockGap=16\n //% blockId=device_gesture_event block=\"on |%NAME\"\n //% parts=\"accelerometer\"\n //% NAME.fieldEditor=\"gestures\" NAME.fieldOptions.columns=4 shim=input::onGesture\n function onGesture(gesture: Gesture, body: () => void): void;\n\n /**\n * Tests if a gesture is currently detected.\n * @param gesture the type of gesture to detect, eg: Gesture.Shake\n */\n //% help=input/is-gesture weight=10 blockGap=8\n //% blockId=deviceisgesture block=\"is %gesture gesture\"\n //% parts=\"accelerometer\"\n //% gesture.fieldEditor=\"gestures\" gesture.fieldOptions.columns=4 shim=input::isGesture\n function isGesture(gesture: Gesture): boolean;\n\n /**\n * Do something when a pin is touched and released again (while also touching the GND pin).\n * @param name the pin that needs to be pressed, eg: TouchPin.P0\n * @param body the code to run when the pin is pressed\n */\n //% help=input/on-pin-pressed weight=83 blockGap=32\n //% blockId=device_pin_event block=\"on pin %name|pressed\" shim=input::onPinPressed\n function onPinPressed(name: TouchPin, body: () => void): void;\n\n /**\n * Do something when a pin is released.\n * @param name the pin that needs to be released, eg: TouchPin.P0\n * @param body the code to run when the pin is released\n */\n //% help=input/on-pin-released weight=6 blockGap=16\n //% blockId=device_pin_released block=\"on pin %NAME|released\"\n //% advanced=true shim=input::onPinReleased\n function onPinReleased(name: TouchPin, body: () => void): void;\n\n /**\n * Get the button state (pressed or not) for ``A`` and ``B``.\n * @param button the button to query the request, eg: Button.A\n */\n //% help=input/button-is-pressed weight=60\n //% block=\"button|%NAME|is pressed\"\n //% blockId=device_get_button2\n //% icon=\"\\uf192\" blockGap=8\n //% parts=\"buttonpair\" shim=input::buttonIsPressed\n function buttonIsPressed(button: Button): boolean;\n\n /**\n * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.\n * @param name pin used to detect the touch, eg: TouchPin.P0\n */\n //% help=input/pin-is-pressed weight=58\n //% blockId=\"device_pin_is_pressed\" block=\"pin %NAME|is pressed\"\n //% blockGap=8 shim=input::pinIsPressed\n function pinIsPressed(name: TouchPin): boolean;\n\n /**\n * Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)\n * @param dimension x, y, or z dimension, eg: Dimension.X\n */\n //% help=input/acceleration weight=58\n //% blockId=device_acceleration block=\"acceleration (mg)|%NAME\" blockGap=8\n //% parts=\"accelerometer\" shim=input::acceleration\n function acceleration(dimension: Dimension): int32;\n\n /**\n * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.\n */\n //% help=input/light-level weight=57\n //% blockId=device_get_light_level block=\"light level\" blockGap=8\n //% parts=\"ledmatrix\" shim=input::lightLevel\n function lightLevel(): int32;\n\n /**\n * Get the current compass heading in degrees.\n */\n //% help=input/compass-heading\n //% weight=56\n //% blockId=device_heading block=\"compass heading (°)\" blockGap=8\n //% parts=\"compass\" shim=input::compassHeading\n function compassHeading(): int32;\n\n /**\n * Gets the temperature in Celsius degrees (°C).\n */\n //% weight=55\n //% help=input/temperature\n //% blockId=device_temperature block=\"temperature (°C)\" blockGap=8\n //% parts=\"thermometer\" shim=input::temperature\n function temperature(): int32;\n\n /**\n * The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.\n * @param kind pitch or roll\n */\n //% help=input/rotation weight=52\n //% blockId=device_get_rotation block=\"rotation (°)|%NAME\" blockGap=8\n //% parts=\"accelerometer\" advanced=true shim=input::rotation\n function rotation(kind: Rotation): int32;\n\n /**\n * Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.\n * @param dimension the x, y, or z dimension, eg: Dimension.X\n */\n //% help=input/magnetic-force weight=51\n //% blockId=device_get_magnetic_force block=\"magnetic force (µT)|%NAME\" blockGap=8\n //% parts=\"compass\"\n //% advanced=true shim=input::magneticForce\n function magneticForce(dimension: Dimension): number;\n\n /**\n * Obsolete, compass calibration is automatic.\n */\n //% help=input/calibrate-compass advanced=true\n //% blockId=\"input_compass_calibrate\" block=\"calibrate compass\"\n //% weight=45 shim=input::calibrateCompass\n function calibrateCompass(): void;\n\n /**\n * Sets the accelerometer sample range in gravities.\n * @param range a value describe the maximum strengh of acceleration measured\n */\n //% help=input/set-accelerometer-range\n //% blockId=device_set_accelerometer_range block=\"set accelerometer|range %range\"\n //% weight=5\n //% parts=\"accelerometer\"\n //% advanced=true shim=input::setAccelerometerRange\n function setAccelerometerRange(range: AcceleratorRange): void;\n}\n\n\n\n //% weight=1 color=\"#333333\"\n //% advanced=true\ndeclare namespace control {\n\n /**\n * Gets the number of milliseconds elapsed since power on.\n */\n //% help=control/millis weight=50\n //% blockId=control_running_time block=\"millis (ms)\" shim=control::millis\n function millis(): int32;\n\n /**\n * Gets current time in microseconds. Overflows every ~18 minutes.\n */\n //% shim=control::micros\n function micros(): int32;\n\n /**\n * Schedules code that run in the background.\n */\n //% help=control/in-background blockAllowMultiple=1 afterOnStart=true\n //% blockId=\"control_in_background\" block=\"run in background\" blockGap=8 shim=control::inBackground\n function inBackground(a: () => void): void;\n\n /**\n * Blocks the calling thread until the specified event is raised.\n */\n //% help=control/wait-for-event async\n //% blockId=control_wait_for_event block=\"wait for event|from %src|with value %value\" shim=control::waitForEvent\n function waitForEvent(src: int32, value: int32): void;\n\n /**\n * Resets the BBC micro:bit.\n */\n //% weight=30 async help=control/reset blockGap=8\n //% blockId=\"control_reset\" block=\"reset\" shim=control::reset\n function reset(): void;\n\n /**\n * Blocks the current fiber for the given microseconds\n * @param micros number of micro-seconds to wait. eg: 4\n */\n //% help=control/wait-micros weight=29 async\n //% blockId=\"control_wait_us\" block=\"wait (µs)%micros\"\n //% micros.min=0 micros.max=6000 shim=control::waitMicros\n function waitMicros(micros: int32): void;\n\n /**\n * Raises an event in the event bus.\n * @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.\n * @param value Component specific code indicating the cause of the event.\n * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).\n */\n //% weight=21 blockGap=12 blockId=\"control_raise_event\" block=\"raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\" blockExternalInputs=1\n //% help=control/raise-event\n //% mode.defl=1 shim=control::raiseEvent\n function raiseEvent(src: int32, value: int32, mode?: EventCreationMode): void;\n\n /**\n * Registers an event handler.\n */\n //% weight=20 blockGap=8 blockId=\"control_on_event\" block=\"on event|from %src=control_event_source_id|with value %value=control_event_value_id\"\n //% help=control/on-event\n //% blockExternalInputs=1 flags.defl=0 shim=control::onEvent\n function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;\n\n /**\n * Gets the value of the last event executed on the bus\n */\n //% blockId=control_event_value\" block=\"event value\"\n //% help=control/event-value\n //% weight=18 shim=control::eventValue\n function eventValue(): int32;\n\n /**\n * Gets the timestamp of the last event executed on the bus\n */\n //% blockId=control_event_timestamp\" block=\"event timestamp\"\n //% help=control/event-timestamp\n //% weight=19 blockGap=8 shim=control::eventTimestamp\n function eventTimestamp(): int32;\n\n /**\n * Make a friendly name for the device based on its serial number\n */\n //% blockId=\"control_device_name\" block=\"device name\" weight=10 blockGap=8\n //% help=control/device-name\n //% advanced=true shim=control::deviceName\n function deviceName(): string;\n\n /**\n * Returns the major version of the microbit\n */\n //% help=control/hardware-version shim=control::_hardwareVersion\n function _hardwareVersion(): string;\n\n /**\n * Derive a unique, consistent serial number of this device from internal data.\n */\n //% blockId=\"control_device_serial_number\" block=\"device serial number\" weight=9\n //% help=control/device-serial-number\n //% advanced=true shim=control::deviceSerialNumber\n function deviceSerialNumber(): int32;\n\n /**\n * Derive a unique, consistent 64-bit serial number of this device from internal data.\n */\n //% help=control/device-long-serial-number\n //% advanced=true shim=control::deviceLongSerialNumber\n function deviceLongSerialNumber(): Buffer;\n\n /**\n * Informs simulator/runtime of a MIDI message\n * Internal function to support the simulator.\n */\n //% part=midioutput blockHidden=1 shim=control::__midiSend\n function __midiSend(buffer: Buffer): void;\n\n /**\n *\n */\n //% shim=control::__log\n function __log(priority: int32, text: string): void;\n\n /**\n * Allocates the next user notification event\n */\n //% help=control/allocate-notify-event shim=control::allocateNotifyEvent\n function allocateNotifyEvent(): int32;\n\n /** Write a message to DMESG debugging buffer. */\n //% shim=control::dmesg\n function dmesg(s: string): void;\n\n /** Write a message and value (pointer) to DMESG debugging buffer. */\n //% shim=control::dmesgPtr\n function dmesgPtr(str: string, ptr: Object): void;\n}\ndeclare namespace control {\n\n /**\n * Force GC and dump basic information about heap.\n */\n //% shim=control::gc\n function gc(): void;\n\n /**\n * Force GC and halt waiting for debugger to do a full heap dump.\n */\n //% shim=control::heapDump\n function heapDump(): void;\n\n /**\n * Set flags used when connecting an external debugger.\n */\n //% shim=control::setDebugFlags\n function setDebugFlags(flags: int32): void;\n\n /**\n * Record a heap snapshot to debug memory leaks.\n */\n //% shim=control::heapSnapshot\n function heapSnapshot(): void;\n\n /**\n * Return true if profiling is enabled in the current build.\n */\n //% shim=control::profilingEnabled\n function profilingEnabled(): boolean;\n}\n\n\n\n //% color=#7600A8 weight=101 icon=\"\\uf205\"\ndeclare namespace led {\n\n /**\n * Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED starting at 0\n * @param y the vertical coordinate of the LED starting at 0\n */\n //% help=led/plot weight=78\n //% blockId=device_plot block=\"plot|x %x|y %y\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::plot\n function plot(x: int32, y: int32): void;\n\n /**\n * Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED starting at 0\n * @param y the vertical coordinate of the LED starting at 0\n * @param brightness the brightness from 0 (off) to 255 (bright), eg:255\n */\n //% help=led/plot-brightness weight=78\n //% blockId=device_plot_brightness block=\"plot|x %x|y %y|brightness %brightness\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1\n //% advanced=true shim=led::plotBrightness\n function plotBrightness(x: int32, y: int32, brightness: int32): void;\n\n /**\n * Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED\n * @param y the vertical coordinate of the LED\n */\n //% help=led/unplot weight=77\n //% blockId=device_unplot block=\"unplot|x %x|y %y\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::unplot\n function unplot(x: int32, y: int32): void;\n\n /**\n * Get the brightness state of the specified LED using x, y coordinates. (0,0) is upper left.\n * @param x the horizontal coordinate of the LED\n * @param y the vertical coordinate of the LED\n */\n //% help=led/point-brightness weight=76\n //% blockId=device_point_brightness block=\"point|x %x|y %y brightness\"\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1\n //% advanced=true shim=led::pointBrightness\n function pointBrightness(x: int32, y: int32): int32;\n\n /**\n * Get the screen brightness from 0 (off) to 255 (full bright).\n */\n //% help=led/brightness weight=60\n //% blockId=device_get_brightness block=\"brightness\" blockGap=8\n //% parts=\"ledmatrix\"\n //% advanced=true shim=led::brightness\n function brightness(): int32;\n\n /**\n * Set the screen brightness from 0 (off) to 255 (full bright).\n * @param value the brightness value, eg:255, 127, 0\n */\n //% help=led/set-brightness weight=59\n //% blockId=device_set_brightness block=\"set brightness %value\"\n //% parts=\"ledmatrix\"\n //% advanced=true\n //% value.min=0 value.max=255 shim=led::setBrightness\n function setBrightness(value: int32): void;\n\n /**\n * Cancels the current animation and clears other pending animations.\n */\n //% weight=50 help=led/stop-animation\n //% blockId=device_stop_animation block=\"stop animation\"\n //% parts=\"ledmatrix\"\n //% advanced=true shim=led::stopAnimation\n function stopAnimation(): void;\n\n /**\n * Sets the display mode between black and white and greyscale for rendering LEDs.\n * @param mode mode the display mode in which the screen operates\n */\n //% weight=1 help=led/set-display-mode\n //% parts=\"ledmatrix\" advanced=true weight=1\n //% blockId=\"led_set_display_mode\" block=\"set display mode $mode\" shim=led::setDisplayMode\n function setDisplayMode(mode: DisplayMode): void;\n\n /**\n * Gets the current display mode\n */\n //% weight=1 parts=\"ledmatrix\" advanced=true shim=led::displayMode\n function displayMode(): DisplayMode;\n\n /**\n * Turns on or off the display\n */\n //% help=led/enable blockId=device_led_enable block=\"led enable %on\"\n //% advanced=true parts=\"ledmatrix\" shim=led::enable\n function enable(on: boolean): void;\n\n /**\n * Takes a screenshot of the LED screen and returns an image.\n */\n //% help=led/screenshot\n //% parts=\"ledmatrix\" shim=led::screenshot\n function screenshot(): Image;\n}\ndeclare namespace music {\n\n /**\n * Set the default output volume of the sound synthesizer.\n * @param volume the volume 0...255\n */\n //% blockId=synth_set_volume block=\"set volume %volume\"\n //% volume.min=0 volume.max=255\n //%\n //% help=music/set-volume\n //% weight=70\n //% group=\"Volume\"\n //% blockGap=8 volume.defl=127 shim=music::setVolume\n function setVolume(volume?: int32): void;\n\n /**\n * Returns the current output volume of the sound synthesizer.\n */\n //% blockId=synth_get_volume block=\"volume\"\n //% help=music/volume\n //% weight=69\n //% group=\"Volume\"\n //% blockGap=8 shim=music::volume\n function volume(): int32;\n\n /**\n * Turn the built-in speaker on or off.\n * Disabling the speaker resets the sound pin to the default of P0.\n * @param enabled whether the built-in speaker is enabled in addition to the sound pin\n */\n //% blockId=music_set_built_in_speaker_enable block=\"set built-in speaker $enabled\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\"\n //% parts=builtinspeaker\n //% help=music/set-built-in-speaker-enabled\n //% enabled.shadow=toggleOnOff shim=music::setBuiltInSpeakerEnabled\n function setBuiltInSpeakerEnabled(enabled: boolean): void;\n\n /**\n * Defines an optional sample level to generate during periods of silence.\n **/\n //% group=\"micro:bit (V2)\"\n //% help=music/set-silence-level\n //% level.min=0\n //% level.max=1024\n //%\n //% weight=1 level.defl=0 shim=music::setSilenceLevel\n function setSilenceLevel(level?: int32): void;\n}\ndeclare namespace pins {\n\n /**\n * Read the specified pin or connector as either 0 or 1\n * @param name pin to read from, eg: DigitalPin.P0\n */\n //% help=pins/digital-read-pin weight=30\n //% blockId=device_get_digital_pin block=\"digital read|pin %name\" blockGap=8\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::digitalReadPin\n function digitalReadPin(name: DigitalPin): int32;\n\n /**\n * Set a pin or connector value to either 0 or 1.\n * @param name pin to write to, eg: DigitalPin.P0\n * @param value value to set on the pin, 1 eg,0\n */\n //% help=pins/digital-write-pin weight=29\n //% blockId=device_set_digital_pin block=\"digital write|pin %name|to %value\"\n //% value.min=0 value.max=1\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::digitalWritePin\n function digitalWritePin(name: DigitalPin, value: int32): void;\n\n /**\n * Read the connector value as analog, that is, as a value comprised between 0 and 1023.\n * @param name pin to write to, eg: AnalogPin.P0\n */\n //% help=pins/analog-read-pin weight=25\n //% blockId=device_get_analog_pin block=\"analog read|pin %name\" blockGap=\"8\"\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::analogReadPin\n function analogReadPin(name: AnalogPin): int32;\n\n /**\n * Set the connector value as analog. Value must be comprised between 0 and 1023.\n * @param name pin name to write to, eg: AnalogPin.P0\n * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0\n */\n //% help=pins/analog-write-pin weight=24\n //% blockId=device_set_analog_pin block=\"analog write|pin %name|to %value\" blockGap=8\n //% value.min=0 value.max=1023\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::analogWritePin\n function analogWritePin(name: AnalogPin, value: int32): void;\n\n /**\n * Configure the pulse-width modulation (PWM) period of the analog output in microseconds.\n * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.\n * @param name analog pin to set period to, eg: AnalogPin.P0\n * @param micros period in micro seconds. eg:20000\n */\n //% help=pins/analog-set-period weight=23 blockGap=8\n //% blockId=device_set_analog_period block=\"analog set period|pin %pin|to (µs)%micros\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" shim=pins::analogSetPeriod\n function analogSetPeriod(name: AnalogPin, micros: int32): void;\n\n /**\n * Configure the pin as a digital input and generate an event when the pin is pulsed either high or low.\n * @param name digital pin to register to, eg: DigitalPin.P0\n * @param pulse the value of the pulse, eg: PulseValue.High\n */\n //% help=pins/on-pulsed weight=22 blockGap=16 advanced=true\n //% blockId=pins_on_pulsed block=\"on|pin %pin|pulsed %pulse\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\" shim=pins::onPulsed\n function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;\n\n /**\n * Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler.\n */\n //% help=pins/pulse-duration advanced=true\n //% blockId=pins_pulse_duration block=\"pulse duration (µs)\"\n //% weight=21 blockGap=8 shim=pins::pulseDuration\n function pulseDuration(): int32;\n\n /**\n * Return the duration of a pulse at a pin in microseconds.\n * @param name the pin which measures the pulse, eg: DigitalPin.P0\n * @param value the value of the pulse, eg: PulseValue.High\n * @param maximum duration in microseconds\n */\n //% blockId=\"pins_pulse_in\" block=\"pulse in (µs)|pin %name|pulsed %value\"\n //% weight=20 advanced=true\n //% help=pins/pulse-in\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" maxDuration.defl=2000000 shim=pins::pulseIn\n function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: int32): int32;\n\n /**\n * Write a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).\n * @param name pin to write to, eg: AnalogPin.P0\n * @param value angle or rotation speed, eg:180,90,0\n */\n //% help=pins/servo-write-pin weight=20\n //% blockId=device_set_servo_pin block=\"servo write|pin %name|to %value\" blockGap=8\n //% parts=microservo trackArgs=0\n //% value.min=0 value.max=180\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::servoWritePin\n function servoWritePin(name: AnalogPin, value: int32): void;\n\n /**\n * Specifies that a continuous servo is connected.\n */\n //% shim=pins::servoSetContinuous\n function servoSetContinuous(name: AnalogPin, value: boolean): void;\n\n /**\n * Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds.\n * @param name pin name\n * @param micros pulse duration in micro seconds, eg:1500\n */\n //% help=pins/servo-set-pulse weight=19\n //% blockId=device_set_servo_pulse block=\"servo set pulse|pin %value|to (µs) %micros\"\n //% value.fieldEditor=\"gridpicker\" value.fieldOptions.columns=4\n //% value.fieldOptions.tooltips=\"false\" value.fieldOptions.width=\"250\" shim=pins::servoSetPulse\n function servoSetPulse(name: AnalogPin, micros: int32): void;\n\n /**\n * Set the pin used when using analog pitch or music.\n * @param name pin to modulate pitch from\n */\n //% blockId=device_analog_set_pitch_pin block=\"analog set pitch pin %name\"\n //% help=pins/analog-set-pitch-pin weight=3 advanced=true\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::analogSetPitchPin\n function analogSetPitchPin(name: AnalogPin): void;\n\n /**\n * Sets the volume on the pitch pin\n * @param volume the intensity of the sound from 0..255\n */\n //% blockId=device_analog_set_pitch_volume block=\"analog set pitch volume $volume\"\n //% help=pins/analog-set-pitch-volume weight=3 advanced=true\n //% volume.min=0 volume.max=255\n //% deprecated shim=pins::analogSetPitchVolume\n function analogSetPitchVolume(volume: int32): void;\n\n /**\n * Gets the volume the pitch pin from 0..255\n */\n //% blockId=device_analog_pitch_volume block=\"analog pitch volume\"\n //% help=pins/analog-pitch-volume weight=3 advanced=true\n //% deprecated shim=pins::analogPitchVolume\n function analogPitchVolume(): int32;\n\n /**\n * Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.\n * @param frequency frequency to modulate in Hz.\n * @param ms duration of the pitch in milli seconds.\n */\n //% blockId=device_analog_pitch block=\"analog pitch %frequency|for (ms) %ms\"\n //% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 shim=pins::analogPitch\n function analogPitch(frequency: int32, ms: int32): void;\n\n /**\n * Configure the pull directiion of of a pin.\n * @param name pin to set the pull mode on, eg: DigitalPin.P0\n * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp\n */\n //% help=pins/set-pull weight=3 advanced=true\n //% blockId=device_set_pull block=\"set pull|pin %pin|to %pull\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\" shim=pins::setPull\n function setPull(name: DigitalPin, pull: PinPullMode): void;\n\n /**\n * Configure the events emitted by this pin. Events can be subscribed to\n * using ``control.onEvent()``.\n * @param name pin to set the event mode on, eg: DigitalPin.P0\n * @param type the type of events for this pin to emit, eg: PinEventType.Edge\n */\n //% help=pins/set-events weight=4 advanced=true\n //% blockId=device_set_pin_events block=\"set pin %pin|to emit %type|events\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\" shim=pins::setEvents\n function setEvents(name: DigitalPin, type: PinEventType): void;\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //% shim=pins::createBuffer\n function createBuffer(size: int32): Buffer;\n\n /**\n * Set the matrix width for Neopixel strip (already assigned to a pin).\n * Should be used in conjunction with `set matrix width` from Neopixel package.\n * @param name pin of Neopixel strip, eg: DigitalPin.P1\n * @param value width of matrix (at least ``2``)\n */\n //% help=pins/neopixel-matrix-width weight=3 advanced=true\n //% blockId=pin_neopixel_matrix_width block=\"neopixel matrix width|pin %pin %width\" blockGap=8\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% width.min=2 width.defl=5 shim=pins::setMatrixWidth\n function setMatrixWidth(pin: DigitalPin, width?: int32): void;\n\n /**\n * Read `size` bytes from a 7-bit I2C `address`.\n */\n //% repeat.defl=0 shim=pins::i2cReadBuffer\n function i2cReadBuffer(address: int32, size: int32, repeat?: boolean): Buffer;\n\n /**\n * Write bytes to a 7-bit I2C `address`.\n */\n //% repeat.defl=0 shim=pins::i2cWriteBuffer\n function i2cWriteBuffer(address: int32, buf: Buffer, repeat?: boolean): int32;\n\n /**\n * Write to the SPI slave and return the response\n * @param value Data to be sent to the SPI slave\n */\n //% help=pins/spi-write weight=5 advanced=true\n //% blockId=spi_write block=\"spi write %value\" shim=pins::spiWrite\n function spiWrite(value: int32): int32;\n\n /**\n * Write to and read from the SPI slave at the same time\n * @param command Data to be sent to the SPI slave (can be null)\n * @param response Data received from the SPI slave (can be null)\n */\n //% help=pins/spi-transfer argsNullable shim=pins::spiTransfer\n function spiTransfer(command: Buffer, response: Buffer): void;\n\n /**\n * Set the SPI frequency\n * @param frequency the clock frequency, eg: 1000000\n */\n //% help=pins/spi-frequency weight=4 advanced=true\n //% blockId=spi_frequency block=\"spi frequency %frequency\" shim=pins::spiFrequency\n function spiFrequency(frequency: int32): void;\n\n /**\n * Set the SPI bits and mode\n * @param bits the number of bits, eg: 8\n * @param mode the mode, eg: 3\n */\n //% help=pins/spi-format weight=3 advanced=true\n //% blockId=spi_format block=\"spi format|bits %bits|mode %mode\" shim=pins::spiFormat\n function spiFormat(bits: int32, mode: int32): void;\n\n /**\n * Set the MOSI, MISO, SCK pins used by the SPI connection\n *\n */\n //% help=pins/spi-pins weight=2 advanced=true\n //% blockId=spi_pins block=\"spi set pins|MOSI %mosi|MISO %miso|SCK %sck\"\n //% mosi.fieldEditor=\"gridpicker\" mosi.fieldOptions.columns=4\n //% mosi.fieldOptions.tooltips=\"false\" mosi.fieldOptions.width=\"250\"\n //% miso.fieldEditor=\"gridpicker\" miso.fieldOptions.columns=4\n //% miso.fieldOptions.tooltips=\"false\" miso.fieldOptions.width=\"250\"\n //% sck.fieldEditor=\"gridpicker\" sck.fieldOptions.columns=4\n //% sck.fieldOptions.tooltips=\"false\" sck.fieldOptions.width=\"250\" shim=pins::spiPins\n function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void;\n\n /**\n * Mounts a push button on the given pin\n */\n //% help=pins/push-button advanced=true shim=pins::pushButton\n function pushButton(pin: DigitalPin): void;\n\n /**\n * Set the pin used when producing sounds and melodies. Default is P0.\n * @param name pin to modulate pitch from\n */\n //% blockId=pin_set_audio_pin block=\"set audio pin $name\"\n //% help=pins/set-audio-pin weight=3\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% weight=1 shim=pins::setAudioPin\n function setAudioPin(name: AnalogPin): void;\n}\n\n\n\n //% weight=2 color=#002050 icon=\"\\uf287\"\n //% advanced=true\ndeclare namespace serial {\n\n /**\n * Read a line of text from the serial port and return the buffer when the delimiter is met.\n * @param delimiter text delimiter that separates each text chunk\n */\n //% help=serial/read-until\n //% blockId=serial_read_until block=\"serial|read until %delimiter=serial_delimiter_conv\"\n //% weight=19 shim=serial::readUntil\n function readUntil(delimiter: string): string;\n\n /**\n * Read the buffered received data as a string\n */\n //% help=serial/read-string\n //% blockId=serial_read_buffer block=\"serial|read string\"\n //% weight=18 shim=serial::readString\n function readString(): string;\n\n /**\n * Register an event to be fired when one of the delimiter is matched.\n * @param delimiters the characters to match received characters against.\n */\n //% help=serial/on-data-received\n //% weight=18 blockId=serial_on_data_received block=\"serial|on data received %delimiters=serial_delimiter_conv\" shim=serial::onDataReceived\n function onDataReceived(delimiters: string, body: () => void): void;\n\n /**\n * Send a piece of text through the serial connection.\n */\n //% help=serial/write-string\n //% weight=87 blockGap=8\n //% blockId=serial_writestring block=\"serial|write string %text\"\n //% text.shadowOptions.toString=true shim=serial::writeString\n function writeString(text: string): void;\n\n /**\n * Send a buffer through serial connection\n */\n //% blockId=serial_writebuffer block=\"serial|write buffer %buffer=serial_readbuffer\"\n //% help=serial/write-buffer advanced=true weight=6 shim=serial::writeBuffer\n function writeBuffer(buffer: Buffer): void;\n\n /**\n * Read multiple characters from the receive buffer. \n * If length is positive, pauses until enough characters are present.\n * @param length default buffer length\n */\n //% blockId=serial_readbuffer block=\"serial|read buffer %length\"\n //% help=serial/read-buffer advanced=true weight=5 shim=serial::readBuffer\n function readBuffer(length: int32): Buffer;\n\n /**\n * Set the serial input and output to use pins instead of the USB connection.\n * @param tx the new transmission pin, eg: SerialPin.P0\n * @param rx the new reception pin, eg: SerialPin.P1\n * @param rate the new baud rate. eg: 115200\n */\n //% weight=10\n //% help=serial/redirect\n //% blockId=serial_redirect block=\"serial|redirect to|TX %tx|RX %rx|at baud rate %rate\"\n //% blockExternalInputs=1\n //% tx.fieldEditor=\"gridpicker\" tx.fieldOptions.columns=3\n //% tx.fieldOptions.tooltips=\"false\"\n //% rx.fieldEditor=\"gridpicker\" rx.fieldOptions.columns=3\n //% rx.fieldOptions.tooltips=\"false\"\n //% blockGap=8 shim=serial::redirect\n function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;\n\n /**\n Set the baud rate of the serial port\n */\n //% weight=10\n //% blockId=serial_setbaudrate block=\"serial|set baud rate %rate\"\n //% blockGap=8 inlineInputMode=inline\n //% help=serial/set-baud-rate\n //% group=\"Configuration\" advanced=true shim=serial::setBaudRate\n function setBaudRate(rate: BaudRate): void;\n\n /**\n * Direct the serial input and output to use the USB connection.\n */\n //% weight=9 help=serial/redirect-to-usb\n //% blockId=serial_redirect_to_usb block=\"serial|redirect to USB\" shim=serial::redirectToUSB\n function redirectToUSB(): void;\n\n /**\n * Sets the size of the RX buffer in bytes\n * @param size length of the rx buffer in bytes, eg: 32\n */\n //% help=serial/set-rx-buffer-size\n //% blockId=serialSetRxBufferSize block=\"serial set rx buffer size to $size\"\n //% advanced=true shim=serial::setRxBufferSize\n function setRxBufferSize(size: uint8): void;\n\n /**\n * Sets the size of the TX buffer in bytes\n * @param size length of the tx buffer in bytes, eg: 32\n */\n //% help=serial/set-tx-buffer-size\n //% blockId=serialSetTxBufferSize block=\"serial set tx buffer size to $size\"\n //% advanced=true shim=serial::setTxBufferSize\n function setTxBufferSize(size: uint8): void;\n}\n\n\n\n //% indexerGet=BufferMethods::getByte indexerSet=BufferMethods::setByte\ndeclare interface Buffer {\n /**\n * Reads an unsigned byte at a particular location\n */\n //% shim=BufferMethods::getUint8\n getUint8(off: int32): int32;\n\n /**\n * Returns false when the buffer can be written to.\n */\n //% shim=BufferMethods::isReadOnly\n isReadOnly(): boolean;\n\n /**\n * Writes an unsigned byte at a particular location\n */\n //% shim=BufferMethods::setUint8\n setUint8(off: int32, v: int32): void;\n\n /**\n * Write a number in specified format in the buffer.\n */\n //% shim=BufferMethods::setNumber\n setNumber(format: NumberFormat, offset: int32, value: number): void;\n\n /**\n * Read a number in specified format from the buffer.\n */\n //% shim=BufferMethods::getNumber\n getNumber(format: NumberFormat, offset: int32): number;\n\n /** Returns the length of a Buffer object. */\n //% property shim=BufferMethods::length\n length: int32;\n\n /**\n * Fill (a fragment) of the buffer with given value.\n */\n //% offset.defl=0 length.defl=-1 shim=BufferMethods::fill\n fill(value: int32, offset?: int32, length?: int32): void;\n\n /**\n * Return a copy of a fragment of a buffer.\n */\n //% offset.defl=0 length.defl=-1 shim=BufferMethods::slice\n slice(offset?: int32, length?: int32): Buffer;\n\n /**\n * Shift buffer left in place, with zero padding.\n * @param offset number of bytes to shift; use negative value to shift right\n * @param start start offset in buffer. Default is 0.\n * @param length number of elements in buffer. If negative, length is set as the buffer length minus\n * start. eg: -1\n */\n //% start.defl=0 length.defl=-1 shim=BufferMethods::shift\n shift(offset: int32, start?: int32, length?: int32): void;\n\n /**\n * Convert a buffer to string assuming UTF8 encoding\n */\n //% shim=BufferMethods::toString\n toString(): string;\n\n /**\n * Convert a buffer to its hexadecimal representation.\n */\n //% shim=BufferMethods::toHex\n toHex(): string;\n\n /**\n * Rotate buffer left in place.\n * @param offset number of bytes to shift; use negative value to shift right\n * @param start start offset in buffer. Default is 0.\n * @param length number of elements in buffer. If negative, length is set as the buffer length minus\n * start. eg: -1\n */\n //% start.defl=0 length.defl=-1 shim=BufferMethods::rotate\n rotate(offset: int32, start?: int32, length?: int32): void;\n\n /**\n * Write contents of `src` at `dstOffset` in current buffer.\n */\n //% shim=BufferMethods::write\n write(dstOffset: int32, src: Buffer): void;\n\n /**\n * Compute k-bit FNV-1 non-cryptographic hash of the buffer.\n */\n //% shim=BufferMethods::hash\n hash(bits: int32): uint32;\n}\ndeclare namespace control {\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //% deprecated=1 shim=control::createBuffer\n function createBuffer(size: int32): Buffer;\n\n /**\n * Create a new buffer with UTF8-encoded string\n * @param str the string to put in the buffer\n */\n //% deprecated=1 shim=control::createBufferFromUTF8\n function createBufferFromUTF8(str: string): Buffer;\n}\ndeclare namespace light {\n\n /**\n * Sends a color buffer to a light strip\n **/\n //% advanced=true shim=light::sendWS2812Buffer\n function sendWS2812Buffer(buf: Buffer, pin: int32): void;\n\n /**\n * Sends a color buffer to a light strip\n **/\n //% advanced=true shim=light::sendWS2812BufferWithBrightness\n function sendWS2812BufferWithBrightness(buf: Buffer, pin: int32, brightness: int32): void;\n\n /**\n * Sets the light mode of a pin\n **/\n //% advanced=true\n //% shim=light::setMode\n function setMode(pin: int32, mode: int32): void;\n}\ndeclare namespace input {\n\n /**\n * Do something when the logo is touched and released again.\n * @param body the code to run when the logo is pressed\n */\n //% weight=83 blockGap=32\n //% blockId=input_logo_event block=\"on logo $action\"\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/on-logo-event\" shim=input::onLogoEvent\n function onLogoEvent(action: TouchButtonEvent, body: () => void): void;\n\n /**\n * Get the logo state (pressed or not).\n */\n //% weight=58\n //% blockId=\"input_logo_is_pressed\" block=\"logo is pressed\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/logo-is-pressed\" shim=input::logoIsPressed\n function logoIsPressed(): boolean;\n}\ndeclare namespace pins {\n\n /**\n * Configure the touch detection for the pins and logo.\n * P0, P1, P2 use resistive touch by default.\n * The logo uses capacitative touch by default.\n * @param name target to change the touch mode for\n * @param mode the touch mode to use\n */\n //% weight=60\n //% blockId=device_touch_set_type block=\"set %name to touch mode %mode\"\n //% advanced=true\n //% group=\"micro:bit (V2)\"\n //% help=pins/touch-set-mode shim=pins::touchSetMode\n function touchSetMode(name: TouchTarget, mode: TouchTargetMode): void;\n}\ndeclare namespace music {\n\n /**\n * Internal use only\n **/\n //% async shim=music::__playSoundExpression\n function __playSoundExpression(nodes: string, waitTillDone: boolean): void;\n\n /**\n * Internal use only\n */\n //% shim=music::__stopSoundExpressions\n function __stopSoundExpressions(): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2778
+ "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n /**\n * Creation, manipulation and display of LED images.\n */\n //% color=#7600A8 weight=31 icon=\"\\uf03e\"\n //% advanced=true\ndeclare namespace images {\n\n /**\n * Creates an image that fits on the LED screen.\n */\n //% weight=75 help=images/create-image\n //% blockId=device_build_image block=\"create image\"\n //% parts=\"ledmatrix\" imageLiteral=1 shim=images::createImage\n function createImage(leds: string): Image;\n\n /**\n * Creates an image with 2 frames.\n */\n //% weight=74 help=images/create-big-image\n //% blockId=device_build_big_image block=\"create big image\" imageLiteral=2\n //% parts=\"ledmatrix\" shim=images::createBigImage\n function createBigImage(leds: string): Image;\n}\n\n\ndeclare interface Image {\n /**\n * Plots the image at a given column to the screen\n */\n //% help=images/plot-image\n //% parts=\"ledmatrix\" xOffset.defl=0 shim=ImageMethods::plotImage\n plotImage(xOffset?: int32): void;\n\n /**\n * Shows an frame from the image at offset ``x offset``.\n * @param xOffset column index to start displaying the image\n * @param interval time in milliseconds to pause after drawing\n */\n //% help=images/show-image weight=80 blockNamespace=images\n //% blockId=device_show_image_offset block=\"show image %sprite(myImage)|at offset %offset ||and interval (ms) %interval\"\n //%\n //% blockGap=8 parts=\"ledmatrix\" async interval.defl=400 shim=ImageMethods::showImage\n showImage(xOffset: int32, interval?: int32): void;\n\n /**\n * Draws the ``index``-th frame of the image on the screen.\n * @param xOffset column index to start displaying the image\n */\n //% help=images/plot-frame weight=80\n //% parts=\"ledmatrix\" shim=ImageMethods::plotFrame\n plotFrame(xOffset: int32): void;\n\n /**\n * Scrolls an image .\n * @param frameOffset x offset moved on each animation step, eg: 1, 2, 5\n * @param interval time between each animation step in milli seconds, eg: 200\n */\n //% help=images/scroll-image weight=79 async blockNamespace=images\n //% blockId=device_scroll_image\n //% block=\"scroll image %sprite(myImage)|with offset %frameoffset|and interval (ms) %delay\"\n //% blockGap=8 parts=\"ledmatrix\" shim=ImageMethods::scrollImage\n scrollImage(frameOffset: int32, interval: int32): void;\n\n /**\n * Sets all pixels off.\n */\n //% help=images/clear\n //% parts=\"ledmatrix\" shim=ImageMethods::clear\n clear(): void;\n\n /**\n * Sets a specific pixel brightness at a given position\n */\n //%\n //% parts=\"ledmatrix\" shim=ImageMethods::setPixelBrightness\n setPixelBrightness(x: int32, y: int32, value: int32): void;\n\n /**\n * Gets the pixel brightness ([0..255]) at a given position\n */\n //%\n //% parts=\"ledmatrix\" shim=ImageMethods::pixelBrightness\n pixelBrightness(x: int32, y: int32): int32;\n\n /**\n * Gets the width in columns\n */\n //% help=functions/width shim=ImageMethods::width\n width(): int32;\n\n /**\n * Gets the height in rows (always 5)\n */\n //% shim=ImageMethods::height\n height(): int32;\n\n /**\n * Set a pixel state at position ``(x,y)``\n * @param x pixel column\n * @param y pixel row\n * @param value pixel state\n */\n //% help=images/set-pixel\n //% parts=\"ledmatrix\" shim=ImageMethods::setPixel\n setPixel(x: int32, y: int32, value: boolean): void;\n\n /**\n * Get the pixel state at position ``(x,y)``\n * @param x pixel column\n * @param y pixel row\n */\n //% help=images/pixel\n //% parts=\"ledmatrix\" shim=ImageMethods::pixel\n pixel(x: int32, y: int32): boolean;\n\n /**\n * Show a particular frame of the image strip.\n * @param frame image frame to show\n */\n //% weight=70 help=images/show-frame\n //% parts=\"ledmatrix\" interval.defl=400 shim=ImageMethods::showFrame\n showFrame(frame: int32, interval?: int32): void;\n}\n\n\n /**\n * Provides access to basic micro:bit functionality.\n */\n //% color=#1E90FF weight=116 icon=\"\\uf00a\"\ndeclare namespace basic {\n\n /**\n * Draws an image on the LED screen.\n * @param leds the pattern of LED to turn on/off\n * @param interval time in milliseconds to pause after drawing\n */\n //% help=basic/show-leds\n //% weight=95 blockGap=8\n //% imageLiteral=1 async\n //% blockId=device_show_leds\n //% block=\"show leds\" icon=\"\\uf00a\"\n //% parts=\"ledmatrix\" interval.defl=400 shim=basic::showLeds\n function showLeds(leds: string, interval?: int32): void;\n\n /**\n * Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.\n * @param text the text to scroll on the screen, eg: \"Hello!\"\n * @param interval how fast to shift characters; eg: 150, 100, 200, -100\n */\n //% help=basic/show-string\n //% weight=87 blockGap=16\n //% block=\"show|string %text\"\n //% async\n //% blockId=device_print_message\n //% parts=\"ledmatrix\"\n //% text.shadowOptions.toString=true interval.defl=150 shim=basic::showString\n function showString(text: string, interval?: int32): void;\n\n /**\n * Turn off all LEDs\n */\n //% help=basic/clear-screen weight=79\n //% blockId=device_clear_display block=\"clear screen\"\n //% parts=\"ledmatrix\" shim=basic::clearScreen\n function clearScreen(): void;\n\n /**\n * Shows a sequence of LED screens as an animation.\n * @param leds pattern of LEDs to turn on/off\n * @param interval time in milliseconds between each redraw\n */\n //% help=basic/show-animation imageLiteral=1 async\n //% parts=\"ledmatrix\" interval.defl=400 shim=basic::showAnimation\n function showAnimation(leds: string, interval?: int32): void;\n\n /**\n * Draws an image on the LED screen.\n * @param leds pattern of LEDs to turn on/off\n */\n //% help=basic/plot-leds weight=80\n //% parts=\"ledmatrix\" imageLiteral=1 shim=basic::plotLeds\n function plotLeds(leds: string): void;\n\n /**\n * Repeats the code forever in the background. On each iteration, allows other codes to run.\n * @param body code to execute\n */\n //% help=basic/forever weight=55 blockGap=16 blockAllowMultiple=1 afterOnStart=true\n //% blockId=device_forever block=\"forever\" icon=\"\\uf01e\" shim=basic::forever\n function forever(a: () => void): void;\n\n /**\n * Pause for the specified time in milliseconds\n * @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000\n */\n //% help=basic/pause weight=54\n //% async block=\"pause (ms) %pause\" blockGap=16\n //% blockId=device_pause icon=\"\\uf110\"\n //% pause.shadow=timePicker shim=basic::pause\n function pause(ms: int32): void;\n}\n\n\n\n //% color=#D400D4 weight=111 icon=\"\\uf192\"\ndeclare namespace input {\n\n /**\n * Do something when a button (A, B or both A+B) is pushed down and released again.\n * @param button the button that needs to be pressed\n * @param body code to run when event is raised\n */\n //% help=input/on-button-pressed weight=85 blockGap=16\n //% blockId=device_button_event block=\"on button|%NAME|pressed\"\n //% parts=\"buttonpair\" shim=input::onButtonPressed\n function onButtonPressed(button: Button, body: () => void): void;\n\n /**\n * Do something when when a gesture is done (like shaking the micro:bit).\n * @param gesture the type of gesture to track, eg: Gesture.Shake\n * @param body code to run when gesture is raised\n */\n //% help=input/on-gesture weight=84 blockGap=16\n //% blockId=device_gesture_event block=\"on |%NAME\"\n //% parts=\"accelerometer\"\n //% NAME.fieldEditor=\"gestures\" NAME.fieldOptions.columns=4 shim=input::onGesture\n function onGesture(gesture: Gesture, body: () => void): void;\n\n /**\n * Tests if a gesture is currently detected.\n * @param gesture the type of gesture to detect, eg: Gesture.Shake\n */\n //% help=input/is-gesture weight=10 blockGap=8\n //% blockId=deviceisgesture block=\"is %gesture gesture\"\n //% parts=\"accelerometer\"\n //% gesture.fieldEditor=\"gestures\" gesture.fieldOptions.columns=4 shim=input::isGesture\n function isGesture(gesture: Gesture): boolean;\n\n /**\n * Do something when a pin is touched and released again (while also touching the GND pin).\n * @param name the pin that needs to be pressed, eg: TouchPin.P0\n * @param body the code to run when the pin is pressed\n */\n //% help=input/on-pin-pressed weight=83 blockGap=32\n //% blockId=device_pin_event block=\"on pin %name|pressed\" shim=input::onPinPressed\n function onPinPressed(name: TouchPin, body: () => void): void;\n\n /**\n * Do something when a pin is released.\n * @param name the pin that needs to be released, eg: TouchPin.P0\n * @param body the code to run when the pin is released\n */\n //% help=input/on-pin-released weight=6 blockGap=16\n //% blockId=device_pin_released block=\"on pin %NAME|released\"\n //% advanced=true shim=input::onPinReleased\n function onPinReleased(name: TouchPin, body: () => void): void;\n\n /**\n * Get the button state (pressed or not) for ``A`` and ``B``.\n * @param button the button to query the request, eg: Button.A\n */\n //% help=input/button-is-pressed weight=60\n //% block=\"button|%NAME|is pressed\"\n //% blockId=device_get_button2\n //% icon=\"\\uf192\" blockGap=8\n //% parts=\"buttonpair\" shim=input::buttonIsPressed\n function buttonIsPressed(button: Button): boolean;\n\n /**\n * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.\n * @param name pin used to detect the touch, eg: TouchPin.P0\n */\n //% help=input/pin-is-pressed weight=58\n //% blockId=\"device_pin_is_pressed\" block=\"pin %NAME|is pressed\"\n //% blockGap=8 shim=input::pinIsPressed\n function pinIsPressed(name: TouchPin): boolean;\n\n /**\n * Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)\n * @param dimension x, y, or z dimension, eg: Dimension.X\n */\n //% help=input/acceleration weight=58\n //% blockId=device_acceleration block=\"acceleration (mg)|%NAME\" blockGap=8\n //% parts=\"accelerometer\" shim=input::acceleration\n function acceleration(dimension: Dimension): int32;\n\n /**\n * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.\n */\n //% help=input/light-level weight=57\n //% blockId=device_get_light_level block=\"light level\" blockGap=8\n //% parts=\"ledmatrix\" shim=input::lightLevel\n function lightLevel(): int32;\n\n /**\n * Get the current compass heading in degrees.\n */\n //% help=input/compass-heading\n //% weight=56\n //% blockId=device_heading block=\"compass heading (°)\" blockGap=8\n //% parts=\"compass\" shim=input::compassHeading\n function compassHeading(): int32;\n\n /**\n * Gets the temperature in Celsius degrees (°C).\n */\n //% weight=55\n //% help=input/temperature\n //% blockId=device_temperature block=\"temperature (°C)\" blockGap=8\n //% parts=\"thermometer\" shim=input::temperature\n function temperature(): int32;\n\n /**\n * The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.\n * @param kind pitch or roll\n */\n //% help=input/rotation weight=52\n //% blockId=device_get_rotation block=\"rotation (°)|%NAME\" blockGap=8\n //% parts=\"accelerometer\" advanced=true shim=input::rotation\n function rotation(kind: Rotation): int32;\n\n /**\n * Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.\n * @param dimension the x, y, or z dimension, eg: Dimension.X\n */\n //% help=input/magnetic-force weight=51\n //% blockId=device_get_magnetic_force block=\"magnetic force (µT)|%NAME\" blockGap=8\n //% parts=\"compass\"\n //% advanced=true shim=input::magneticForce\n function magneticForce(dimension: Dimension): number;\n\n /**\n * Obsolete, compass calibration is automatic.\n */\n //% help=input/calibrate-compass advanced=true\n //% blockId=\"input_compass_calibrate\" block=\"calibrate compass\"\n //% weight=45 shim=input::calibrateCompass\n function calibrateCompass(): void;\n\n /**\n * Sets the accelerometer sample range in gravities.\n * @param range a value describe the maximum strengh of acceleration measured\n */\n //% help=input/set-accelerometer-range\n //% blockId=device_set_accelerometer_range block=\"set accelerometer|range %range\"\n //% weight=5\n //% parts=\"accelerometer\"\n //% advanced=true shim=input::setAccelerometerRange\n function setAccelerometerRange(range: AcceleratorRange): void;\n}\n\n\n\n //% weight=1 color=\"#333333\"\n //% advanced=true\ndeclare namespace control {\n\n /**\n * Gets the number of milliseconds elapsed since power on.\n */\n //% help=control/millis weight=50\n //% blockId=control_running_time block=\"millis (ms)\" shim=control::millis\n function millis(): int32;\n\n /**\n * Gets current time in microseconds. Overflows every ~18 minutes.\n */\n //% shim=control::micros\n function micros(): int32;\n\n /**\n * Schedules code that run in the background.\n */\n //% help=control/in-background blockAllowMultiple=1 afterOnStart=true\n //% blockId=\"control_in_background\" block=\"run in background\" blockGap=8 shim=control::inBackground\n function inBackground(a: () => void): void;\n\n /**\n * Blocks the calling thread until the specified event is raised.\n */\n //% help=control/wait-for-event async\n //% blockId=control_wait_for_event block=\"wait for event|from %src|with value %value\" shim=control::waitForEvent\n function waitForEvent(src: int32, value: int32): void;\n\n /**\n * Resets the BBC micro:bit.\n */\n //% weight=30 async help=control/reset blockGap=8\n //% blockId=\"control_reset\" block=\"reset\" shim=control::reset\n function reset(): void;\n\n /**\n * Blocks the current fiber for the given microseconds\n * @param micros number of micro-seconds to wait. eg: 4\n */\n //% help=control/wait-micros weight=29 async\n //% blockId=\"control_wait_us\" block=\"wait (µs)%micros\"\n //% micros.min=0 micros.max=6000 shim=control::waitMicros\n function waitMicros(micros: int32): void;\n\n /**\n * Raises an event in the event bus.\n * @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.\n * @param value Component specific code indicating the cause of the event.\n * @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).\n */\n //% weight=21 blockGap=12 blockId=\"control_raise_event\" block=\"raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\" blockExternalInputs=1\n //% help=control/raise-event\n //% mode.defl=1 shim=control::raiseEvent\n function raiseEvent(src: int32, value: int32, mode?: EventCreationMode): void;\n\n /**\n * Registers an event handler.\n */\n //% weight=20 blockGap=8 blockId=\"control_on_event\" block=\"on event|from %src=control_event_source_id|with value %value=control_event_value_id\"\n //% help=control/on-event\n //% blockExternalInputs=1 flags.defl=0 shim=control::onEvent\n function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;\n\n /**\n * Gets the value of the last event executed on the bus\n */\n //% blockId=control_event_value\" block=\"event value\"\n //% help=control/event-value\n //% weight=18 shim=control::eventValue\n function eventValue(): int32;\n\n /**\n * Gets the timestamp of the last event executed on the bus\n */\n //% blockId=control_event_timestamp\" block=\"event timestamp\"\n //% help=control/event-timestamp\n //% weight=19 blockGap=8 shim=control::eventTimestamp\n function eventTimestamp(): int32;\n\n /**\n * Make a friendly name for the device based on its serial number\n */\n //% blockId=\"control_device_name\" block=\"device name\" weight=10 blockGap=8\n //% help=control/device-name\n //% advanced=true shim=control::deviceName\n function deviceName(): string;\n\n /**\n * Returns the major version of the microbit\n */\n //% help=control/hardware-version shim=control::_hardwareVersion\n function _hardwareVersion(): string;\n\n /**\n * Derive a unique, consistent serial number of this device from internal data.\n */\n //% blockId=\"control_device_serial_number\" block=\"device serial number\" weight=9\n //% help=control/device-serial-number\n //% advanced=true shim=control::deviceSerialNumber\n function deviceSerialNumber(): int32;\n\n /**\n * Derive a unique, consistent 64-bit serial number of this device from internal data.\n */\n //% help=control/device-long-serial-number\n //% advanced=true shim=control::deviceLongSerialNumber\n function deviceLongSerialNumber(): Buffer;\n\n /**\n * Informs simulator/runtime of a MIDI message\n * Internal function to support the simulator.\n */\n //% part=midioutput blockHidden=1 shim=control::__midiSend\n function __midiSend(buffer: Buffer): void;\n\n /**\n *\n */\n //% shim=control::__log\n function __log(priority: int32, text: string): void;\n\n /**\n * Allocates the next user notification event\n */\n //% help=control/allocate-notify-event shim=control::allocateNotifyEvent\n function allocateNotifyEvent(): int32;\n\n /** Write a message to DMESG debugging buffer. */\n //% shim=control::dmesg\n function dmesg(s: string): void;\n\n /** Write a message and value (pointer) to DMESG debugging buffer. */\n //% shim=control::dmesgPtr\n function dmesgPtr(str: string, ptr: Object): void;\n}\ndeclare namespace control {\n\n /**\n * Force GC and dump basic information about heap.\n */\n //% shim=control::gc\n function gc(): void;\n\n /**\n * Force GC and halt waiting for debugger to do a full heap dump.\n */\n //% shim=control::heapDump\n function heapDump(): void;\n\n /**\n * Set flags used when connecting an external debugger.\n */\n //% shim=control::setDebugFlags\n function setDebugFlags(flags: int32): void;\n\n /**\n * Record a heap snapshot to debug memory leaks.\n */\n //% shim=control::heapSnapshot\n function heapSnapshot(): void;\n\n /**\n * Return true if profiling is enabled in the current build.\n */\n //% shim=control::profilingEnabled\n function profilingEnabled(): boolean;\n}\n\n\n\n //% color=#7600A8 weight=101 icon=\"\\uf205\"\ndeclare namespace led {\n\n /**\n * Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED starting at 0\n * @param y the vertical coordinate of the LED starting at 0\n */\n //% help=led/plot weight=78\n //% blockId=device_plot block=\"plot|x %x|y %y\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::plot\n function plot(x: int32, y: int32): void;\n\n /**\n * Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED starting at 0\n * @param y the vertical coordinate of the LED starting at 0\n * @param brightness the brightness from 0 (off) to 255 (bright), eg:255\n */\n //% help=led/plot-brightness weight=78\n //% blockId=device_plot_brightness block=\"plot|x %x|y %y|brightness %brightness\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1\n //% advanced=true shim=led::plotBrightness\n function plotBrightness(x: int32, y: int32, brightness: int32): void;\n\n /**\n * Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.\n * @param x the horizontal coordinate of the LED\n * @param y the vertical coordinate of the LED\n */\n //% help=led/unplot weight=77\n //% blockId=device_unplot block=\"unplot|x %x|y %y\" blockGap=8\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::unplot\n function unplot(x: int32, y: int32): void;\n\n /**\n * Get the brightness state of the specified LED using x, y coordinates. (0,0) is upper left.\n * @param x the horizontal coordinate of the LED\n * @param y the vertical coordinate of the LED\n */\n //% help=led/point-brightness weight=76\n //% blockId=device_point_brightness block=\"point|x %x|y %y brightness\"\n //% parts=\"ledmatrix\"\n //% x.min=0 x.max=4 y.min=0 y.max=4\n //% x.fieldOptions.precision=1 y.fieldOptions.precision=1\n //% advanced=true shim=led::pointBrightness\n function pointBrightness(x: int32, y: int32): int32;\n\n /**\n * Get the screen brightness from 0 (off) to 255 (full bright).\n */\n //% help=led/brightness weight=60\n //% blockId=device_get_brightness block=\"brightness\" blockGap=8\n //% parts=\"ledmatrix\"\n //% advanced=true shim=led::brightness\n function brightness(): int32;\n\n /**\n * Set the screen brightness from 0 (off) to 255 (full bright).\n * @param value the brightness value, eg:255, 127, 0\n */\n //% help=led/set-brightness weight=59\n //% blockId=device_set_brightness block=\"set brightness %value\"\n //% parts=\"ledmatrix\"\n //% advanced=true\n //% value.min=0 value.max=255 shim=led::setBrightness\n function setBrightness(value: int32): void;\n\n /**\n * Cancels the current animation and clears other pending animations.\n */\n //% weight=50 help=led/stop-animation\n //% blockId=device_stop_animation block=\"stop animation\"\n //% parts=\"ledmatrix\"\n //% advanced=true shim=led::stopAnimation\n function stopAnimation(): void;\n\n /**\n * Sets the display mode between black and white and greyscale for rendering LEDs.\n * @param mode mode the display mode in which the screen operates\n */\n //% weight=1 help=led/set-display-mode\n //% parts=\"ledmatrix\" advanced=true weight=1\n //% blockId=\"led_set_display_mode\" block=\"set display mode $mode\" shim=led::setDisplayMode\n function setDisplayMode(mode: DisplayMode): void;\n\n /**\n * Gets the current display mode\n */\n //% weight=1 parts=\"ledmatrix\" advanced=true shim=led::displayMode\n function displayMode(): DisplayMode;\n\n /**\n * Turns on or off the display\n */\n //% help=led/enable blockId=device_led_enable block=\"led enable %on\"\n //% advanced=true parts=\"ledmatrix\" shim=led::enable\n function enable(on: boolean): void;\n\n /**\n * Takes a screenshot of the LED screen and returns an image.\n */\n //% help=led/screenshot\n //% parts=\"ledmatrix\" shim=led::screenshot\n function screenshot(): Image;\n}\ndeclare namespace music {\n\n /**\n * Set the default output volume of the sound synthesizer.\n * @param volume the volume 0...255\n */\n //% blockId=synth_set_volume block=\"set volume %volume\"\n //% volume.min=0 volume.max=255\n //%\n //% help=music/set-volume\n //% weight=70\n //% group=\"Volume\"\n //% blockGap=8 volume.defl=127 shim=music::setVolume\n function setVolume(volume?: int32): void;\n\n /**\n * Returns the current output volume of the sound synthesizer.\n */\n //% blockId=synth_get_volume block=\"volume\"\n //% help=music/volume\n //% weight=69\n //% group=\"Volume\"\n //% blockGap=8 shim=music::volume\n function volume(): int32;\n\n /**\n * Turn the built-in speaker on or off.\n * Disabling the speaker resets the sound pin to the default of P0.\n * @param enabled whether the built-in speaker is enabled in addition to the sound pin\n */\n //% blockId=music_set_built_in_speaker_enable block=\"set built-in speaker $enabled\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\"\n //% parts=builtinspeaker\n //% help=music/set-built-in-speaker-enabled\n //% enabled.shadow=toggleOnOff shim=music::setBuiltInSpeakerEnabled\n function setBuiltInSpeakerEnabled(enabled: boolean): void;\n\n /**\n * Defines an optional sample level to generate during periods of silence.\n **/\n //% group=\"micro:bit (V2)\"\n //% help=music/set-silence-level\n //% level.min=0\n //% level.max=1024\n //%\n //% weight=1 level.defl=0 shim=music::setSilenceLevel\n function setSilenceLevel(level?: int32): void;\n}\ndeclare namespace pins {\n\n /**\n * Read the specified pin or connector as either 0 or 1\n * @param name pin to read from, eg: DigitalPin.P0\n */\n //% help=pins/digital-read-pin weight=30\n //% blockId=device_get_digital_pin block=\"digital read|pin %name\" blockGap=8\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::digitalReadPin\n function digitalReadPin(name: DigitalPin): int32;\n\n /**\n * Set a pin or connector value to either 0 or 1.\n * @param name pin to write to, eg: DigitalPin.P0\n * @param value value to set on the pin, 1 eg,0\n */\n //% help=pins/digital-write-pin weight=29\n //% blockId=device_set_digital_pin block=\"digital write|pin %name|to %value\"\n //% value.min=0 value.max=1\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::digitalWritePin\n function digitalWritePin(name: DigitalPin, value: int32): void;\n\n /**\n * Read the connector value as analog, that is, as a value comprised between 0 and 1023.\n * @param name pin to write to, eg: AnalogPin.P0\n */\n //% help=pins/analog-read-pin weight=25\n //% blockId=device_get_analog_pin block=\"analog read|pin %name\" blockGap=\"8\"\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::analogReadPin\n function analogReadPin(name: AnalogPin): int32;\n\n /**\n * Set the connector value as analog. Value must be comprised between 0 and 1023.\n * @param name pin name to write to, eg: AnalogPin.P0\n * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0\n */\n //% help=pins/analog-write-pin weight=24\n //% blockId=device_set_analog_pin block=\"analog write|pin %name|to %value\" blockGap=8\n //% value.min=0 value.max=1023\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\" shim=pins::analogWritePin\n function analogWritePin(name: AnalogPin, value: int32): void;\n\n /**\n * Configure the pulse-width modulation (PWM) period of the analog output in microseconds.\n * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.\n * @param name analog pin to set period to, eg: AnalogPin.P0\n * @param micros period in micro seconds. eg:20000\n */\n //% help=pins/analog-set-period weight=23 blockGap=8\n //% blockId=device_set_analog_period block=\"analog set period|pin %pin|to (µs)%micros\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" shim=pins::analogSetPeriod\n function analogSetPeriod(name: AnalogPin, micros: int32): void;\n\n /**\n * Configure the pin as a digital input and generate an event when the pin is pulsed either high or low.\n * @param name digital pin to register to, eg: DigitalPin.P0\n * @param pulse the value of the pulse, eg: PulseValue.High\n */\n //% help=pins/on-pulsed advanced=true\n //% blockId=pins_on_pulsed block=\"on|pin %pin|pulsed %pulse\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pulse\"\n //% weight=25\n //% blockGap=8 shim=pins::onPulsed\n function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;\n\n /**\n * Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler.\n */\n //% help=pins/pulse-duration advanced=true\n //% blockId=pins_pulse_duration block=\"pulse duration (µs)\"\n //% group=\"Pulse\"\n //% weight=24\n //% blockGap=8 shim=pins::pulseDuration\n function pulseDuration(): int32;\n\n /**\n * Return the duration of a pulse at a pin in microseconds.\n * @param name the pin which measures the pulse, eg: DigitalPin.P0\n * @param value the value of the pulse, eg: PulseValue.High\n * @param maximum duration in microseconds\n */\n //% blockId=\"pins_pulse_in\" block=\"pulse in (µs)|pin %name|pulsed %value\"\n //% advanced=true\n //% help=pins/pulse-in\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Pulse\"\n //% weight=23\n //% blockGap=8 maxDuration.defl=2000000 shim=pins::pulseIn\n function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: int32): int32;\n\n /**\n * Write a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).\n * @param name pin to write to, eg: AnalogPin.P0\n * @param value angle or rotation speed, eg:180,90,0\n */\n //% help=pins/servo-write-pin weight=20\n //% blockId=device_set_servo_pin block=\"servo write|pin %name|to %value\" blockGap=8\n //% parts=microservo trackArgs=0\n //% value.min=0 value.max=180\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Servo\" shim=pins::servoWritePin\n function servoWritePin(name: AnalogPin, value: int32): void;\n\n /**\n * Specifies that a continuous servo is connected.\n */\n //% shim=pins::servoSetContinuous\n function servoSetContinuous(name: AnalogPin, value: boolean): void;\n\n /**\n * Configure the IO pin as an analog/pwm output and set a pulse width. The period is 20 ms period and the pulse width is set based on the value given in **microseconds** or `1/1000` milliseconds.\n * @param name pin name\n * @param micros pulse duration in micro seconds, eg:1500\n */\n //% help=pins/servo-set-pulse weight=19\n //% blockId=device_set_servo_pulse block=\"servo set pulse|pin %value|to (µs) %micros\"\n //% value.fieldEditor=\"gridpicker\" value.fieldOptions.columns=4\n //% value.fieldOptions.tooltips=\"false\" value.fieldOptions.width=\"250\"\n //% group=\"Servo\" shim=pins::servoSetPulse\n function servoSetPulse(name: AnalogPin, micros: int32): void;\n\n /**\n * Set the pin used when using analog pitch or music.\n * @param name pin to modulate pitch from\n */\n //% blockId=device_analog_set_pitch_pin block=\"analog set pitch pin %name\"\n //% help=pins/analog-set-pitch-pin advanced=true\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=12\n //% blockGap=8 shim=pins::analogSetPitchPin\n function analogSetPitchPin(name: AnalogPin): void;\n\n /**\n * Sets the volume on the pitch pin\n * @param volume the intensity of the sound from 0..255\n */\n //% blockId=device_analog_set_pitch_volume block=\"analog set pitch volume $volume\"\n //% help=pins/analog-set-pitch-volume weight=3 advanced=true\n //% volume.min=0 volume.max=255\n //% deprecated shim=pins::analogSetPitchVolume\n function analogSetPitchVolume(volume: int32): void;\n\n /**\n * Gets the volume the pitch pin from 0..255\n */\n //% blockId=device_analog_pitch_volume block=\"analog pitch volume\"\n //% help=pins/analog-pitch-volume weight=3 advanced=true\n //% deprecated shim=pins::analogPitchVolume\n function analogPitchVolume(): int32;\n\n /**\n * Emit a plse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.\n * @param frequency frequency to modulate in Hz.\n * @param ms duration of the pitch in milli seconds.\n */\n //% blockId=device_analog_pitch block=\"analog pitch %frequency|for (ms) %ms\"\n //% help=pins/analog-pitch async advanced=true\n //% group=\"Pins\"\n //% weight=14\n //% blockGap=8 shim=pins::analogPitch\n function analogPitch(frequency: int32, ms: int32): void;\n\n /**\n * Configure the pull direction of of a pin.\n * @param name pin to set the pull mode on, eg: DigitalPin.P0\n * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp\n */\n //% help=pins/set-pull advanced=true\n //% blockId=device_set_pull block=\"set pull|pin %pin|to %pull\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=15\n //% blockGap=8 shim=pins::setPull\n function setPull(name: DigitalPin, pull: PinPullMode): void;\n\n /**\n * Configure the events emitted by this pin. Events can be subscribed to\n * using ``control.onEvent()``.\n * @param name pin to set the event mode on, eg: DigitalPin.P0\n * @param type the type of events for this pin to emit, eg: PinEventType.Edge\n */\n //% help=pins/set-events advanced=true\n //% blockId=device_set_pin_events block=\"set pin %pin|to emit %type|events\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% group=\"Pins\"\n //% weight=13\n //% blockGap=8 shim=pins::setEvents\n function setEvents(name: DigitalPin, type: PinEventType): void;\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //% shim=pins::createBuffer\n function createBuffer(size: int32): Buffer;\n\n /**\n * Set the matrix width for Neopixel strip (already assigned to a pin).\n * Should be used in conjunction with `set matrix width` from Neopixel package.\n * @param name pin of Neopixel strip, eg: DigitalPin.P1\n * @param value width of matrix (at least ``2``)\n */\n //% help=pins/neopixel-matrix-width advanced=true\n //% blockId=pin_neopixel_matrix_width block=\"neopixel matrix width|pin %pin %width\"\n //% pin.fieldEditor=\"gridpicker\" pin.fieldOptions.columns=4\n //% pin.fieldOptions.tooltips=\"false\" pin.fieldOptions.width=\"250\"\n //% width.min=2\n //% group=\"Pins\"\n //% weight=11\n //% blockGap=8 width.defl=5 shim=pins::setMatrixWidth\n function setMatrixWidth(pin: DigitalPin, width?: int32): void;\n\n /**\n * Read `size` bytes from a 7-bit I2C `address`.\n */\n //% repeat.defl=0 shim=pins::i2cReadBuffer\n function i2cReadBuffer(address: int32, size: int32, repeat?: boolean): Buffer;\n\n /**\n * Write bytes to a 7-bit I2C `address`.\n */\n //% repeat.defl=0 shim=pins::i2cWriteBuffer\n function i2cWriteBuffer(address: int32, buf: Buffer, repeat?: boolean): int32;\n\n /**\n * Write to the SPI slave and return the response\n * @param value Data to be sent to the SPI slave\n */\n //% help=pins/spi-write advanced=true\n //% blockId=spi_write block=\"spi write %value\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=53 shim=pins::spiWrite\n function spiWrite(value: int32): int32;\n\n /**\n * Write to and read from the SPI slave at the same time\n * @param command Data to be sent to the SPI slave (can be null)\n * @param response Data received from the SPI slave (can be null)\n */\n //% help=pins/spi-transfer argsNullable shim=pins::spiTransfer\n function spiTransfer(command: Buffer, response: Buffer): void;\n\n /**\n * Set the SPI frequency\n * @param frequency the clock frequency, eg: 1000000\n */\n //% help=pins/spi-frequency advanced=true\n //% blockId=spi_frequency block=\"spi frequency %frequency\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=55 shim=pins::spiFrequency\n function spiFrequency(frequency: int32): void;\n\n /**\n * Set the SPI bits and mode\n * @param bits the number of bits, eg: 8\n * @param mode the mode, eg: 3\n */\n //% help=pins/spi-format advanced=true\n //% blockId=spi_format block=\"spi format|bits %bits|mode %mode\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=54 shim=pins::spiFormat\n function spiFormat(bits: int32, mode: int32): void;\n\n /**\n * Set the MOSI, MISO, SCK pins used by the SPI connection\n *\n */\n //% help=pins/spi-pins advanced=true\n //% blockId=spi_pins block=\"spi set pins|MOSI %mosi|MISO %miso|SCK %sck\"\n //% mosi.fieldEditor=\"gridpicker\" mosi.fieldOptions.columns=4\n //% mosi.fieldOptions.tooltips=\"false\" mosi.fieldOptions.width=\"250\"\n //% miso.fieldEditor=\"gridpicker\" miso.fieldOptions.columns=4\n //% miso.fieldOptions.tooltips=\"false\" miso.fieldOptions.width=\"250\"\n //% sck.fieldEditor=\"gridpicker\" sck.fieldOptions.columns=4\n //% sck.fieldOptions.tooltips=\"false\" sck.fieldOptions.width=\"250\"\n //% group=\"SPI\"\n //% blockGap=8\n //% weight=51 shim=pins::spiPins\n function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void;\n\n /**\n * Mounts a push button on the given pin\n */\n //% help=pins/push-button advanced=true shim=pins::pushButton\n function pushButton(pin: DigitalPin): void;\n\n /**\n * Set the pin used when producing sounds and melodies. Default is P0.\n * @param name pin to modulate pitch from\n */\n //% blockId=pin_set_audio_pin block=\"set audio pin $name\"\n //% help=pins/set-audio-pin weight=3\n //% name.fieldEditor=\"gridpicker\" name.fieldOptions.columns=4\n //% name.fieldOptions.tooltips=\"false\" name.fieldOptions.width=\"250\"\n //% weight=1 shim=pins::setAudioPin\n function setAudioPin(name: AnalogPin): void;\n}\n\n\n\n //% weight=2 color=#002050 icon=\"\\uf287\"\n //% advanced=true\ndeclare namespace serial {\n\n /**\n * Read a line of text from the serial port and return the buffer when the delimiter is met.\n * @param delimiter text delimiter that separates each text chunk\n */\n //% help=serial/read-until\n //% blockId=serial_read_until block=\"serial|read until %delimiter=serial_delimiter_conv\"\n //% weight=19 shim=serial::readUntil\n function readUntil(delimiter: string): string;\n\n /**\n * Read the buffered received data as a string\n */\n //% help=serial/read-string\n //% blockId=serial_read_buffer block=\"serial|read string\"\n //% weight=18 shim=serial::readString\n function readString(): string;\n\n /**\n * Register an event to be fired when one of the delimiter is matched.\n * @param delimiters the characters to match received characters against.\n */\n //% help=serial/on-data-received\n //% weight=18 blockId=serial_on_data_received block=\"serial|on data received %delimiters=serial_delimiter_conv\" shim=serial::onDataReceived\n function onDataReceived(delimiters: string, body: () => void): void;\n\n /**\n * Send a piece of text through the serial connection.\n */\n //% help=serial/write-string\n //% weight=87 blockGap=8\n //% blockId=serial_writestring block=\"serial|write string %text\"\n //% text.shadowOptions.toString=true shim=serial::writeString\n function writeString(text: string): void;\n\n /**\n * Send a buffer through serial connection\n */\n //% blockId=serial_writebuffer block=\"serial|write buffer %buffer=serial_readbuffer\"\n //% help=serial/write-buffer advanced=true weight=6 shim=serial::writeBuffer\n function writeBuffer(buffer: Buffer): void;\n\n /**\n * Read multiple characters from the receive buffer. \n * If length is positive, pauses until enough characters are present.\n * @param length default buffer length\n */\n //% blockId=serial_readbuffer block=\"serial|read buffer %length\"\n //% help=serial/read-buffer advanced=true weight=5 shim=serial::readBuffer\n function readBuffer(length: int32): Buffer;\n\n /**\n * Set the serial input and output to use pins instead of the USB connection.\n * @param tx the new transmission pin, eg: SerialPin.P0\n * @param rx the new reception pin, eg: SerialPin.P1\n * @param rate the new baud rate. eg: 115200\n */\n //% weight=10\n //% help=serial/redirect\n //% blockId=serial_redirect block=\"serial|redirect to|TX %tx|RX %rx|at baud rate %rate\"\n //% blockExternalInputs=1\n //% tx.fieldEditor=\"gridpicker\" tx.fieldOptions.columns=3\n //% tx.fieldOptions.tooltips=\"false\"\n //% rx.fieldEditor=\"gridpicker\" rx.fieldOptions.columns=3\n //% rx.fieldOptions.tooltips=\"false\"\n //% blockGap=8 shim=serial::redirect\n function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void;\n\n /**\n Set the baud rate of the serial port\n */\n //% weight=10\n //% blockId=serial_setbaudrate block=\"serial|set baud rate %rate\"\n //% blockGap=8 inlineInputMode=inline\n //% help=serial/set-baud-rate\n //% group=\"Configuration\" advanced=true shim=serial::setBaudRate\n function setBaudRate(rate: BaudRate): void;\n\n /**\n * Direct the serial input and output to use the USB connection.\n */\n //% weight=9 help=serial/redirect-to-usb\n //% blockId=serial_redirect_to_usb block=\"serial|redirect to USB\" shim=serial::redirectToUSB\n function redirectToUSB(): void;\n\n /**\n * Sets the size of the RX buffer in bytes\n * @param size length of the rx buffer in bytes, eg: 32\n */\n //% help=serial/set-rx-buffer-size\n //% blockId=serialSetRxBufferSize block=\"serial set rx buffer size to $size\"\n //% advanced=true shim=serial::setRxBufferSize\n function setRxBufferSize(size: uint8): void;\n\n /**\n * Sets the size of the TX buffer in bytes\n * @param size length of the tx buffer in bytes, eg: 32\n */\n //% help=serial/set-tx-buffer-size\n //% blockId=serialSetTxBufferSize block=\"serial set tx buffer size to $size\"\n //% advanced=true shim=serial::setTxBufferSize\n function setTxBufferSize(size: uint8): void;\n}\n\n\n\n //% indexerGet=BufferMethods::getByte indexerSet=BufferMethods::setByte\ndeclare interface Buffer {\n /**\n * Reads an unsigned byte at a particular location\n */\n //% shim=BufferMethods::getUint8\n getUint8(off: int32): int32;\n\n /**\n * Returns false when the buffer can be written to.\n */\n //% shim=BufferMethods::isReadOnly\n isReadOnly(): boolean;\n\n /**\n * Writes an unsigned byte at a particular location\n */\n //% shim=BufferMethods::setUint8\n setUint8(off: int32, v: int32): void;\n\n /**\n * Write a number in specified format in the buffer.\n */\n //% shim=BufferMethods::setNumber\n setNumber(format: NumberFormat, offset: int32, value: number): void;\n\n /**\n * Read a number in specified format from the buffer.\n */\n //% shim=BufferMethods::getNumber\n getNumber(format: NumberFormat, offset: int32): number;\n\n /** Returns the length of a Buffer object. */\n //% property shim=BufferMethods::length\n length: int32;\n\n /**\n * Fill (a fragment) of the buffer with given value.\n */\n //% offset.defl=0 length.defl=-1 shim=BufferMethods::fill\n fill(value: int32, offset?: int32, length?: int32): void;\n\n /**\n * Return a copy of a fragment of a buffer.\n */\n //% offset.defl=0 length.defl=-1 shim=BufferMethods::slice\n slice(offset?: int32, length?: int32): Buffer;\n\n /**\n * Shift buffer left in place, with zero padding.\n * @param offset number of bytes to shift; use negative value to shift right\n * @param start start offset in buffer. Default is 0.\n * @param length number of elements in buffer. If negative, length is set as the buffer length minus\n * start. eg: -1\n */\n //% start.defl=0 length.defl=-1 shim=BufferMethods::shift\n shift(offset: int32, start?: int32, length?: int32): void;\n\n /**\n * Convert a buffer to string assuming UTF8 encoding\n */\n //% shim=BufferMethods::toString\n toString(): string;\n\n /**\n * Convert a buffer to its hexadecimal representation.\n */\n //% shim=BufferMethods::toHex\n toHex(): string;\n\n /**\n * Rotate buffer left in place.\n * @param offset number of bytes to shift; use negative value to shift right\n * @param start start offset in buffer. Default is 0.\n * @param length number of elements in buffer. If negative, length is set as the buffer length minus\n * start. eg: -1\n */\n //% start.defl=0 length.defl=-1 shim=BufferMethods::rotate\n rotate(offset: int32, start?: int32, length?: int32): void;\n\n /**\n * Write contents of `src` at `dstOffset` in current buffer.\n */\n //% shim=BufferMethods::write\n write(dstOffset: int32, src: Buffer): void;\n\n /**\n * Compute k-bit FNV-1 non-cryptographic hash of the buffer.\n */\n //% shim=BufferMethods::hash\n hash(bits: int32): uint32;\n}\ndeclare namespace control {\n\n /**\n * Create a new zero-initialized buffer.\n * @param size number of bytes in the buffer\n */\n //% deprecated=1 shim=control::createBuffer\n function createBuffer(size: int32): Buffer;\n\n /**\n * Create a new buffer with UTF8-encoded string\n * @param str the string to put in the buffer\n */\n //% deprecated=1 shim=control::createBufferFromUTF8\n function createBufferFromUTF8(str: string): Buffer;\n}\ndeclare namespace light {\n\n /**\n * Sends a color buffer to a light strip\n **/\n //% advanced=true shim=light::sendWS2812Buffer\n function sendWS2812Buffer(buf: Buffer, pin: int32): void;\n\n /**\n * Sends a color buffer to a light strip\n **/\n //% advanced=true shim=light::sendWS2812BufferWithBrightness\n function sendWS2812BufferWithBrightness(buf: Buffer, pin: int32, brightness: int32): void;\n\n /**\n * Sets the light mode of a pin\n **/\n //% advanced=true\n //% shim=light::setMode\n function setMode(pin: int32, mode: int32): void;\n}\ndeclare namespace input {\n\n /**\n * Do something when the logo is touched and released again.\n * @param body the code to run when the logo is pressed\n */\n //% weight=83 blockGap=32\n //% blockId=input_logo_event block=\"on logo $action\"\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/on-logo-event\" shim=input::onLogoEvent\n function onLogoEvent(action: TouchButtonEvent, body: () => void): void;\n\n /**\n * Get the logo state (pressed or not).\n */\n //% weight=58\n //% blockId=\"input_logo_is_pressed\" block=\"logo is pressed\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\"\n //% parts=\"logotouch\"\n //% help=\"input/logo-is-pressed\" shim=input::logoIsPressed\n function logoIsPressed(): boolean;\n}\ndeclare namespace pins {\n\n /**\n * Configure the touch detection for the pins and logo.\n * P0, P1, P2 use resistive touch by default.\n * The logo uses capacitative touch by default.\n * @param name target to change the touch mode for\n * @param mode the touch mode to use\n */\n //% weight=60\n //% blockId=device_touch_set_type block=\"set %name to touch mode %mode\"\n //% advanced=true\n //% group=\"micro:bit (V2)\"\n //% help=pins/touch-set-mode shim=pins::touchSetMode\n function touchSetMode(name: TouchTarget, mode: TouchTargetMode): void;\n}\ndeclare namespace music {\n\n /**\n * Internal use only\n **/\n //% async shim=music::__playSoundExpression\n function __playSoundExpression(nodes: string, waitTillDone: boolean): void;\n\n /**\n * Internal use only\n */\n //% shim=music::__stopSoundExpressions\n function __stopSoundExpressions(): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2779
2779
  "soundexpressions.cpp": "#include \"pxt.h\"\r\n\r\nnamespace music {\r\n /**\r\n * Internal use only\r\n **/\r\n //% async\r\n void __playSoundExpression(String nodes, bool waitTillDone) {\r\n#if MICROBIT_CODAL\r\n if (waitTillDone)\r\n uBit.audio.soundExpressions.play(MSTR(nodes));\r\n else\r\n uBit.audio.soundExpressions.playAsync(MSTR(nodes));\r\n#else\r\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\r\n#endif\r\n }\r\n\r\n /**\r\n * Internal use only\r\n */\r\n //% \r\n void __stopSoundExpressions() {\r\n#if MICROBIT_CODAL\r\n uBit.audio.soundExpressions.stop();\r\n#endif\r\n }\r\n}",
2780
2780
  "soundexpressions.ts": "/**\n * A sound expression.\n */\n//% fixedInstances\n//% blockNamespace=music\n//% group=\"micro:bit (V2)\"\nclass SoundExpression {\n constructor(private notes: string) {\n }\n\n /**\n * Starts to play a sound expression.\n */\n //% block=\"play sound $this\"\n //% weight=80\n //% blockGap=8\n //% help=music/play\n //% group=\"micro:bit (V2)\"\n //% parts=builtinspeaker\n play() {\n music.__playSoundExpression(this.notes, false)\n }\n\n /**\n * Plays a sound expression until finished\n */\n //% block=\"play sound $this until done\"\n //% weight=81\n //% blockGap=8\n //% help=music/play-until-done\n //% group=\"micro:bit (V2)\"\n //% parts=builtinspeaker\n playUntilDone() {\n music.__playSoundExpression(this.notes, true)\n }\n}\n\nnamespace soundExpression {\n //% fixedInstance whenUsed block=\"{id:soundexpression}giggle\"\n export const giggle = new SoundExpression(\"giggle\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}happy\"\n export const happy = new SoundExpression(\"happy\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}hello\"\n export const hello = new SoundExpression(\"hello\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}mysterious\"\n export const mysterious = new SoundExpression(\"mysterious\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}sad\"\n export const sad = new SoundExpression(\"sad\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}slide\"\n export const slide = new SoundExpression(\"slide\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}soaring\"\n export const soaring = new SoundExpression(\"soaring\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}spring\"\n export const spring = new SoundExpression(\"spring\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}twinkle\"\n export const twinkle = new SoundExpression(\"twinkle\");\n //% fixedInstance whenUsed block=\"{id:soundexpression}yawn\"\n export const yawn = new SoundExpression(\"yawn\");\n}",
2781
2781
  "templates.ts": "/**\n * Tagged hex literal converter\n */\n//% shim=@hex\nfunction hex(lits: any, ...args: any[]): Buffer { return null }\n",
@@ -2785,10 +2785,10 @@ var pxtTargetBundle = {
2785
2785
  "radio": {
2786
2786
  "README.md": "# radio\n\nThe radio library.\n\n",
2787
2787
  "enums.d.ts": "// Auto-generated. Do not edit.\ndeclare namespace radio {\n}\n\n// Auto-generated. Do not edit. Really.\n",
2788
- "pxt.json": "{\n \"name\": \"radio\",\n \"description\": \"The radio services\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"shims.d.ts\",\n \"enums.d.ts\",\n \"radio.cpp\",\n \"radio.ts\",\n \"targetoverrides.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"enabled\": 0\n }\n }\n }\n },\n \"icon\": \"/static/libs/radio.png\"\n}\n",
2789
- "radio.cpp": "#include \"pxt.h\"\n\n// micro:bit dal\n#if defined(MICROBIT_H) \n\n#define CODAL_RADIO MicroBitRadio\n#define DEVICE_OK MICROBIT_OK\n#define DEVICE_NOT_SUPPORTED MICROBIT_NOT_SUPPORTED\n#define CODAL_EVENT MicroBitEvent\n#define CODAL_RADIO_MICROBIT_DAL 1\n\n// any other NRF52 board\n#elif defined(NRF52_SERIES)\n\n#include \"NRF52Radio.h\"\n#define CODAL_RADIO codal::NRF52Radio\n#define CODAL_EVENT codal::Event\n\n#endif\n\nusing namespace pxt;\n\n#ifndef MICROBIT_RADIO_MAX_PACKET_SIZE\n#define MICROBIT_RADIO_MAX_PACKET_SIZE 32\n#endif\n\n#ifndef DEVICE_RADIO_MAX_PACKET_SIZE\n#define DEVICE_RADIO_MAX_PACKET_SIZE MICROBIT_RADIO_MAX_PACKET_SIZE\n#endif\n\n#ifndef MICROBIT_ID_RADIO\n#define MICROBIT_ID_RADIO 29\n#endif\n\n#ifndef DEVICE_ID_RADIO\n#define DEVICE_ID_RADIO MICROBIT_ID_RADIO\n#endif\n\n#ifndef MICROBIT_RADIO_EVT_DATAGRAM\n#define MICROBIT_RADIO_EVT_DATAGRAM 1 // Event to signal that a new datagram has been received.\n#endif\n\n#ifndef DEVICE_RADIO_EVT_DATAGRAM\n#define DEVICE_RADIO_EVT_DATAGRAM MICROBIT_RADIO_EVT_DATAGRAM\n#endif\n\n//% color=#E3008C weight=96 icon=\"\\uf012\"\nnamespace radio {\n \n#if CODAL_RADIO_MICROBIT_DAL\n CODAL_RADIO* getRadio() {\n return &uBit.radio;\n }\n#elif defined(CODAL_RADIO)\nclass RadioWrap {\n CODAL_RADIO radio;\n public:\n RadioWrap() \n : radio()\n {}\n\n CODAL_RADIO* getRadio() {\n return &radio;\n }\n};\nSINGLETON(RadioWrap);\nCODAL_RADIO* getRadio() {\n auto wrap = getRadioWrap();\n if (NULL != wrap)\n return wrap->getRadio(); \n return NULL;\n}\n#endif // #else\n\n bool radioEnabled = false;\n int radioEnable() {\n#ifdef CODAL_RADIO\n auto radio = getRadio();\n if (NULL == radio) \n return DEVICE_NOT_SUPPORTED;\n\n int r = radio->enable();\n if (r != DEVICE_OK) {\n target_panic(43);\n return r;\n }\n if (!radioEnabled) {\n getRadio()->setGroup(pxt::programHash());\n getRadio()->setTransmitPower(6); // start with high power by default\n radioEnabled = true;\n }\n return r;\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n }\n\n /**\n * Sends an event over radio to neigboring devices\n */\n //% blockId=radioRaiseEvent block=\"radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\"\n //% blockExternalInputs=1\n //% advanced=true\n //% weight=1\n //% help=radio/raise-event\n void raiseEvent(int src, int value) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->event.eventReceived(CODAL_EVENT(src, value, CREATE_ONLY));\n#endif \n }\n\n /**\n * Internal use only. Takes the next packet from the radio queue and returns its contents + RSSI in a Buffer.\n * @returns NULL if no packet available\n */\n //%\n Buffer readRawPacket() {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return NULL;\n\n auto p = getRadio()->datagram.recv();\n#if CODAL_RADIO_MICROBIT_DAL\n if (p == PacketBuffer::EmptyPacket)\n return NULL;\n int rssi = p.getRSSI();\n auto length = p.length();\n auto bytes = p.getBytes();\n#else\n // TODO: RSSI support\n int rssi = -73; \n auto length = p.length();\n auto bytes = p.getBytes();\n if (length == 0)\n return NULL;\n#endif\n\n uint8_t buf[DEVICE_RADIO_MAX_PACKET_SIZE + sizeof(int)]; // packet length + rssi\n memset(buf, 0, sizeof(buf));\n memcpy(buf, bytes, length); // data\n memcpy(buf + DEVICE_RADIO_MAX_PACKET_SIZE, &rssi, sizeof(int)); // RSSi - assumes Int32LE layout\n return mkBuffer(buf, sizeof(buf));\n#else\n return NULL;\n#endif \n }\n\n /**\n * Internal use only. Sends a raw packet through the radio (assumes RSSI appened to packet)\n */\n //% async\n void sendRawPacket(Buffer msg) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK || NULL == msg) return;\n\n // don't send RSSI data; and make sure no buffer underflow\n int len = msg->length - sizeof(int);\n if (len > 0)\n getRadio()->datagram.send(msg->data, len);\n#endif \n }\n\n /**\n * Used internally by the library.\n */\n //% help=radio/on-data-received\n //% weight=0\n //% blockId=radio_datagram_received_event block=\"radio on data received\" blockGap=8\n //% deprecated=true blockHidden=1\n void onDataReceived(Action body) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n registerWithDal(DEVICE_ID_RADIO, DEVICE_RADIO_EVT_DATAGRAM, body);\n getRadio()->datagram.recv(); // wake up read code\n#endif \n }\n\n /**\n * Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n * @param id the group id between ``0`` and ``255``, eg: 1\n */\n //% help=radio/set-group\n //% weight=100\n //% blockId=radio_set_group block=\"radio set group %ID\"\n //% id.min=0 id.max=255\n void setGroup(int id) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->setGroup(id);\n#endif \n }\n\n /**\n * Change the output power level of the transmitter to the given value.\n * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7\n */\n //% help=radio/set-transmit-power\n //% weight=9 blockGap=8\n //% blockId=radio_set_transmit_power block=\"radio set transmit power %power\"\n //% power.min=0 power.max=7\n //% advanced=true\n void setTransmitPower(int power) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->setTransmitPower(power);\n#endif \n }\n\n /**\n * Change the transmission and reception band of the radio to the given channel\n * @param band a frequency band in the range 0 - 83. Each step is 1MHz wide, based at 2400MHz.\n **/\n //% help=radio/set-frequency-band\n //% weight=8 blockGap=8\n //% blockId=radio_set_frequency_band block=\"radio set frequency band %band\"\n //% band.min=0 band.max=83\n //% advanced=true\n void setFrequencyBand(int band) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n getRadio()->setFrequencyBand(band);\n#endif \n }\n}\n",
2788
+ "pxt.json": "{\n \"name\": \"radio\",\n \"description\": \"The radio services\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"shims.d.ts\",\n \"enums.d.ts\",\n \"radio.cpp\",\n \"radio.ts\",\n \"targetoverrides.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"enabled\": 0\n }\n }\n }\n },\n \"icon\": \"/static/libs/radio.png\"\n}\n",
2789
+ "radio.cpp": "#include \"pxt.h\"\n\n// micro:bit dal\n#if defined(MICROBIT_H) \n\n#define CODAL_RADIO MicroBitRadio\n#define DEVICE_OK MICROBIT_OK\n#define DEVICE_NOT_SUPPORTED MICROBIT_NOT_SUPPORTED\n#define CODAL_EVENT MicroBitEvent\n#define CODAL_RADIO_MICROBIT_DAL 1\n\n// any other NRF52 board\n#elif defined(NRF52_SERIES)\n\n#include \"NRF52Radio.h\"\n#define CODAL_RADIO codal::NRF52Radio\n#define CODAL_EVENT codal::Event\n\n#endif\n\nusing namespace pxt;\n\n#ifndef MICROBIT_RADIO_MAX_PACKET_SIZE\n#define MICROBIT_RADIO_MAX_PACKET_SIZE 32\n#endif\n\n#ifndef DEVICE_RADIO_MAX_PACKET_SIZE\n#define DEVICE_RADIO_MAX_PACKET_SIZE MICROBIT_RADIO_MAX_PACKET_SIZE\n#endif\n\n#ifndef MICROBIT_ID_RADIO\n#define MICROBIT_ID_RADIO 29\n#endif\n\n#ifndef DEVICE_ID_RADIO\n#define DEVICE_ID_RADIO MICROBIT_ID_RADIO\n#endif\n\n#ifndef MICROBIT_RADIO_EVT_DATAGRAM\n#define MICROBIT_RADIO_EVT_DATAGRAM 1 // Event to signal that a new datagram has been received.\n#endif\n\n#ifndef DEVICE_RADIO_EVT_DATAGRAM\n#define DEVICE_RADIO_EVT_DATAGRAM MICROBIT_RADIO_EVT_DATAGRAM\n#endif\n\n//% color=#E3008C weight=96 icon=\"\\uf012\"\nnamespace radio {\n \n#if CODAL_RADIO_MICROBIT_DAL\n CODAL_RADIO* getRadio() {\n return &uBit.radio;\n }\n#elif defined(CODAL_RADIO)\nclass RadioWrap {\n CODAL_RADIO radio;\n public:\n RadioWrap() \n : radio()\n {}\n\n CODAL_RADIO* getRadio() {\n return &radio;\n }\n};\nSINGLETON(RadioWrap);\nCODAL_RADIO* getRadio() {\n auto wrap = getRadioWrap();\n if (NULL != wrap)\n return wrap->getRadio(); \n return NULL;\n}\n#endif // #else\n\n bool radioEnabled = false;\n bool init = false;\n int radioEnable() {\n#ifdef CODAL_RADIO\n auto radio = getRadio();\n if (NULL == radio) \n return DEVICE_NOT_SUPPORTED;\n\n if (init && !radioEnabled) {\n //If radio was explicitly disabled from a call to off API\n //We don't want to enable it here. User needs to call on API first.\n return DEVICE_NOT_SUPPORTED;\n }\n\n int r = radio->enable();\n if (r != DEVICE_OK) {\n target_panic(43);\n return r;\n }\n if (!init) {\n getRadio()->setGroup(0); //Default group zero. This used to be pxt::programHash()\n getRadio()->setTransmitPower(6); // start with high power by default\n init = true;\n }\n radioEnabled = true;\n return r;\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n }\n\n /**\n * Disables the radio for use as a multipoint sender/receiver.\n * Disabling radio will help conserve battery power when it is not in use.\n */\n //% help=radio/off\n void off() {\n#ifdef CODAL_RADIO\n auto radio = getRadio();\n if (NULL == radio)\n return;\n\n int r = radio->disable();\n if (r != DEVICE_OK) {\n target_panic(43);\n } else {\n radioEnabled = false;\n }\n#else\n return;\n#endif\n }\n\n /**\n * Initialises the radio for use as a multipoint sender/receiver\n * Only useful when the radio.off() is used beforehand.\n */\n //% help=radio/on\n void on() {\n#ifdef CODAL_RADIO\n auto radio = getRadio();\n if (NULL == radio)\n return;\n\n int r = radio->enable();\n if (r != DEVICE_OK) {\n target_panic(43);\n } else {\n radioEnabled = true;\n }\n#else\n return;\n#endif\n }\n\n /**\n * Sends an event over radio to neigboring devices\n */\n //% blockId=radioRaiseEvent block=\"radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\"\n //% blockExternalInputs=1\n //% advanced=true\n //% weight=1\n //% help=radio/raise-event\n void raiseEvent(int src, int value) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->event.eventReceived(CODAL_EVENT(src, value, CREATE_ONLY));\n#endif \n }\n\n /**\n * Internal use only. Takes the next packet from the radio queue and returns its contents + RSSI in a Buffer.\n * @returns NULL if no packet available\n */\n //%\n Buffer readRawPacket() {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return NULL;\n\n auto p = getRadio()->datagram.recv();\n#if CODAL_RADIO_MICROBIT_DAL\n if (p == PacketBuffer::EmptyPacket)\n return NULL;\n int rssi = p.getRSSI();\n auto length = p.length();\n auto bytes = p.getBytes();\n#else\n // TODO: RSSI support\n int rssi = -73; \n auto length = p.length();\n auto bytes = p.getBytes();\n if (length == 0)\n return NULL;\n#endif\n\n uint8_t buf[DEVICE_RADIO_MAX_PACKET_SIZE + sizeof(int)]; // packet length + rssi\n memset(buf, 0, sizeof(buf));\n memcpy(buf, bytes, length); // data\n memcpy(buf + DEVICE_RADIO_MAX_PACKET_SIZE, &rssi, sizeof(int)); // RSSi - assumes Int32LE layout\n return mkBuffer(buf, sizeof(buf));\n#else\n return NULL;\n#endif \n }\n\n /**\n * Internal use only. Sends a raw packet through the radio (assumes RSSI appened to packet)\n */\n //% async\n void sendRawPacket(Buffer msg) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK || NULL == msg) return;\n\n // don't send RSSI data; and make sure no buffer underflow\n int len = msg->length - sizeof(int);\n if (len > 0)\n getRadio()->datagram.send(msg->data, len);\n#endif \n }\n\n /**\n * Used internally by the library.\n */\n //% help=radio/on-data-received\n //% weight=0\n //% blockId=radio_datagram_received_event block=\"radio on data received\" blockGap=8\n //% deprecated=true blockHidden=1\n void onDataReceived(Action body) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n registerWithDal(DEVICE_ID_RADIO, DEVICE_RADIO_EVT_DATAGRAM, body);\n getRadio()->datagram.recv(); // wake up read code\n#endif \n }\n\n /**\n * Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n * @param id the group id between ``0`` and ``255``, eg: 1\n */\n //% help=radio/set-group\n //% weight=100\n //% blockId=radio_set_group block=\"radio set group %ID\"\n //% id.min=0 id.max=255\n void setGroup(int id) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->setGroup(id);\n#endif \n }\n\n /**\n * Change the output power level of the transmitter to the given value.\n * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7\n */\n //% help=radio/set-transmit-power\n //% weight=9 blockGap=8\n //% blockId=radio_set_transmit_power block=\"radio set transmit power %power\"\n //% power.min=0 power.max=7\n //% advanced=true\n void setTransmitPower(int power) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n\n getRadio()->setTransmitPower(power);\n#endif \n }\n\n /**\n * Change the transmission and reception band of the radio to the given channel\n * @param band a frequency band in the range 0 - 83. Each step is 1MHz wide, based at 2400MHz.\n **/\n //% help=radio/set-frequency-band\n //% weight=8 blockGap=8\n //% blockId=radio_set_frequency_band block=\"radio set frequency band %band\"\n //% band.min=0 band.max=83\n //% advanced=true\n void setFrequencyBand(int band) {\n#ifdef CODAL_RADIO \n if (radioEnable() != DEVICE_OK) return;\n getRadio()->setFrequencyBand(band);\n#endif \n }\n}\n",
2790
2790
  "radio.ts": "\nenum RadioPacketProperty {\n //% blockIdentity=radio._packetProperty\n //% block=\"signal strength\"\n SignalStrength = 2,\n //% blockIdentity=radio._packetProperty\n //% block=\"time\"\n Time = 0,\n //% block=\"serial number\"\n //% blockIdentity=radio._packetProperty\n SerialNumber = 1\n}\n\n/**\n * Communicate data using radio packets\n */\n//% color=#E3008C weight=96 icon=\"\\uf012\"\nnamespace radio {\n\n // keep in sync with CODAL\n const RADIO_MAX_PACKET_SIZE = 32;\n const MAX_FIELD_DOUBLE_NAME_LENGTH = 8;\n const MAX_PAYLOAD_LENGTH = 20;\n const PACKET_PREFIX_LENGTH = 9;\n const VALUE_PACKET_NAME_LEN_OFFSET = 13;\n const DOUBLE_VALUE_PACKET_NAME_LEN_OFFSET = 17;\n\n // Packet Spec:\n // | 0 | 1 ... 4 | 5 ... 8 | 9 ... 28\n // ----------------------------------------------------------------\n // | packet type | system time | serial number | payload\n //\n // Serial number defaults to 0 unless enabled by user\n\n // payload: number (9 ... 12)\n export const PACKET_TYPE_NUMBER = 0;\n // payload: number (9 ... 12), name length (13), name (14 ... 26)\n export const PACKET_TYPE_VALUE = 1;\n // payload: string length (9), string (10 ... 28)\n export const PACKET_TYPE_STRING = 2;\n // payload: buffer length (9), buffer (10 ... 28)\n export const PACKET_TYPE_BUFFER = 3;\n // payload: number (9 ... 16)\n export const PACKET_TYPE_DOUBLE = 4;\n // payload: number (9 ... 16), name length (17), name (18 ... 26)\n export const PACKET_TYPE_DOUBLE_VALUE = 5;\n\n let transmittingSerial: boolean;\n let initialized = false;\n\n export let lastPacket: RadioPacket;\n let onReceivedNumberHandler: (receivedNumber: number) => void;\n let onReceivedValueHandler: (name: string, value: number) => void;\n let onReceivedStringHandler: (receivedString: string) => void;\n let onReceivedBufferHandler: (receivedBuffer: Buffer) => void;\n\n function init() {\n if (initialized) return;\n initialized = true;\n onDataReceived(handleDataReceived);\n }\n\n function handleDataReceived() {\n let buffer: Buffer = readRawPacket();\n while (buffer) {\n lastPacket = RadioPacket.getPacket(buffer);\n switch (lastPacket.packetType) {\n case PACKET_TYPE_NUMBER:\n case PACKET_TYPE_DOUBLE:\n if (onReceivedNumberHandler)\n onReceivedNumberHandler(lastPacket.numberPayload);\n break;\n case PACKET_TYPE_VALUE:\n case PACKET_TYPE_DOUBLE_VALUE:\n if (onReceivedValueHandler)\n onReceivedValueHandler(lastPacket.stringPayload, lastPacket.numberPayload);\n break;\n case PACKET_TYPE_BUFFER:\n if (onReceivedBufferHandler)\n onReceivedBufferHandler(lastPacket.bufferPayload);\n break;\n case PACKET_TYPE_STRING:\n if (onReceivedStringHandler)\n onReceivedStringHandler(lastPacket.stringPayload);\n break;\n }\n // read next packet if any\n buffer = readRawPacket();\n }\n }\n\n /**\n * Registers code to run when the radio receives a number.\n */\n //% help=radio/on-received-number\n //% blockId=radio_on_number_drag block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" draggableParameters=reporter\n export function onReceivedNumber(cb: (receivedNumber: number) => void) {\n init();\n onReceivedNumberHandler = cb;\n }\n\n /**\n * Registers code to run when the radio receives a key value pair.\n */\n //% help=radio/on-received-value\n //% blockId=radio_on_value_drag block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" draggableParameters=reporter\n export function onReceivedValue(cb: (name: string, value: number) => void) {\n init();\n onReceivedValueHandler = cb;\n }\n\n /**\n * Registers code to run when the radio receives a string.\n */\n //% help=radio/on-received-string\n //% blockId=radio_on_string_drag block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" draggableParameters=reporter\n export function onReceivedString(cb: (receivedString: string) => void) {\n init();\n onReceivedStringHandler = cb;\n }\n\n /**\n * Registers code to run when the radio receives a buffer.\n */\n //% help=radio/on-received-buffer blockHidden=1\n //% blockId=radio_on_buffer_drag block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" draggableParameters=reporter\n export function onReceivedBuffer(cb: (receivedBuffer: Buffer) => void) {\n init();\n onReceivedBufferHandler = cb;\n }\n\n /**\n * Returns properties of the last radio packet received.\n * @param type the type of property to retrieve from the last packet\n */\n //% help=radio/received-packet\n //% weight=11 blockGap=8\n //% blockId=radio_received_packet block=\"received packet %type=radio_packet_property\" blockGap=16\n export function receivedPacket(type: number) {\n if (lastPacket) {\n switch (type) {\n case RadioPacketProperty.Time: return lastPacket.time;\n case RadioPacketProperty.SerialNumber: return lastPacket.serial;\n case RadioPacketProperty.SignalStrength: return lastPacket.signal;\n }\n }\n return 0;\n }\n\n /**\n * Gets a packet property.\n * @param type the packet property type, eg: PacketProperty.time\n */\n //% blockId=radio_packet_property block=\"%note\"\n //% shim=TD_ID blockHidden=1\n export function _packetProperty(type: RadioPacketProperty): number {\n return type;\n }\n\n export class RadioPacket {\n public static getPacket(data: Buffer) {\n if (!data) return undefined;\n // last 4 bytes is RSSi\n return new RadioPacket(data);\n }\n\n public static mkPacket(packetType: number) {\n const res = new RadioPacket();\n res.data[0] = packetType;\n return res;\n }\n\n private constructor(public readonly data?: Buffer) {\n if (!data) this.data = control.createBuffer(RADIO_MAX_PACKET_SIZE + 4);\n }\n\n get signal() {\n return this.data.getNumber(NumberFormat.Int32LE, this.data.length - 4);\n }\n\n get packetType() {\n return this.data[0];\n }\n\n get time() {\n return this.data.getNumber(NumberFormat.Int32LE, 1);\n }\n\n set time(val: number) {\n this.data.setNumber(NumberFormat.Int32LE, 1, val);\n }\n\n get serial() {\n return this.data.getNumber(NumberFormat.Int32LE, 5);\n }\n\n set serial(val: number) {\n this.data.setNumber(NumberFormat.Int32LE, 5, val);\n }\n\n get stringPayload() {\n const offset = getStringOffset(this.packetType) as number;\n return offset ? this.data.slice(offset + 1, this.data[offset]).toString() : undefined;\n }\n\n set stringPayload(val: string) {\n const offset = getStringOffset(this.packetType) as number;\n if (offset) {\n const buf = control.createBufferFromUTF8(truncateString(val, getMaxStringLength(this.packetType)));\n this.data[offset] = buf.length;\n this.data.write(offset + 1, buf);\n }\n }\n\n get numberPayload() {\n switch (this.packetType) {\n case PACKET_TYPE_NUMBER:\n case PACKET_TYPE_VALUE:\n return this.data.getNumber(NumberFormat.Int32LE, PACKET_PREFIX_LENGTH);\n case PACKET_TYPE_DOUBLE:\n case PACKET_TYPE_DOUBLE_VALUE:\n return this.data.getNumber(NumberFormat.Float64LE, PACKET_PREFIX_LENGTH);\n }\n return undefined;\n }\n\n set numberPayload(val: number) {\n switch (this.packetType) {\n case PACKET_TYPE_NUMBER:\n case PACKET_TYPE_VALUE:\n this.data.setNumber(NumberFormat.Int32LE, PACKET_PREFIX_LENGTH, val);\n break;\n case PACKET_TYPE_DOUBLE:\n case PACKET_TYPE_DOUBLE_VALUE:\n this.data.setNumber(NumberFormat.Float64LE, PACKET_PREFIX_LENGTH, val);\n break;\n }\n }\n\n get bufferPayload() {\n const len = this.data[PACKET_PREFIX_LENGTH];\n return this.data.slice(PACKET_PREFIX_LENGTH + 1, len);\n }\n\n set bufferPayload(b: Buffer) {\n const len = Math.min(b.length, MAX_PAYLOAD_LENGTH - 1);\n this.data[PACKET_PREFIX_LENGTH] = len;\n this.data.write(PACKET_PREFIX_LENGTH + 1, b.slice(0, len));\n }\n\n hasString() {\n return this.packetType === PACKET_TYPE_STRING ||\n this.packetType === PACKET_TYPE_VALUE ||\n this.packetType === PACKET_TYPE_DOUBLE_VALUE;\n }\n\n hasNumber() {\n return this.packetType === PACKET_TYPE_NUMBER ||\n this.packetType === PACKET_TYPE_DOUBLE ||\n this.packetType === PACKET_TYPE_VALUE ||\n this.packetType === PACKET_TYPE_DOUBLE_VALUE;\n }\n }\n\n /**\n * Broadcasts a number over radio to any connected micro:bit in the group.\n */\n //% help=radio/send-number\n //% weight=60\n //% blockId=radio_datagram_send block=\"radio send number %value\" blockGap=8\n export function sendNumber(value: number) {\n let packet: RadioPacket;\n\n if (value === (value | 0)) {\n packet = RadioPacket.mkPacket(PACKET_TYPE_NUMBER);\n }\n else {\n packet = RadioPacket.mkPacket(PACKET_TYPE_DOUBLE);\n }\n\n packet.numberPayload = value;\n sendPacket(packet);\n }\n\n /**\n * Broadcasts a name / value pair along with the device serial number\n * and running time to any connected micro:bit in the group. The name can\n * include no more than 8 characters.\n * @param name the field name (max 8 characters), eg: \"name\"\n * @param value the numeric value\n */\n //% help=radio/send-value\n //% weight=59\n //% blockId=radio_datagram_send_value block=\"radio send|value %name|= %value\" blockGap=8\n export function sendValue(name: string, value: number) {\n let packet: RadioPacket;\n\n if (value === (value | 0)) {\n packet = RadioPacket.mkPacket(PACKET_TYPE_VALUE);\n }\n else {\n packet = RadioPacket.mkPacket(PACKET_TYPE_DOUBLE_VALUE);\n }\n\n packet.numberPayload = value;\n packet.stringPayload = name;\n sendPacket(packet);\n }\n\n /**\n * Broadcasts a string along with the device serial number\n * and running time to any connected micro:bit in the group.\n */\n //% help=radio/send-string\n //% weight=58\n //% blockId=radio_datagram_send_string block=\"radio send string %msg\"\n //% msg.shadowOptions.toString=true\n export function sendString(value: string) {\n const packet = RadioPacket.mkPacket(PACKET_TYPE_STRING);\n packet.stringPayload = value;\n sendPacket(packet);\n }\n\n /**\n * Broadcasts a buffer (up to 19 bytes long) along with the device serial number\n * and running time to any connected micro:bit in the group.\n */\n //% help=radio/send-buffer\n //% weight=57\n //% advanced=true\n export function sendBuffer(msg: Buffer) {\n const packet = RadioPacket.mkPacket(PACKET_TYPE_BUFFER);\n packet.bufferPayload = msg;\n sendPacket(packet);\n }\n\n /**\n * Set the radio to transmit the serial number in each message.\n * @param transmit value indicating if the serial number is transmitted, eg: true\n */\n //% help=radio/set-transmit-serial-number\n //% weight=8 blockGap=8\n //% blockId=radio_set_transmit_serial_number block=\"radio set transmit serial number %transmit\"\n //% advanced=true\n export function setTransmitSerialNumber(transmit: boolean) {\n transmittingSerial = transmit;\n }\n\n function sendPacket(packet: RadioPacket) {\n packet.time = control.millis();\n packet.serial = transmittingSerial ? control.deviceSerialNumber() : 0;\n radio.sendRawPacket(packet.data);\n }\n\n function truncateString(str: string, bytes: number) {\n str = str.substr(0, bytes);\n let buff = control.createBufferFromUTF8(str);\n\n while (buff.length > bytes) {\n str = str.substr(0, str.length - 1);\n buff = control.createBufferFromUTF8(str);\n }\n\n return str;\n }\n\n function getStringOffset(packetType: number) {\n switch (packetType) {\n case PACKET_TYPE_STRING:\n return PACKET_PREFIX_LENGTH;\n case PACKET_TYPE_VALUE:\n return VALUE_PACKET_NAME_LEN_OFFSET;\n case PACKET_TYPE_DOUBLE_VALUE:\n return DOUBLE_VALUE_PACKET_NAME_LEN_OFFSET;\n default:\n return undefined;\n }\n }\n\n function getMaxStringLength(packetType: number) {\n switch (packetType) {\n case PACKET_TYPE_STRING:\n return MAX_PAYLOAD_LENGTH - 2;\n case PACKET_TYPE_VALUE:\n case PACKET_TYPE_DOUBLE_VALUE:\n return MAX_FIELD_DOUBLE_NAME_LENGTH;\n default:\n return undefined;\n }\n }\n}",
2791
- "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n\n //% color=#E3008C weight=96 icon=\"\\uf012\"\ndeclare namespace radio {\n\n /**\n * Sends an event over radio to neigboring devices\n */\n //% blockId=radioRaiseEvent block=\"radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\"\n //% blockExternalInputs=1\n //% advanced=true\n //% weight=1\n //% help=radio/raise-event shim=radio::raiseEvent\n function raiseEvent(src: int32, value: int32): void;\n\n /**\n * Internal use only. Takes the next packet from the radio queue and returns its contents + RSSI in a Buffer.\n * @returns NULL if no packet available\n */\n //% shim=radio::readRawPacket\n function readRawPacket(): Buffer;\n\n /**\n * Internal use only. Sends a raw packet through the radio (assumes RSSI appened to packet)\n */\n //% async shim=radio::sendRawPacket\n function sendRawPacket(msg: Buffer): void;\n\n /**\n * Used internally by the library.\n */\n //% help=radio/on-data-received\n //% weight=0\n //% blockId=radio_datagram_received_event block=\"radio on data received\" blockGap=8\n //% deprecated=true blockHidden=1 shim=radio::onDataReceived\n function onDataReceived(body: () => void): void;\n\n /**\n * Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n * @param id the group id between ``0`` and ``255``, eg: 1\n */\n //% help=radio/set-group\n //% weight=100\n //% blockId=radio_set_group block=\"radio set group %ID\"\n //% id.min=0 id.max=255 shim=radio::setGroup\n function setGroup(id: int32): void;\n\n /**\n * Change the output power level of the transmitter to the given value.\n * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7\n */\n //% help=radio/set-transmit-power\n //% weight=9 blockGap=8\n //% blockId=radio_set_transmit_power block=\"radio set transmit power %power\"\n //% power.min=0 power.max=7\n //% advanced=true shim=radio::setTransmitPower\n function setTransmitPower(power: int32): void;\n\n /**\n * Change the transmission and reception band of the radio to the given channel\n * @param band a frequency band in the range 0 - 83. Each step is 1MHz wide, based at 2400MHz.\n **/\n //% help=radio/set-frequency-band\n //% weight=8 blockGap=8\n //% blockId=radio_set_frequency_band block=\"radio set frequency band %band\"\n //% band.min=0 band.max=83\n //% advanced=true shim=radio::setFrequencyBand\n function setFrequencyBand(band: int32): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2791
+ "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n\n //% color=#E3008C weight=96 icon=\"\\uf012\"\ndeclare namespace radio {\n\n /**\n * Disables the radio for use as a multipoint sender/receiver.\n * Disabling radio will help conserve battery power when it is not in use.\n */\n //% help=radio/off shim=radio::off\n function off(): void;\n\n /**\n * Initialises the radio for use as a multipoint sender/receiver\n * Only useful when the radio.off() is used beforehand.\n */\n //% help=radio/on shim=radio::on\n function on(): void;\n\n /**\n * Sends an event over radio to neigboring devices\n */\n //% blockId=radioRaiseEvent block=\"radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id\"\n //% blockExternalInputs=1\n //% advanced=true\n //% weight=1\n //% help=radio/raise-event shim=radio::raiseEvent\n function raiseEvent(src: int32, value: int32): void;\n\n /**\n * Internal use only. Takes the next packet from the radio queue and returns its contents + RSSI in a Buffer.\n * @returns NULL if no packet available\n */\n //% shim=radio::readRawPacket\n function readRawPacket(): Buffer;\n\n /**\n * Internal use only. Sends a raw packet through the radio (assumes RSSI appened to packet)\n */\n //% async shim=radio::sendRawPacket\n function sendRawPacket(msg: Buffer): void;\n\n /**\n * Used internally by the library.\n */\n //% help=radio/on-data-received\n //% weight=0\n //% blockId=radio_datagram_received_event block=\"radio on data received\" blockGap=8\n //% deprecated=true blockHidden=1 shim=radio::onDataReceived\n function onDataReceived(body: () => void): void;\n\n /**\n * Sets the group id for radio communications. A micro:bit can only listen to one group ID at any time.\n * @param id the group id between ``0`` and ``255``, eg: 1\n */\n //% help=radio/set-group\n //% weight=100\n //% blockId=radio_set_group block=\"radio set group %ID\"\n //% id.min=0 id.max=255 shim=radio::setGroup\n function setGroup(id: int32): void;\n\n /**\n * Change the output power level of the transmitter to the given value.\n * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7\n */\n //% help=radio/set-transmit-power\n //% weight=9 blockGap=8\n //% blockId=radio_set_transmit_power block=\"radio set transmit power %power\"\n //% power.min=0 power.max=7\n //% advanced=true shim=radio::setTransmitPower\n function setTransmitPower(power: int32): void;\n\n /**\n * Change the transmission and reception band of the radio to the given channel\n * @param band a frequency band in the range 0 - 83. Each step is 1MHz wide, based at 2400MHz.\n **/\n //% help=radio/set-frequency-band\n //% weight=8 blockGap=8\n //% blockId=radio_set_frequency_band block=\"radio set frequency band %band\"\n //% band.min=0 band.max=83\n //% advanced=true shim=radio::setFrequencyBand\n function setFrequencyBand(band: int32): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2792
2792
  "targetoverrides.ts": "namespace radio {\n export class Packet {\n /**\n * The number payload if a number was sent in this packet (via ``sendNumber()`` or ``sendValue()``)\n * or 0 if this packet did not contain a number.\n */\n public receivedNumber: number;\n /**\n * The string payload if a string was sent in this packet (via ``sendString()`` or ``sendValue()``)\n * or the empty string if this packet did not contain a string.\n */\n public receivedString: string;\n /**\n * The buffer payload if a buffer was sent in this packet\n * or the empty buffer\n */\n public receivedBuffer: Buffer;\n /**\n * The system time of the sender of the packet at the time the packet was sent.\n */\n public time: number;\n /**\n * The serial number of the sender of the packet or 0 if the sender did not sent their serial number.\n */\n public serial: number;\n /**\n * The received signal strength indicator (RSSI) of the packet.\n */\n public signal: number;\n }\n\n /**\n * Deprecated. Use onDataReceived() instead\n * Registers code to run when the radio receives a packet. Also takes the\n * received packet from the radio queue.\n */\n //% help=radio/on-data-packet-received blockHandlerKey=\"radioreceived\" deprecated=true\n //% mutate=objectdestructuring\n //% mutateText=Packet\n //% mutateDefaults=\"receivedNumber;receivedString:name,receivedNumber:value;receivedString\"\n //% blockId=radio_on_packet block=\"on radio received\" blockGap=8\n export function onDataPacketReceived(cb: (packet: Packet) => void) {\n onDataReceived(() => {\n receiveNumber();\n const packet = new Packet();\n packet.receivedNumber = receivedNumber();\n packet.time = receivedTime();\n packet.serial = receivedSerial();\n packet.receivedString = receivedString();\n packet.receivedBuffer = receivedBuffer();\n packet.signal = receivedSignalStrength();\n cb(packet)\n });\n }\n\n /**\n * Registers code to run when the radio receives a number. Deprecated, use\n * onReceivedNumber instead.\n */\n //% help=radio/on-received-number blockHandlerKey=\"radioreceived\"\n //% blockId=radio_on_number block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" deprecated=1\n export function onReceivedNumberDeprecated(cb: (receivedNumber: number) => void) {\n onReceivedNumber(cb);\n }\n\n /**\n * Registers code to run when the radio receives a key value pair. Deprecated, use\n * onReceivedValue instead.\n */\n //% help=radio/on-received-value blockHandlerKey=\"radioreceived\"\n //% blockId=radio_on_value block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" deprecated=1\n export function onReceivedValueDeprecated(cb: (name: string, value: number) => void) {\n onReceivedValue(cb);\n }\n\n /**\n * Registers code to run when the radio receives a string. Deprecated, use\n * onReceivedString instead.\n */\n //% help=radio/on-received-string blockHandlerKey=\"radioreceived\"\n //% blockId=radio_on_string block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" deprecated=1\n export function onReceivedStringDeprecated(cb: (receivedString: string) => void) {\n onReceivedString(cb);\n }\n\n /**\n * Registers code to run when the radio receives a buffer. Deprecated, use\n * onReceivedBuffer instead.\n */\n //% help=radio/on-received-buffer blockHandlerKey=\"radioreceived\" blockHidden=1\n //% blockId=radio_on_buffer block=\"on radio received\" blockGap=16\n //% useLoc=\"radio.onDataPacketReceived\" deprecated=1\n export function onReceivedBufferDeprecated(cb: (receivedBuffer: Buffer) => void) {\n onReceivedBuffer(cb);\n }\n\n /**\n * Returns the number payload from the last packet taken from the radio queue\n * (via ``receiveNumber``, ``receiveString``, etc) or 0 if that packet did not\n * contain a number.\n */\n //% help=radio/received-number deprecated=1\n export function receivedNumber(): number {\n return (lastPacket ? lastPacket.numberPayload : 0) || 0;\n }\n\n /**\n * Returns the serial number of the sender micro:bit from the last packet taken\n * from the radio queue (via ``receiveNumber``, ``receiveString``, etc) or 0 if\n * that packet did not send a serial number.\n */\n //% help=radio/received-serial deprecated=1\n export function receivedSerial(): number {\n return lastPacket ? lastPacket.serial : 0;\n }\n\n /**\n * Returns the string payload from the last packet taken from the radio queue\n * (via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\n * packet did not contain a string.\n */\n //% help=radio/received-string deprecated=1\n export function receivedString(): string {\n return (lastPacket ? lastPacket.stringPayload : \"\") || \"\";\n }\n\n /**\n * Returns the buffer payload from the last packet taken from the radio queue\n * (via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\n * packet did not contain a string.\n */\n //% help=radio/received-buffer deprecated=1\n export function receivedBuffer(): Buffer {\n return (lastPacket ? lastPacket.bufferPayload : null) || control.createBuffer(0);\n }\n\n /**\n * Returns the system time of the sender micro:bit at the moment when it sent the\n * last packet taken from the radio queue (via ``receiveNumber``,\n * ``receiveString``, etc).\n */\n //% help=radio/received-time deprecated=1\n export function receivedTime(): number {\n return lastPacket ? lastPacket.time : 0;\n }\n\n /**\n * Reads the next packet from the radio queue and returns the packet's number\n * payload or 0 if the packet did not contain a number.\n */\n //% help=radio/receive-number\n //% weight=46\n //% blockId=radio_datagram_receive block=\"radio receive number\" blockGap=8\n //% deprecated=true\n export function receiveNumber(): number {\n lastPacket = RadioPacket.getPacket(readRawPacket());\n return receivedNumber();\n }\n\n /**\n * Reads the next packet from the radio queue and returns the packet's string\n * payload or the empty string if the packet did not contain a string.\n */\n //% blockId=radio_datagram_receive_string block=\"radio receive string\" blockGap=8\n //% weight=44\n //% help=radio/receive-string\n //% deprecated=true\n export function receiveString(): string {\n lastPacket = RadioPacket.getPacket(readRawPacket());\n return receivedString();\n }\n\n /**\n * Gets the received signal strength indicator (RSSI) from the last packet taken\n * from the radio queue (via ``receiveNumber``, ``receiveString``, etc). Not supported in simulator.\n */\n //% help=radio/received-signal-strength\n //% weight=40\n //% blockId=radio_datagram_rssi block=\"radio received signal strength\"\n //% deprecated=true blockHidden=true\n export function receivedSignalStrength(): number {\n return lastPacket ? lastPacket.signal : 0;\n }\n\n /**\n * Reads the next packet from the radio queue and and writes it to serial\n * as JSON.\n */\n //% help=radio/write-value-to-serial\n //% weight=3\n //% blockId=radio_write_value_serial block=\"radio write value to serial\"\n //% deprecated=true\n export function writeValueToSerial() {\n const p = RadioPacket.getPacket(radio.readRawPacket());\n if(p)\n writeToSerial(p);\n }\n\n /**\n * Writes the last received packet to serial as JSON. This should be called\n * within an ``onDataPacketReceived`` callback.\n */\n //% help=radio/write-received-packet-to-serial\n //% weight=3\n //% blockId=radio_write_packet_serial block=\"radio write received packet to serial\"\n //% advanced=true deprecated=true\n export function writeReceivedPacketToSerial() {\n if (lastPacket) writeToSerial(lastPacket)\n }\n\n function writeToSerial(packet: RadioPacket) {\n serial.writeString(\"{\");\n serial.writeString(\"\\\"t\\\":\");\n serial.writeString(\"\" + packet.time);\n serial.writeString(\",\\\"s\\\":\");\n serial.writeString(\"\" + packet.serial);\n\n if (packet.hasString()) {\n serial.writeString(\",\\\"n\\\":\\\"\");\n serial.writeString(packet.stringPayload);\n serial.writeString(\"\\\"\");\n }\n if (packet.packetType == PACKET_TYPE_BUFFER) {\n serial.writeString(\",\\\"b\\\":\\\"\");\n // TODO: proper base64 encoding\n serial.writeString(packet.bufferPayload.toString());\n serial.writeString(\"\\\"\");\n }\n if (packet.hasNumber()) {\n serial.writeString(\",\\\"v\\\":\");\n serial.writeString(\"\" + packet.numberPayload);\n }\n\n serial.writeString(\"}\\r\\n\");\n }\n}"
2793
2793
  },
2794
2794
  "devices": {
@@ -2796,7 +2796,7 @@ var pxtTargetBundle = {
2796
2796
  "devices.cpp": "#include \"pxt.h\"\n#include \"MESEvents.h\"\n\nusing namespace pxt;\n\nenum class MesCameraEvent {\n //% block=\"take photo\"\n TakePhoto = MES_CAMERA_EVT_TAKE_PHOTO,\n //% block=\"start video capture\"\n StartVideoCapture = MES_CAMERA_EVT_START_VIDEO_CAPTURE,\n //% block=\"stop video capture\"\n StopVideoCapture = MES_CAMERA_EVT_STOP_VIDEO_CAPTURE,\n //% block=\"toggle front-rear\"\n ToggleFrontRear = MES_CAMERA_EVT_TOGGLE_FRONT_REAR,\n //% block=\"launch photo mode\"\n LaunchPhotoMode = MES_CAMERA_EVT_LAUNCH_PHOTO_MODE,\n //% block=\"launch video mode\"\n LaunchVideoMode = MES_CAMERA_EVT_LAUNCH_VIDEO_MODE,\n //% block=\"stop photo mode\"\n StopPhotoMode = MES_CAMERA_EVT_STOP_PHOTO_MODE,\n //% block=\"stop video mode\"\n StopVideoMode = MES_CAMERA_EVT_STOP_VIDEO_MODE,\n};\n\nenum class MesAlertEvent {\n //% block=\"display toast\"\n DisplayToast = MES_ALERT_EVT_DISPLAY_TOAST,\n //% block=\"vibrate\"\n Vibrate = MES_ALERT_EVT_VIBRATE,\n //% block=\"play sound\"\n PlaySound = MES_ALERT_EVT_PLAY_SOUND,\n //% block=\"play ring tone\"\n PlayRingtone = MES_ALERT_EVT_PLAY_RINGTONE,\n //% block=\"find my phone\"\n FindMyPhone = MES_ALERT_EVT_FIND_MY_PHONE,\n //% block=\"ring alarm\"\n RingAlarm = MES_ALERT_EVT_ALARM1,\n //% block=\"ring alarm 2\"\n RingAlarm2 = MES_ALERT_EVT_ALARM2,\n //% block=\"ring alarm 3\"\n RingAlarm3 = MES_ALERT_EVT_ALARM3,\n //% block=\"ring alarm 4\"\n RingAlarm4 = MES_ALERT_EVT_ALARM4,\n //% block=\"ring alarm 5\"\n RingAlarm5 = MES_ALERT_EVT_ALARM5,\n //% block=\"ring alarm 6\"\n RingAlarm6 = MES_ALERT_EVT_ALARM6,\n};\n\nenum class MesDeviceInfo {\n //% block=\"incoming call\"\n IncomingCall = MES_DEVICE_INCOMING_CALL,\n //% block=\"incoming message\"\n IncomingMessage = MES_DEVICE_INCOMING_MESSAGE,\n //% block=\"orientation landscape\"\n OrientationLandscape = MES_DEVICE_ORIENTATION_LANDSCAPE,\n //% block=\"orientation portrait\"\n OrientationPortrait = MES_DEVICE_ORIENTATION_PORTRAIT,\n //% block=\"shaken\"\n Shaken = MES_DEVICE_GESTURE_DEVICE_SHAKEN,\n //% block=\"display off\"\n DisplayOff = MES_DEVICE_DISPLAY_OFF,\n //% block=\"display on\"\n DisplayOn = MES_DEVICE_DISPLAY_ON,\n};\n\nenum class MesRemoteControlEvent {\n //% block=\"play\"\n play = MES_REMOTE_CONTROL_EVT_PLAY,\n //% block=\"pause\"\n pause = MES_REMOTE_CONTROL_EVT_PAUSE,\n //% block=\"stop\"\n stop = MES_REMOTE_CONTROL_EVT_STOP,\n //% block=\"next track\"\n nextTrack = MES_REMOTE_CONTROL_EVT_NEXTTRACK,\n //% block=\"previous track\"\n previousTrack = MES_REMOTE_CONTROL_EVT_PREVTRACK,\n //% block=\"forward\"\n forward = MES_REMOTE_CONTROL_EVT_FORWARD,\n //% block=\"rewind\"\n rewind = MES_REMOTE_CONTROL_EVT_REWIND,\n //% block=\"volume up\"\n volumeUp = MES_REMOTE_CONTROL_EVT_VOLUMEUP,\n //% block=\"volume down\"\n volumeDown = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN,\n};\n\n/**\n * Control a phone with the BBC micro:bit via Bluetooth.\n */\n//% color=#008272 weight=80 icon=\"\\uf10b\"\nnamespace devices {\n\n static int _signalStrength = -1;\n static void signalStrengthHandler(MicroBitEvent ev) { \n // keep in sync with MESEvents.h\n _signalStrength = ev.value - 1; \n }\n static void initSignalStrength() {\n if (_signalStrength < 0) {\n _signalStrength = 0;\n uBit.messageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);\n } \n }\n \n /**\n * Returns the last signal strength reported by the paired device.\n */\n //% help=devices/signal-strength weight=24\n //% blockId=devices_signal_strength block=\"signal strength\" blockGap=14 icon=\"\\uf012\" blockGap=14\n int signalStrength() {\n initSignalStrength();\n return _signalStrength;\n }\n\n /**\n * Registers code to run when the device notifies about a change of signal strength.\n * @param body Code run when the signal strength changes.\n */\n //% weight=23 help=devices/on-signal-strength-changed\n //% blockId=devices_signal_strength_changed_event block=\"on signal strength changed\" icon=\"\\uf012\"\n void onSignalStrengthChanged(Action body) {\n initSignalStrength(); \n registerWithDal(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, body);\n }\n}\n",
2797
2797
  "devices.ts": "\nnamespace devices {\n /**\n * Sends a ``camera`` command to the parent device.\n * @param event event description\n */\n //% weight=30 help=devices/tell-camera-to\n //% blockId=devices_camera icon=\"\\uf030\" block=\"tell camera to|%property\" blockGap=8\n export function tellCameraTo(event: MesCameraEvent) {\n control.raiseEvent(DAL.MES_CAMERA_ID, event);\n }\n\n /**\n * Sends a ``remote control`` command to the parent device.\n * @param event event description\n */\n //% weight=29 help=devices/tell-remote-control-to\n //% blockId=devices_remote_control block=\"tell remote control to|%property\" blockGap=14 icon=\"\\uf144\"\n export function tellRemoteControlTo(event: MesRemoteControlEvent) {\n control.raiseEvent(DAL.MES_REMOTE_CONTROL_ID, event);\n }\n\n /**\n * Sends an ``alert`` command to the parent device.\n * @param event event description\n */\n //% weight=27 help=devices/raise-alert-to\n //% blockId=devices_alert block=\"raise alert to|%property\" icon=\"\\uf0f3\"\n export function raiseAlertTo(event: MesAlertEvent) {\n control.raiseEvent(DAL.MES_ALERTS_ID, event);\n }\n\n /**\n * Registers code to run when the device notifies about a particular event.\n * @param event event description\n * @param body code handler when event is triggered\n */\n //% help=devices/on-notified weight=26\n //% blockId=devices_device_info_event block=\"on notified|%event\" icon=\"\\uf10a\"\n export function onNotified(event: MesDeviceInfo, body: () => void) {\n control.onEvent(DAL.MES_DEVICE_INFO_ID, event, body);\n }\n\n /**\n * Register code to run when the micro:bit receives a command from the paired gamepad.\n * @param name button name\n * @param body code to run when button is pressed\n */\n //% help=devices/on-gamepad-button weight=40\n //% weight=25\n //% blockId=devices_gamepad_event block=\"on gamepad button|%NAME\" icon=\"\\uf11b\"\n export function onGamepadButton(name: MesDpadButtonInfo, body: () => void) {\n control.onEvent(DAL.MES_DPAD_CONTROLLER_ID, name, body);\n }\n}",
2798
2798
  "enums.d.ts": "// Auto-generated. Do not edit.\n\n\n declare const enum MesCameraEvent {\n //% block=\"take photo\"\n TakePhoto = 3, // MES_CAMERA_EVT_TAKE_PHOTO\n //% block=\"start video capture\"\n StartVideoCapture = 4, // MES_CAMERA_EVT_START_VIDEO_CAPTURE\n //% block=\"stop video capture\"\n StopVideoCapture = 5, // MES_CAMERA_EVT_STOP_VIDEO_CAPTURE\n //% block=\"toggle front-rear\"\n ToggleFrontRear = 8, // MES_CAMERA_EVT_TOGGLE_FRONT_REAR\n //% block=\"launch photo mode\"\n LaunchPhotoMode = 1, // MES_CAMERA_EVT_LAUNCH_PHOTO_MODE\n //% block=\"launch video mode\"\n LaunchVideoMode = 2, // MES_CAMERA_EVT_LAUNCH_VIDEO_MODE\n //% block=\"stop photo mode\"\n StopPhotoMode = 6, // MES_CAMERA_EVT_STOP_PHOTO_MODE\n //% block=\"stop video mode\"\n StopVideoMode = 7, // MES_CAMERA_EVT_STOP_VIDEO_MODE\n }\n\n\n declare const enum MesAlertEvent {\n //% block=\"display toast\"\n DisplayToast = 1, // MES_ALERT_EVT_DISPLAY_TOAST\n //% block=\"vibrate\"\n Vibrate = 2, // MES_ALERT_EVT_VIBRATE\n //% block=\"play sound\"\n PlaySound = 3, // MES_ALERT_EVT_PLAY_SOUND\n //% block=\"play ring tone\"\n PlayRingtone = 4, // MES_ALERT_EVT_PLAY_RINGTONE\n //% block=\"find my phone\"\n FindMyPhone = 5, // MES_ALERT_EVT_FIND_MY_PHONE\n //% block=\"ring alarm\"\n RingAlarm = 6, // MES_ALERT_EVT_ALARM1\n //% block=\"ring alarm 2\"\n RingAlarm2 = 7, // MES_ALERT_EVT_ALARM2\n //% block=\"ring alarm 3\"\n RingAlarm3 = 8, // MES_ALERT_EVT_ALARM3\n //% block=\"ring alarm 4\"\n RingAlarm4 = 9, // MES_ALERT_EVT_ALARM4\n //% block=\"ring alarm 5\"\n RingAlarm5 = 10, // MES_ALERT_EVT_ALARM5\n //% block=\"ring alarm 6\"\n RingAlarm6 = 11, // MES_ALERT_EVT_ALARM6\n }\n\n\n declare const enum MesDeviceInfo {\n //% block=\"incoming call\"\n IncomingCall = 7, // MES_DEVICE_INCOMING_CALL\n //% block=\"incoming message\"\n IncomingMessage = 8, // MES_DEVICE_INCOMING_MESSAGE\n //% block=\"orientation landscape\"\n OrientationLandscape = 1, // MES_DEVICE_ORIENTATION_LANDSCAPE\n //% block=\"orientation portrait\"\n OrientationPortrait = 2, // MES_DEVICE_ORIENTATION_PORTRAIT\n //% block=\"shaken\"\n Shaken = 4, // MES_DEVICE_GESTURE_DEVICE_SHAKEN\n //% block=\"display off\"\n DisplayOff = 5, // MES_DEVICE_DISPLAY_OFF\n //% block=\"display on\"\n DisplayOn = 6, // MES_DEVICE_DISPLAY_ON\n }\n\n\n declare const enum MesRemoteControlEvent {\n //% block=\"play\"\n play = 1, // MES_REMOTE_CONTROL_EVT_PLAY\n //% block=\"pause\"\n pause = 2, // MES_REMOTE_CONTROL_EVT_PAUSE\n //% block=\"stop\"\n stop = 3, // MES_REMOTE_CONTROL_EVT_STOP\n //% block=\"next track\"\n nextTrack = 4, // MES_REMOTE_CONTROL_EVT_NEXTTRACK\n //% block=\"previous track\"\n previousTrack = 5, // MES_REMOTE_CONTROL_EVT_PREVTRACK\n //% block=\"forward\"\n forward = 6, // MES_REMOTE_CONTROL_EVT_FORWARD\n //% block=\"rewind\"\n rewind = 7, // MES_REMOTE_CONTROL_EVT_REWIND\n //% block=\"volume up\"\n volumeUp = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP\n //% block=\"volume down\"\n volumeDown = 9, // MES_REMOTE_CONTROL_EVT_VOLUMEDOWN\n }\ndeclare namespace devices {\n}\n\n// Auto-generated. Do not edit. Really.\n",
2799
- "pxt.json": "{\n \"name\": \"devices\",\n \"description\": \"BETA - Camera, remote control and other Bluetooth services. App required.\",\n \"dependencies\": {\n \"core\": \"*\",\n \"bluetooth\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"devices.cpp\",\n \"devices.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"icon\": \"./static/packages/devices/icon.png\",\n \"hidden\": true\n}\n",
2799
+ "pxt.json": "{\n \"name\": \"devices\",\n \"description\": \"BETA - Camera, remote control and other Bluetooth services. App required.\",\n \"dependencies\": {\n \"core\": \"*\",\n \"bluetooth\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"devices.cpp\",\n \"devices.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"icon\": \"./static/packages/devices/icon.png\",\n \"hidden\": true\n}\n",
2800
2800
  "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n /**\n * Control a phone with the BBC micro:bit via Bluetooth.\n */\n //% color=#008272 weight=80 icon=\"\\uf10b\"\ndeclare namespace devices {\n\n /**\n * Returns the last signal strength reported by the paired device.\n */\n //% help=devices/signal-strength weight=24\n //% blockId=devices_signal_strength block=\"signal strength\" blockGap=14 icon=\"\\uf012\" blockGap=14 shim=devices::signalStrength\n function signalStrength(): int32;\n\n /**\n * Registers code to run when the device notifies about a change of signal strength.\n * @param body Code run when the signal strength changes.\n */\n //% weight=23 help=devices/on-signal-strength-changed\n //% blockId=devices_signal_strength_changed_event block=\"on signal strength changed\" icon=\"\\uf012\" shim=devices::onSignalStrengthChanged\n function onSignalStrengthChanged(body: () => void): void;\n}\n\n// Auto-generated. Do not edit. Really.\n"
2801
2801
  },
2802
2802
  "bluetooth": {
@@ -2806,18 +2806,18 @@ var pxtTargetBundle = {
2806
2806
  "bluetooth.cpp": "#include \"pxt.h\"\n#include \"MESEvents.h\"\n#include \"MicroBitUARTService.h\"\n#include \"BLEHF2Service.h\"\n\nusing namespace pxt;\n\n/**\n * Support for additional Bluetooth services.\n */\n//% color=#0082FB weight=96 icon=\"\\uf294\"\nnamespace bluetooth {\n MicroBitUARTService *uart = NULL;\n BLEHF2Service* pHF2 = NULL;\n\n //%\n void __log(int priority, String msg) {\n if (NULL == pHF2)\n pHF2 = new BLEHF2Service(*uBit.ble);\n pHF2->sendSerial(msg->getUTF8Data(), msg->getUTF8Size(), false);\n }\n\n /**\n * Starts the Bluetooth accelerometer service\n */\n //% help=bluetooth/start-accelerometer-service\n //% blockId=bluetooth_start_accelerometer_service block=\"bluetooth accelerometer service\"\n //% parts=\"bluetooth\" weight=90 blockGap=8\n void startAccelerometerService() {\n new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer); \n } \n\n /**\n * Starts the Bluetooth button service\n */\n //% help=bluetooth/start-button-service\n //% blockId=bluetooth_start_button_service block=\"bluetooth button service\" blockGap=8\n //% parts=\"bluetooth\" weight=89\n void startButtonService() {\n new MicroBitButtonService(*uBit.ble); \n }\n\n /**\n * Starts the Bluetooth IO pin service.\n */\n //% help=bluetooth/start-io-pin-service\n //% blockId=bluetooth_start_io_pin_service block=\"bluetooth io pin service\" blockGap=8\n //% parts=\"bluetooth\" weight=88\n void startIOPinService() {\n new MicroBitIOPinService(*uBit.ble, uBit.io);\n }\n\n /**\n * Starts the Bluetooth LED service\n */\n //% help=bluetooth/start-led-service\n //% blockId=bluetooth_start_led_service block=\"bluetooth led service\" blockGap=8\n //% parts=\"bluetooth\" weight=87\n void startLEDService() {\n new MicroBitLEDService(*uBit.ble, uBit.display);\n }\n\n /**\n * Starts the Bluetooth temperature service\n */\n //% help=bluetooth/start-temperature-service\n //% blockId=bluetooth_start_temperature_service block=\"bluetooth temperature service\" blockGap=8\n //% parts=\"bluetooth\" weight=86\n void startTemperatureService() { \n new MicroBitTemperatureService(*uBit.ble, uBit.thermometer); \n }\n\n /**\n * Starts the Bluetooth magnetometer service\n */\n //% help=bluetooth/start-magnetometer-service\n //% blockId=bluetooth_start_magnetometer_service block=\"bluetooth magnetometer service\"\n //% parts=\"bluetooth\" weight=85\n void startMagnetometerService() { \n new MicroBitMagnetometerService(*uBit.ble, uBit.compass); \n }\n\n\n /**\n * Starts the Bluetooth UART service\n */\n //% help=bluetooth/start-uart-service\n //% blockId=bluetooth_start_uart_service block=\"bluetooth uart service\"\n //% parts=\"bluetooth\" advanced=true\n void startUartService() {\n if (uart) return;\n // 61 octet buffer size is 3 x (MTU - 3) + 1\n // MTU on nRF51822 is 23 octets. 3 are used by Attribute Protocol header data leaving 20 octets for payload\n // So we allow a RX buffer that can contain 3 x max length messages plus one octet for a terminator character\n uart = new MicroBitUARTService(*uBit.ble, 61, 60);\n }\n \n //%\n void uartWriteString(String data) {\n startUartService();\n \tuart->send(MSTR(data));\n } \n\n //%\n String uartReadUntil(String del) {\n startUartService();\n return PSTR(uart->readUntil(MSTR(del)));\n } \n\n\n /**\n * Sends a buffer of data via Bluetooth UART\n */\n //%\n void uartWriteBuffer(Buffer buffer) {\n startUartService();\n uart->send(buffer->data, buffer->length);\n }\n\n /**\n * Reads buffered UART data into a buffer\n */\n //%\n Buffer uartReadBuffer() {\n startUartService();\n int bytes = uart->rxBufferedSize();\n auto buffer = mkBuffer(NULL, bytes);\n auto res = buffer;\n registerGCObj(buffer);\n int read = uart->read(buffer->data, buffer->length);\n // read failed\n if (read < 0) {\n res = mkBuffer(NULL, 0);\n } else if (read != buffer->length) {\n // could not fill the buffer\n res = mkBuffer(buffer->data, read); \n }\n unregisterGCObj(buffer);\n return res;\n }\n\n /**\n * Registers an event to be fired when one of the delimiter is matched.\n * @param delimiters the characters to match received characters against.\n */\n //% help=bluetooth/on-uart-data-received\n //% weight=18 blockId=bluetooth_on_data_received block=\"bluetooth|on data received %delimiters=serial_delimiter_conv\"\n void onUartDataReceived(String delimiters, Action body) {\n startUartService();\n uart->eventOn(MSTR(delimiters));\n registerWithDal(MICROBIT_ID_BLE_UART, MICROBIT_UART_S_EVT_DELIM_MATCH, body);\n }\n\n /**\n * Register code to run when the micro:bit is connected to over Bluetooth\n * @param body Code to run when a Bluetooth connection is established\n */\n //% help=bluetooth/on-bluetooth-connected weight=20\n //% blockId=bluetooth_on_connected block=\"on bluetooth connected\" blockGap=8\n //% parts=\"bluetooth\"\n void onBluetoothConnected(Action body) {\n registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body);\n } \n\n /**\n * Register code to run when a bluetooth connection to the micro:bit is lost\n * @param body Code to run when a Bluetooth connection is lost\n */\n //% help=bluetooth/on-bluetooth-disconnected weight=19\n //% blockId=bluetooth_on_disconnected block=\"on bluetooth disconnected\"\n //% parts=\"bluetooth\"\n void onBluetoothDisconnected(Action body) {\n registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body);\n } \n\n const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};\n /**\n * Advertise an Eddystone URL\n\t* @param url the url to transmit. Must be no longer than the supported eddystone url length, eg: \"https://makecode.com\"\n\t* @param power power level between 0 and 7, eg: 7\n * @param connectable true to keep bluetooth connectable for other services, false otherwise.\n */\n //% blockId=eddystone_advertise_url block=\"bluetooth advertise url %url|with power %power|connectable %connectable\"\n //% parts=bluetooth weight=11 blockGap=8\n //% help=bluetooth/advertise-url blockExternalInputs=1\n //% hidden=1 deprecated=1\n void advertiseUrl(String url, int power, bool connectable) {\n#if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_URL)\n power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));\n int8_t level = CALIBRATED_POWERS[power];\n uBit.bleManager.advertiseEddystoneUrl(MSTR(url), level, connectable);\n uBit.bleManager.setTransmitPower(power);\n#endif\n }\n\n /**\n * Advertise an Eddystone UID\n\t* @param nsAndInstance 16 bytes buffer of namespace (bytes 0-9) and instance (bytes 10-15)\n\t* @param power power level between 0 and 7, eg: 7\n * @param connectable true to keep bluetooth connectable for other services, false otherwise.\n */\n //% parts=bluetooth weight=12 advanced=true deprecated=1\n void advertiseUidBuffer(Buffer nsAndInstance, int power, bool connectable) {\n#if CONFIG_ENABLED(MICROBIT_BLE_EDDYSTONE_UID) \n auto buf = nsAndInstance;\n if (buf->length != 16) return;\n\n power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));\n int8_t level = CALIBRATED_POWERS[power];\n uBit.bleManager.advertiseEddystoneUid((const char*)buf->data, (const char*)buf->data + 10, level, connectable);\n#endif\n }\n\n /**\n * Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).\n * @param power power level between 0 (minimal) and 7 (maximum), eg: 7.\n */\n //% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true\n //% blockId=bluetooth_settransmitpower block=\"bluetooth set transmit power %power\"\n void setTransmitPower(int power) {\n uBit.bleManager.setTransmitPower(min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power)));\n }\n\n /**\n * Stops advertising Eddystone end points\n */\n //% blockId=eddystone_stop_advertising block=\"bluetooth stop advertising\"\n //% parts=bluetooth weight=10\n //% help=bluetooth/stop-advertising advanced=true\n //% hidden=1 deprecated=1\n void stopAdvertising() {\n uBit.bleManager.stopAdvertising();\n } \n}",
2807
2807
  "bluetooth.ts": "/// <reference no-default-lib=\"true\"/>\n/**\n * Support for additional Bluetooth services.\n */\n//% color=#007EF4 weight=96 icon=\"\\uf294\"\nnamespace bluetooth {\n export let NEW_LINE = \"\\r\\n\";\n\n /**\n * Internal use\n */\n //% shim=bluetooth::__log\n export function __log(priority: number, msg: string) {\n return;\n }\n console.addListener(function (_pri, msg) { __log(_pri, msg) });\n\n /**\n * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.\n */\n //% help=bluetooth/uart-write-string weight=80\n //% blockId=bluetooth_uart_write block=\"bluetooth uart|write string %data\" blockGap=8\n //% parts=\"bluetooth\" shim=bluetooth::uartWriteString advanced=true\n export function uartWriteString(data: string): void {\n console.log(data)\n }\n\n /**\n * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.\n */\n //% help=bluetooth/uart-write-line weight=79\n //% blockId=bluetooth_uart_line block=\"bluetooth uart|write line %data\" blockGap=8\n //% parts=\"bluetooth\" advanced=true\n export function uartWriteLine(data: string): void {\n uartWriteString(data + serial.NEW_LINE);\n }\n\n /**\n * Prints a numeric value to the serial\n */\n //% help=bluetooth/uart-write-number weight=79\n //% weight=89 blockGap=8 advanced=true\n //% blockId=bluetooth_uart_writenumber block=\"bluetooth uart|write number %value\"\n export function uartWriteNumber(value: number): void {\n uartWriteString(value.toString());\n }\n\n /**\n * Writes a ``name: value`` pair line to the serial.\n * @param name name of the value stream, eg: x\n * @param value to write\n */\n //% weight=88 weight=78\n //% help=bluetooth/uart-write-value advanced=true\n //% blockId=bluetooth_uart_writevalue block=\"bluetooth uart|write value %name|= %value\"\n export function uartWriteValue(name: string, value: number): void {\n uartWriteString((name ? name + \":\" : \"\") + value + NEW_LINE);\n }\n\n /**\n * Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered.\n */\n //% help=bluetooth/uart-read-until weight=75\n //% blockId=bluetooth_uart_read block=\"bluetooth uart|read until %del=serial_delimiter_conv\"\n //% parts=\"bluetooth\" shim=bluetooth::uartReadUntil advanced=true\n export function uartReadUntil(del: string): string {\n // dummy implementation for simulator\n return \"\"\n }\n\n /**\n * Advertise an Eddystone UID\n * @param ns 4 last bytes of the namespace uid\n * @param instance 4 last bytes of the instance uid\n * @param power power level between 0 and 7, eg: 7\n * @param connectable true to keep bluetooth connectable for other services, false otherwise.\n */\n //% blockId=eddystone_advertise_uid block=\"bluetooth advertise UID|namespace (bytes 6-9)%ns|instance (bytes 2-6)%instance|with power %power|connectable %connectable\"\n //% parts=bluetooth weight=12 blockGap=8\n //% help=bluetooth/advertise-uid blockExternalInputs=1\n //% hidden=1 deprecated=1\n export function advertiseUid(ns: number, instance: number, power: number, connectable: boolean) {\n const buf = pins.createBuffer(16);\n buf.setNumber(NumberFormat.Int32BE, 6, ns);\n buf.setNumber(NumberFormat.Int32BE, 12, instance);\n bluetooth.advertiseUidBuffer(buf, power, connectable);\n }\n}\n",
2808
2808
  "enums.d.ts": "// Auto-generated. Do not edit.\ndeclare namespace bluetooth {\n}\n\n// Auto-generated. Do not edit. Really.\n",
2809
- "pxt.json": "{\n \"name\": \"bluetooth\",\n \"description\": \"Bluetooth services\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"bluetooth.ts\",\n \"bluetooth.cpp\",\n \"BLEHF2Service.h\",\n \"BLEHF2Service.cpp\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"weight\": 10,\n \"searchOnly\": true,\n \"icon\": \"./static/packages/bluetooth/icon.png\",\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"enabled\": 1\n }\n }\n },\n \"optionalConfig\": {\n \"microbit-dal\": {\n \"stack_size\": 1280,\n \"gatt_table_size\": \"0x700\"\n }\n },\n \"userConfigs\": [\n {\n \"description\": \"Disable Bluetooth Event Service\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"event_service\": 0\n }\n }\n }\n }\n ]\n }\n}\n",
2809
+ "pxt.json": "{\n \"name\": \"bluetooth\",\n \"description\": \"Bluetooth services\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"bluetooth.ts\",\n \"bluetooth.cpp\",\n \"BLEHF2Service.h\",\n \"BLEHF2Service.cpp\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"weight\": 10,\n \"searchOnly\": true,\n \"icon\": \"./static/packages/bluetooth/icon.png\",\n \"yotta\": {\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"enabled\": 1\n }\n }\n },\n \"optionalConfig\": {\n \"microbit-dal\": {\n \"stack_size\": 1280,\n \"gatt_table_size\": \"0x700\"\n }\n },\n \"userConfigs\": [\n {\n \"description\": \"Disable Bluetooth Event Service\",\n \"config\": {\n \"microbit-dal\": {\n \"bluetooth\": {\n \"event_service\": 0\n }\n }\n }\n }\n ]\n }\n}\n",
2810
2810
  "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n /**\n * Support for additional Bluetooth services.\n */\n //% color=#0082FB weight=96 icon=\"\\uf294\"\ndeclare namespace bluetooth {\n\n /**\n * Starts the Bluetooth accelerometer service\n */\n //% help=bluetooth/start-accelerometer-service\n //% blockId=bluetooth_start_accelerometer_service block=\"bluetooth accelerometer service\"\n //% parts=\"bluetooth\" weight=90 blockGap=8 shim=bluetooth::startAccelerometerService\n function startAccelerometerService(): void;\n\n /**\n * Starts the Bluetooth button service\n */\n //% help=bluetooth/start-button-service\n //% blockId=bluetooth_start_button_service block=\"bluetooth button service\" blockGap=8\n //% parts=\"bluetooth\" weight=89 shim=bluetooth::startButtonService\n function startButtonService(): void;\n\n /**\n * Starts the Bluetooth IO pin service.\n */\n //% help=bluetooth/start-io-pin-service\n //% blockId=bluetooth_start_io_pin_service block=\"bluetooth io pin service\" blockGap=8\n //% parts=\"bluetooth\" weight=88 shim=bluetooth::startIOPinService\n function startIOPinService(): void;\n\n /**\n * Starts the Bluetooth LED service\n */\n //% help=bluetooth/start-led-service\n //% blockId=bluetooth_start_led_service block=\"bluetooth led service\" blockGap=8\n //% parts=\"bluetooth\" weight=87 shim=bluetooth::startLEDService\n function startLEDService(): void;\n\n /**\n * Starts the Bluetooth temperature service\n */\n //% help=bluetooth/start-temperature-service\n //% blockId=bluetooth_start_temperature_service block=\"bluetooth temperature service\" blockGap=8\n //% parts=\"bluetooth\" weight=86 shim=bluetooth::startTemperatureService\n function startTemperatureService(): void;\n\n /**\n * Starts the Bluetooth magnetometer service\n */\n //% help=bluetooth/start-magnetometer-service\n //% blockId=bluetooth_start_magnetometer_service block=\"bluetooth magnetometer service\"\n //% parts=\"bluetooth\" weight=85 shim=bluetooth::startMagnetometerService\n function startMagnetometerService(): void;\n\n /**\n * Starts the Bluetooth UART service\n */\n //% help=bluetooth/start-uart-service\n //% blockId=bluetooth_start_uart_service block=\"bluetooth uart service\"\n //% parts=\"bluetooth\" advanced=true shim=bluetooth::startUartService\n function startUartService(): void;\n\n /**\n * Sends a buffer of data via Bluetooth UART\n */\n //% shim=bluetooth::uartWriteBuffer\n function uartWriteBuffer(buffer: Buffer): void;\n\n /**\n * Reads buffered UART data into a buffer\n */\n //% shim=bluetooth::uartReadBuffer\n function uartReadBuffer(): Buffer;\n\n /**\n * Registers an event to be fired when one of the delimiter is matched.\n * @param delimiters the characters to match received characters against.\n */\n //% help=bluetooth/on-uart-data-received\n //% weight=18 blockId=bluetooth_on_data_received block=\"bluetooth|on data received %delimiters=serial_delimiter_conv\" shim=bluetooth::onUartDataReceived\n function onUartDataReceived(delimiters: string, body: () => void): void;\n\n /**\n * Register code to run when the micro:bit is connected to over Bluetooth\n * @param body Code to run when a Bluetooth connection is established\n */\n //% help=bluetooth/on-bluetooth-connected weight=20\n //% blockId=bluetooth_on_connected block=\"on bluetooth connected\" blockGap=8\n //% parts=\"bluetooth\" shim=bluetooth::onBluetoothConnected\n function onBluetoothConnected(body: () => void): void;\n\n /**\n * Register code to run when a bluetooth connection to the micro:bit is lost\n * @param body Code to run when a Bluetooth connection is lost\n */\n //% help=bluetooth/on-bluetooth-disconnected weight=19\n //% blockId=bluetooth_on_disconnected block=\"on bluetooth disconnected\"\n //% parts=\"bluetooth\" shim=bluetooth::onBluetoothDisconnected\n function onBluetoothDisconnected(body: () => void): void;\n\n /**\n * Advertise an Eddystone URL\n * @param url the url to transmit. Must be no longer than the supported eddystone url length, eg: \"https://makecode.com\"\n * @param power power level between 0 and 7, eg: 7\n * @param connectable true to keep bluetooth connectable for other services, false otherwise.\n */\n //% blockId=eddystone_advertise_url block=\"bluetooth advertise url %url|with power %power|connectable %connectable\"\n //% parts=bluetooth weight=11 blockGap=8\n //% help=bluetooth/advertise-url blockExternalInputs=1\n //% hidden=1 deprecated=1 shim=bluetooth::advertiseUrl\n function advertiseUrl(url: string, power: int32, connectable: boolean): void;\n\n /**\n * Advertise an Eddystone UID\n * @param nsAndInstance 16 bytes buffer of namespace (bytes 0-9) and instance (bytes 10-15)\n * @param power power level between 0 and 7, eg: 7\n * @param connectable true to keep bluetooth connectable for other services, false otherwise.\n */\n //% parts=bluetooth weight=12 advanced=true deprecated=1 shim=bluetooth::advertiseUidBuffer\n function advertiseUidBuffer(nsAndInstance: Buffer, power: int32, connectable: boolean): void;\n\n /**\n * Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).\n * @param power power level between 0 (minimal) and 7 (maximum), eg: 7.\n */\n //% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true\n //% blockId=bluetooth_settransmitpower block=\"bluetooth set transmit power %power\" shim=bluetooth::setTransmitPower\n function setTransmitPower(power: int32): void;\n\n /**\n * Stops advertising Eddystone end points\n */\n //% blockId=eddystone_stop_advertising block=\"bluetooth stop advertising\"\n //% parts=bluetooth weight=10\n //% help=bluetooth/stop-advertising advanced=true\n //% hidden=1 deprecated=1 shim=bluetooth::stopAdvertising\n function stopAdvertising(): void;\n}\n\n// Auto-generated. Do not edit. Really.\n"
2811
2811
  },
2812
2812
  "servo": {
2813
2813
  "README.md": "# Servo\n\nA small micro-servo library.",
2814
2814
  "ns.ts": "/**\n * Control micro servos\n */\n//% color=\"#03AA74\" weight=88 icon=\"\\uf021\"\nnamespace servos {\n}",
2815
- "pxt.json": "{\n \"name\": \"servo\",\n \"description\": \"A micro-servo library\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"servo.ts\",\n \"ns.ts\",\n \"targetoverrides.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"icon\": \"/static/libs/servo.png\"\n}\n",
2815
+ "pxt.json": "{\n \"name\": \"servo\",\n \"description\": \"A micro-servo library\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"servo.ts\",\n \"ns.ts\",\n \"targetoverrides.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"icon\": \"/static/libs/servo.png\"\n}\n",
2816
2816
  "servo.ts": "/**\n * Control micro servos\n */\n//% color=\"#03AA74\" weight=88 icon=\"\\uf021\" blockGap=8\n//% groups='[\"Positional\", \"Continuous\", \"Configuration\"]'\nnamespace servos {\n //% fixedInstances\n export class Servo {\n private _minAngle: number;\n private _maxAngle: number;\n private _stopOnNeutral: boolean;\n private _angle: number;\n\n constructor() {\n this._angle = undefined;\n this._minAngle = 0;\n this._maxAngle = 180;\n this._stopOnNeutral = false;\n }\n\n private clampDegrees(degrees: number): number {\n degrees = degrees | 0;\n degrees = Math.clamp(this._minAngle, this._maxAngle, degrees);\n return degrees;\n }\n\n /**\n * Set the servo angle\n */\n //% weight=100 help=servos/set-angle\n //% blockId=servoservosetangle block=\"set %servo angle to %degrees=protractorPicker °\"\n //% degrees.defl=90\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n //% blockGap=8\n //% parts=microservo trackArgs=0\n //% group=\"Positional\"\n setAngle(degrees: number) {\n degrees = this.clampDegrees(degrees);\n this.internalSetContinuous(false);\n this._angle = this.internalSetAngle(degrees);\n }\n\n get angle() {\n return this._angle || 90;\n }\n\n protected internalSetContinuous(continuous: boolean): void {\n\n }\n\n protected internalSetAngle(angle: number): number {\n return 0;\n }\n\n /**\n * Set the throttle on a continuous servo\n * @param speed the throttle of the motor from -100% to 100%\n */\n //% weight=99 help=servos/run\n //% blockId=servoservorun block=\"continuous %servo run at %speed=speedPicker \\\\%\"\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n //% parts=microservo trackArgs=0\n //% group=\"Continuous\"\n //% blockGap=8\n run(speed: number): void {\n const degrees = this.clampDegrees(Math.map(speed, -100, 100, this._minAngle, this._maxAngle));\n const neutral = (this.maxAngle - this.minAngle) >> 1;\n this.internalSetContinuous(true);\n if (this._stopOnNeutral && degrees == neutral)\n this.stop();\n else\n this._angle = this.internalSetAngle(degrees);\n }\n\n /**\n * Set the pulse width to the servo in microseconds\n * @param micros the width of the pulse in microseconds\n */\n\n //% weight=10 help=servos/set-pulse\n //% blockId=servoservosetpulse block=\"set %servo pulse to %micros μs\"\n //% micros.min=500 micros.max=2500\n //% micros.defl=1500\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n //% parts=microservo trackArgs=0\n //% group=\"Configuration\"\n //% blockGap=8\n setPulse(micros: number) {\n micros = micros | 0;\n micros = Math.clamp(500, 2500, micros);\n this.internalSetPulse(micros);\n }\n\n protected internalSetPulse(micros: number): void {\n\n }\n\n /**\n * Stop sending commands to the servo so that its rotation will stop at the current position.\n */\n // On a normal servo this will stop the servo where it is, rather than return it to neutral position.\n // It will also not provide any holding force.\n //% weight=10 help=servos/stop\n //% blockId=servoservostop block=\"stop %servo\"\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n //% parts=microservo trackArgs=0\n //% group=\"Continuous\"\n //% blockGap=8\n stop() {\n if (this._angle !== undefined)\n this.internalStop();\n }\n\n /**\n * Gets the minimum angle for the servo\n */\n public get minAngle() {\n return this._minAngle;\n }\n\n /**\n * Gets the maximum angle for the servo\n */\n public get maxAngle() {\n return this._maxAngle;\n }\n\n /**\n * Set the possible rotation range angles for the servo between 0 and 180\n * @param minAngle the minimum angle from 0 to 90\n * @param maxAngle the maximum angle from 90 to 180\n */\n //% help=servos/set-range\n //% blockId=servosetrange block=\"set %servo range from %minAngle to %maxAngle\"\n //% minAngle.min=0 minAngle.max=90\n //% maxAngle.min=90 maxAngle.max=180 maxAngle.defl=180\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n //% parts=microservo trackArgs=0\n //% group=\"Configuration\"\n //% blockGap=8\n public setRange(minAngle: number, maxAngle: number) {\n this._minAngle = Math.max(0, Math.min(90, minAngle | 0));\n this._maxAngle = Math.max(90, Math.min(180, maxAngle | 0));\n }\n\n /**\n * Set a servo stop mode so it will stop when the rotation angle is in the neutral position, 90 degrees.\n * @param on true to enable this mode\n */\n //% help=servos/set-stop-on-neutral\n //% blockId=servostoponneutral block=\"set %servo stop on neutral %enabled\"\n //% enabled.shadow=toggleOnOff\n //% group=\"Configuration\"\n //% blockGap=8\n //% servo.fieldEditor=\"gridpicker\"\n //% servo.fieldOptions.width=220\n //% servo.fieldOptions.columns=2\n public setStopOnNeutral(enabled: boolean) {\n this._stopOnNeutral = enabled;\n }\n\n protected internalStop() { }\n }\n\n export class PinServo extends Servo {\n private _pin: PwmOnlyPin;\n\n constructor(pin: PwmOnlyPin) {\n super();\n this._pin = pin;\n }\n\n protected internalSetAngle(angle: number): number {\n this._pin.servoWrite(angle);\n return angle;\n }\n\n protected internalSetContinuous(continuous: boolean): void {\n this._pin.servoSetContinuous(continuous);\n }\n\n protected internalSetPulse(micros: number): void {\n this._pin.servoSetPulse(micros);\n }\n\n protected internalStop() {\n this._pin.digitalRead();\n this._pin.setPull(PinPullMode.PullNone);\n }\n }\n}\n",
2817
2817
  "targetoverrides.ts": "namespace servos {\n //% block=\"servo P0\" fixedInstance whenUsed\n export const P0 = new servos.PinServo(pins.P0);\n //% block=\"servo P1\" fixedInstance whenUsed\n export const P1 = new servos.PinServo(pins.P1);\n //% block=\"servo P2\" fixedInstance whenUsed\n export const P2 = new servos.PinServo(pins.P2);\n}"
2818
2818
  },
2819
2819
  "radio-broadcast": {
2820
- "pxt.json": "{\n \"name\": \"radio-broadcast\",\n \"description\": \"Adds new blocks for message communication in the radio category\",\n \"dependencies\": {\n \"core\": \"*\",\n \"radio\": \"*\"\n },\n \"files\": [\n \"radio-broadcast.ts\"\n ],\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"icon\": \"/static/libs/radio-broadcast.png\"\n}\n",
2820
+ "pxt.json": "{\n \"name\": \"radio-broadcast\",\n \"description\": \"Adds new blocks for message communication in the radio category\",\n \"dependencies\": {\n \"core\": \"*\",\n \"radio\": \"*\"\n },\n \"files\": [\n \"radio-broadcast.ts\"\n ],\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"icon\": \"/static/libs/radio-broadcast.png\"\n}\n",
2821
2821
  "radio-broadcast.ts": "namespace radio {\n const BROADCAST_GENERAL_ID = 2000;\n\n /**\n * Gets the message code\n */\n //% blockHidden=1 shim=ENUM_GET\n //% blockId=radioMessageCode block=\"$msg\" enumInitialMembers=\"message1\"\n //% enumName=RadioMessage enumMemberName=msg enumPromptHint=\"e.g. Start, Stop, Jump...\"\n //% enumIsHash=1\n export function __message(msg: number): number {\n return msg;\n }\n\n /**\n * Broadcasts a message over radio\n * @param msg \n */\n //% blockId=radioBroadcastMessage block=\"radio send $msg\"\n //% msg.shadow=radioMessageCode draggableParameters\n //% weight=200\n //% blockGap=8\n //% help=radio/send-message\n export function sendMessage(msg: number): void {\n // 0 is MICROBIT_EVT_ANY, shifting by 1\n radio.raiseEvent(BROADCAST_GENERAL_ID, msg + 1);\n }\n\n /**\n * Registers code to run for a particular message\n * @param msg \n * @param handler \n */\n //% blockId=radioOnMessageReceived block=\"on radio $msg received\"\n //% msg.shadow=radioMessageCode draggableParameters\n //% weight=199\n //% help=radio/on-received-message\n export function onReceivedMessage(msg: number, handler: () => void) {\n control.onEvent(BROADCAST_GENERAL_ID, msg + 1, handler);\n }\n}"
2822
2822
  },
2823
2823
  "microphone": {
@@ -2825,7 +2825,7 @@ var pxtTargetBundle = {
2825
2825
  "enums.d.ts": "// Auto-generated. Do not edit.\n\n\n declare const enum DetectedSound {\n //% block=\"loud\"\n Loud = 2,\n //% block=\"quiet\"\n Quiet = 1,\n }\n\n\n declare const enum SoundThreshold {\n //% block=\"loud\"\n Loud = 2,\n //% block=\"quiet\"\n Quiet = 1,\n }\n\n// Auto-generated. Do not edit. Really.\n",
2826
2826
  "microphone.cpp": "#include \"pxt.h\"\n\n#if MICROBIT_CODAL\n#include \"LevelDetector.h\"\n#include \"LevelDetectorSPL.h\"\n#endif\n\n#define MICROPHONE_MIN 52.0f\n#define MICROPHONE_MAX 120.0f\n\nenum class DetectedSound {\n //% block=\"loud\"\n Loud = 2,\n //% block=\"quiet\"\n Quiet = 1\n};\n\nenum class SoundThreshold {\n //% block=\"loud\"\n Loud = 2,\n //% block=\"quiet\"\n Quiet = 1\n};\n\nnamespace pxt {\n#if MICROBIT_CODAL\n codal::LevelDetectorSPL* getMicrophoneLevel();\n#endif\n}\n\nnamespace input {\n\n/**\n* Registers an event that runs when a sound is detected\n*/\n//% help=input/on-sound\n//% blockId=input_on_sound block=\"on %sound sound\"\n//% parts=\"microphone\"\n//% weight=88 blockGap=12\n//% group=\"micro:bit (V2)\"\nvoid onSound(DetectedSound sound, Action handler) {\n#if MICROBIT_CODAL\n pxt::getMicrophoneLevel(); // wake up service\n const auto thresholdType = sound == DetectedSound::Loud ? LEVEL_THRESHOLD_HIGH : LEVEL_THRESHOLD_LOW;\n registerWithDal(DEVICE_ID_MICROPHONE, thresholdType, handler);\n#else\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n#endif\n}\n\n/**\n* Reads the loudness through the microphone from 0 (silent) to 255 (loud)\n*/\n//% help=input/sound-level\n//% blockId=device_get_sound_level block=\"sound level\"\n//% parts=\"microphone\"\n//% weight=34 blockGap=8\n//% group=\"micro:bit (V2)\"\nint soundLevel() {\n#if MICROBIT_CODAL\n auto level = pxt::getMicrophoneLevel();\n if (NULL == level)\n return 0;\n const int micValue = level->getValue();\n const int scaled = max(MICROPHONE_MIN, min(micValue, MICROPHONE_MAX)) - MICROPHONE_MIN;\n return min(0xff, scaled * 0xff / (MICROPHONE_MAX - MICROPHONE_MIN));\n#else\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n return 0;\n#endif\n}\n\n/**\n* Sets the threshold for a sound type.\n*/\n//% help=input/set-sound-threshold\n//% blockId=input_set_sound_threshold block=\"set %sound sound threshold to %value\"\n//% parts=\"microphone\"\n//% threshold.min=0 threshold.max=255 threshold.defl=128\n//% weight=14 blockGap=8\n//% advanced=true\n//% group=\"micro:bit (V2)\"\nvoid setSoundThreshold(SoundThreshold sound, int threshold) {\n#if MICROBIT_CODAL\n auto level = pxt::getMicrophoneLevel();\n if (NULL == level)\n return;\n\n threshold = max(0, min(0xff, threshold));\n const int scaled = MICROPHONE_MIN + threshold * (MICROPHONE_MAX - MICROPHONE_MIN) / 0xff;\n if (SoundThreshold::Loud == sound)\n level->setHighThreshold(scaled);\n else\n level->setLowThreshold(scaled);\n#else\n target_panic(PANIC_VARIANT_NOT_SUPPORTED);\n#endif\n}\n}",
2827
2827
  "microphonehw.cpp": "// The fallback logic below still requires level detection.\n// It's only kept with a view to syncing with the common-packages in future.\n\n#include \"pxt.h\"\n\n#if MICROBIT_CODAL\n#include \"LevelDetector.h\"\n#include \"LevelDetectorSPL.h\"\n#include \"DataStream.h\"\n\n#ifndef MIC_DEVICE\n// STM?\nclass DummyDataSource : public codal::DataSource {\n public:\n DummyDataSource() {}\n};\nclass PanicPDM {\n public:\n uint8_t level;\n DummyDataSource source;\n codal::DataStream output;\n\n PanicPDM(Pin &sd, Pin &sck) : output(source) { target_panic(PANIC_MICROPHONE_MISSING); }\n void enable() {}\n void disable() {}\n};\n#define MIC_DEVICE PanicPDM\n#endif\n\n#ifndef MIC_INIT\n#define MIC_INIT \\\n : microphone(*LOOKUP_PIN(MIC_DATA), *LOOKUP_PIN(MIC_CLOCK)) \\\n , level(microphone.output, 95.0, 75.0, 9, 52, DEVICE_ID_MICROPHONE)\n#endif\n\n#ifndef MIC_ENABLE\n#define MIC_ENABLE microphone.enable()\n#endif\n\nnamespace pxt {\n\nclass WMicrophone {\n public:\n MIC_DEVICE microphone;\n LevelDetectorSPL level;\n WMicrophone() MIC_INIT { MIC_ENABLE; }\n};\nSINGLETON(WMicrophone);\n\ncodal::LevelDetectorSPL *getMicrophoneLevel() {\n auto wmic = getWMicrophone();\n return wmic ? &(wmic->level) : NULL;\n}\n\n} // namespace pxt\n#endif",
2828
- "pxt.json": "{\n \"name\": \"microphone\",\n \"description\": \"The microphone library\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"microphone.cpp\",\n \"microphonehw.cpp\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"targetoverrides.ts\"\n ],\n \"testFiles\": [\n \"test.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"icon\": \"/static/libs/microphone.png\"\n}\n",
2828
+ "pxt.json": "{\n \"name\": \"microphone\",\n \"description\": \"The microphone library\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"microphone.cpp\",\n \"microphonehw.cpp\",\n \"enums.d.ts\",\n \"shims.d.ts\",\n \"targetoverrides.ts\"\n ],\n \"testFiles\": [\n \"test.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"icon\": \"/static/libs/microphone.png\"\n}\n",
2829
2829
  "shims.d.ts": "// Auto-generated. Do not edit.\ndeclare namespace input {\n\n /**\n * Registers an event that runs when a sound is detected\n */\n //% help=input/on-sound\n //% blockId=input_on_sound block=\"on %sound sound\"\n //% parts=\"microphone\"\n //% weight=88 blockGap=12\n //% group=\"micro:bit (V2)\" shim=input::onSound\n function onSound(sound: DetectedSound, handler: () => void): void;\n\n /**\n * Reads the loudness through the microphone from 0 (silent) to 255 (loud)\n */\n //% help=input/sound-level\n //% blockId=device_get_sound_level block=\"sound level\"\n //% parts=\"microphone\"\n //% weight=34 blockGap=8\n //% group=\"micro:bit (V2)\" shim=input::soundLevel\n function soundLevel(): int32;\n\n /**\n * Sets the threshold for a sound type.\n */\n //% help=input/set-sound-threshold\n //% blockId=input_set_sound_threshold block=\"set %sound sound threshold to %value\"\n //% parts=\"microphone\"\n //% threshold.min=0 threshold.max=255\n //% weight=14 blockGap=8\n //% advanced=true\n //% group=\"micro:bit (V2)\" threshold.defl=128 shim=input::setSoundThreshold\n function setSoundThreshold(sound: SoundThreshold, threshold?: int32): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2830
2830
  "targetoverrides.ts": "// target specific code",
2831
2831
  "test.ts": "// tests"
@@ -2839,7 +2839,7 @@ var pxtTargetBundle = {
2839
2839
  "RP2040Flash.cpp": "#include \"pxt.h\"\n#include \"Flash.h\"\n\n//#define LOG DMESG\n#define LOG NOLOG\n\n#ifdef PICO_BOARD\n#include \"hardware/flash.h\"\n\n#define XIP_BIAS 0x10000000\n\nnamespace codal {\n\nint ZFlash::pageSize(uintptr_t address) {\n return FLASH_SECTOR_SIZE;\n}\n\nint ZFlash::totalSize() {\n#ifndef PICO_FLASH_SIZE_BYTES\n return 2*1024*1024;\n#else\n return PICO_FLASH_SIZE_BYTES;\n#endif\n}\n\nint ZFlash::erasePage(uintptr_t address) {\n // address should be aligned to 4096\n if (address % 4096 == 0){\n target_disable_irq();\n flash_range_erase(address - XIP_BIAS, FLASH_SECTOR_SIZE); \n target_enable_irq();\n }\n return 0;\n}\n\nint ZFlash::writeBytes(uintptr_t dst, const void *src, uint32_t len) {\n if (len != FLASH_PAGE_SIZE || (dst & (FLASH_PAGE_SIZE - 1))) return -1;\n // should be aligned to 256\n target_disable_irq();\n flash_range_program(dst - XIP_BIAS, (const uint8_t*)src, FLASH_PAGE_SIZE);\n target_enable_irq();\n \n return 0;\n}\n\n\n\n\n}\n\n#endif\n",
2840
2840
  "SAMDFlash.cpp": "#include \"pxt.h\"\n#include \"Flash.h\"\n\n//#define LOG DMESG\n#define LOG NOLOG\n\n#if defined(SAMD51) || defined(SAMD21)\nnamespace codal {\n\n#ifdef SAMD51\n#define waitForLast() \\\n while (NVMCTRL->STATUS.bit.READY == 0) \\\n ;\n#else\n#define waitForLast() \\\n while (NVMCTRL->INTFLAG.bit.READY == 0) \\\n ;\n#endif\n\nstatic void unlock() {\n#ifdef SAMD51\n // see errata 2.14.1\n NVMCTRL->CTRLA.bit.CACHEDIS0 = true;\n NVMCTRL->CTRLA.bit.CACHEDIS1 = true;\n\n CMCC->CTRL.bit.CEN = 0;\n while (CMCC->SR.bit.CSTS) {\n }\n CMCC->MAINT0.bit.INVALL = 1;\n#endif\n}\n\nstatic void lock() {\n#ifdef SAMD51\n // re-enable cache\n NVMCTRL->CTRLA.bit.CACHEDIS0 = false;\n NVMCTRL->CTRLA.bit.CACHEDIS1 = false;\n\n // re-enable cortex-m cache - it's a separate one\n CMCC->CTRL.bit.CEN = 0;\n while (CMCC->SR.bit.CSTS) {\n }\n CMCC->MAINT0.bit.INVALL = 1;\n CMCC->CTRL.bit.CEN = 1;\n#endif\n}\n\nint ZFlash::totalSize() {\n return (8 << NVMCTRL->PARAM.bit.PSZ) * NVMCTRL->PARAM.bit.NVMP;\n}\n\n// this returns the size of \"page\" that can be erased (\"row\" in datasheet)\nint ZFlash::pageSize(uintptr_t address) {\n#ifdef SAMD51\n if (address < (uintptr_t)totalSize())\n return NVMCTRL_BLOCK_SIZE; // 8k\n#else\n if (address < (uintptr_t)totalSize())\n return 256;\n#endif\n target_panic(DEVICE_FLASH_ERROR);\n return 0;\n}\n\n#ifdef SAMD51\n#define CMD(D21, D51) NVMCTRL->CTRLB.reg = NVMCTRL_CTRLB_CMDEX_KEY | D51\n#else\n#define CMD(D21, D51) NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | D21\n#endif\n\nint ZFlash::erasePage(uintptr_t address) {\n LOG(\"Erase %x\", address);\n#ifdef SAMD51\n NVMCTRL->CTRLA.bit.WMODE = NVMCTRL_CTRLA_WMODE_MAN_Val;\n#else\n NVMCTRL->CTRLB.bit.MANW = 1;\n#endif\n waitForLast();\n unlock();\n#ifdef SAMD51\n NVMCTRL->ADDR.reg = address;\n#else\n // yeah... /2\n NVMCTRL->ADDR.reg = address / 2;\n#endif\n CMD(NVMCTRL_CTRLA_CMD_ER, NVMCTRL_CTRLB_CMD_EB);\n waitForLast();\n lock();\n return 0;\n}\n\n#if 0\n#define CHECK_ECC() \\\n if (NVMCTRL->INTFLAG.bit.ECCSE || NVMCTRL->INTFLAG.bit.ECCDE) \\\n return -10\n#else\n#define CHECK_ECC() ((void)0)\n#endif\n\nint ZFlash::writeBytes(uintptr_t dst, const void *src, uint32_t len) {\n#ifdef SAMD51\n CHECK_ECC();\n\n // only allow writing double word at a time\n if (len & 7)\n return -1;\n if (dst & 7)\n return -2;\n\n // every double-word can only be written once, otherwise we get ECC errors\n // and no, ECC cannot be disabled\n for (unsigned i = 0; i < (len >> 3); ++i)\n if (((uint64_t *)dst)[i] != 0xffffffffffffffff &&\n ((uint64_t *)src)[i] != 0xffffffffffffffff)\n return -3;\n#define WRITE_SIZE 16\n#else\n if ((dst & 3) || (len & 3))\n return -1;\n\n for (unsigned i = 0; i < len; ++i)\n if (((uint8_t *)dst)[i] != 0xff && ((uint8_t *)src)[i] != 0xff)\n return -3;\n#define WRITE_SIZE 64\n#endif\n\n uint32_t writeBuf[WRITE_SIZE >> 2];\n uint32_t idx = 0;\n\n waitForLast();\n unlock();\n __DMB();\n\n while (idx < len) {\n uint32_t off = dst & (WRITE_SIZE - 1);\n uint32_t n = WRITE_SIZE - off;\n if (n > len - idx)\n n = len - idx;\n uint32_t *sp;\n volatile uint32_t *dp;\n if (n != WRITE_SIZE) {\n memset(writeBuf, 0xff, WRITE_SIZE);\n memcpy((uint8_t *)writeBuf + off, src, n);\n sp = writeBuf;\n dp = (uint32_t *)(dst - off);\n } else {\n sp = (uint32_t *)src;\n dp = (uint32_t *)dst;\n }\n\n bool need = false;\n for (unsigned i = 0; i < (WRITE_SIZE >> 2); ++i)\n if (sp[i] != 0xffffffff) {\n need = true;\n break;\n }\n\n if (need) {\n CMD(NVMCTRL_CTRLA_CMD_PBC, NVMCTRL_CTRLB_CMD_PBC);\n waitForLast();\n\n uint32_t q = WRITE_SIZE >> 2;\n\n target_disable_irq();\n while (q--) {\n auto v = *sp++;\n *dp = v;\n dp++;\n }\n\n CMD(NVMCTRL_CTRLA_CMD_WP, NVMCTRL_CTRLB_CMD_WQW);\n target_enable_irq();\n waitForLast();\n }\n\n src = (uint8_t *)src + n;\n dst += n;\n idx += n;\n }\n\n CHECK_ECC();\n\n lock();\n\n return 0;\n}\n} // namespace codal\n#endif\n",
2841
2841
  "STM32Flash.cpp": "#include \"pxt.h\"\n#include \"Flash.h\"\n\n//#define LOG DMESG\n#define LOG NOLOG\n\n#ifdef STM32F4\nnamespace codal {\nstatic void waitForLast() {\n while ((FLASH->SR & FLASH_SR_BSY) == FLASH_SR_BSY)\n ;\n}\n\nstatic void unlock() {\n FLASH->CR |= FLASH_CR_LOCK;\n FLASH->KEYR = FLASH_KEY1;\n FLASH->KEYR = FLASH_KEY2;\n}\n\nstatic void lock() {\n FLASH->CR |= FLASH_CR_LOCK;\n}\n\nint ZFlash::pageSize(uintptr_t address) {\n address |= 0x08000000;\n if (address < 0x08010000)\n return 16 * 1024;\n if (address < 0x08020000)\n return 64 * 1024;\n if (address < 0x08100000)\n return 128 * 1024;\n target_panic(DEVICE_FLASH_ERROR);\n return 0;\n}\n\nint ZFlash::totalSize() {\n return *((uint16_t *)0x1FFF7A22) * 1024;\n}\n\nint ZFlash::erasePage(uintptr_t address) {\n waitForLast();\n unlock();\n\n address |= 0x08000000;\n uintptr_t ptr = 0x08000000;\n int sectNum = 0;\n while (1) {\n ptr += pageSize(ptr);\n if (ptr > address)\n break;\n sectNum++;\n }\n\n FLASH->CR = FLASH_CR_PSIZE_1 | (sectNum << FLASH_CR_SNB_Pos) | FLASH_CR_SER;\n FLASH->CR |= FLASH_CR_STRT;\n\n waitForLast();\n\n FLASH->CR = FLASH_CR_PSIZE_1;\n lock();\n\n // cache flushing only required after erase, not programming (3.5.4)\n __HAL_FLASH_DATA_CACHE_DISABLE();\n __HAL_FLASH_DATA_CACHE_RESET();\n __HAL_FLASH_DATA_CACHE_ENABLE();\n\n // we skip instruction cache, as we're not expecting to erase that\n\n return 0;\n}\n\nint ZFlash::writeBytes(uintptr_t dst, const void *src, uint32_t len) {\n LOG(\"WR flash at %p len=%d\", (void *)dst, len);\n\n if ((dst & 3) || ((uintptr_t)src & 3) || (len & 3))\n return -1;\n\n for (unsigned i = 0; i < len; ++i)\n if (((uint8_t *)dst)[i] != 0xff && ((uint8_t *)src)[i] != 0xff)\n return -3;\n\n waitForLast();\n unlock();\n\n dst |= 0x08000000;\n\n FLASH->CR = FLASH_CR_PSIZE_1 | FLASH_CR_PG;\n\n volatile uint32_t *sp = (uint32_t *)src;\n volatile uint32_t *dp = (uint32_t *)dst;\n len >>= 2;\n\n while (len-- > 0) {\n uint32_t v = *sp++;\n if (v != 0xffffffff) {\n *dp++ = v;\n waitForLast();\n } else {\n dp++;\n }\n }\n\n FLASH->CR = FLASH_CR_PSIZE_1;\n lock();\n\n LOG(\"WR flash OK\");\n\n return 0;\n}\n} // namespace codal\n#endif\n",
2842
- "pxt.json": "{\n \"name\": \"settings\",\n \"description\": \"Settings storage in internal flash\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"RAFFS.cpp\",\n \"RAFFS.h\",\n \"Flash.h\",\n \"STM32Flash.cpp\",\n \"SAMDFlash.cpp\",\n \"NRF52Flash.cpp\",\n \"RP2040Flash.cpp\",\n \"settings.cpp\",\n \"settings.ts\",\n \"shims.d.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"hidden\": true,\n \"disablesVariants\": [\n \"mbdal\"\n ]\n}\n",
2842
+ "pxt.json": "{\n \"name\": \"settings\",\n \"description\": \"Settings storage in internal flash\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"RAFFS.cpp\",\n \"RAFFS.h\",\n \"Flash.h\",\n \"STM32Flash.cpp\",\n \"SAMDFlash.cpp\",\n \"NRF52Flash.cpp\",\n \"RP2040Flash.cpp\",\n \"settings.cpp\",\n \"settings.ts\",\n \"shims.d.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"hidden\": true,\n \"disablesVariants\": [\n \"mbdal\"\n ]\n}\n",
2843
2843
  "settings.cpp": "\n#include \"pxt.h\"\n#include \"RAFFS.h\"\n#include \"GhostFAT.h\"\n\nusing namespace pxt::raffs;\nusing namespace codal;\n\nnamespace settings {\n\n#if defined(SAMD21)\n#define SETTINGS_SIZE (2 * 1024)\n#else\n#define SETTINGS_SIZE (32 * 1024)\n#endif\n\nclass WStorage {\n public:\n CODAL_FLASH flash;\n FS fs;\n bool isMounted;\n\n WStorage()\n : flash(),\n#if defined(STM32F4)\n fs(flash, 0x8008000, SETTINGS_SIZE),\n#elif defined(SAMD51)\n fs(flash, 512 * 1024 - SETTINGS_SIZE, SETTINGS_SIZE),\n#elif defined(SAMD21)\n fs(flash, 256 * 1024 - SETTINGS_SIZE, SETTINGS_SIZE),\n#elif defined(NRF52_SERIES)\n#define NRF_BOOTLOADER_START *(uint32_t *)0x10001014\n fs(flash,\n 128 * 1024 < NRF_BOOTLOADER_START && NRF_BOOTLOADER_START < (uint32_t)flash.totalSize()\n ? NRF_BOOTLOADER_START - SETTINGS_SIZE\n : flash.totalSize() - SETTINGS_SIZE,\n SETTINGS_SIZE),\n#elif defined(PICO_BOARD)\n // XIP bias 0x10000000\n fs(flash, 0x10000000 + flash.totalSize() - SETTINGS_SIZE, SETTINGS_SIZE),\n#else\n fs(flash),\n#endif\n isMounted(false) {\n fs.minGCSpacing = 10000;\n }\n};\nSINGLETON(WStorage);\n\nstatic WStorage *mountedStorage() {\n auto s = getWStorage();\n if (s->fs.tryMount())\n return s;\n s->fs.exists(\"foobar\"); // forces mount and possibly format\n return s;\n}\n\n// large store is area for storing large binary objects, eg ML models\n// it may be already occupied by the user program, in which case largeStoreStart() will return 0\nsize_t largeStoreSize() {\n#if defined(SAMD21)\n return 64 * 1024;\n#else\n return 128 * 1024;\n#endif\n}\n\nuintptr_t largeStoreStart() {\n auto s = getWStorage();\n uintptr_t r;\n#if defined(STM32F4)\n r = 0x08000000 + s->flash.totalSize() - largeStoreSize();\n#else\n r = s->fs.baseAddr - s->fs.bytes - largeStoreSize();\n#endif\n\n if (r < afterProgramPage())\n return 0;\n\n return r;\n}\n\nCODAL_FLASH *largeStoreFlash() {\n return &getWStorage()->flash;\n}\n\n//%\nint _set(String key, Buffer data) {\n auto s = mountedStorage();\n return s->fs.write(key->getUTF8Data(), data->data, data->length);\n}\n\n//%\nint _remove(String key) {\n auto s = mountedStorage();\n return s->fs.remove(key->getUTF8Data());\n}\n\n//%\nbool _exists(String key) {\n auto s = mountedStorage();\n return s->fs.exists(key->getUTF8Data());\n}\n\n//%\nBuffer _get(String key) {\n auto s = mountedStorage();\n auto sz = s->fs.read(key->getUTF8Data(), NULL, 0);\n if (sz < 0)\n return NULL;\n auto ret = mkBuffer(NULL, sz);\n registerGCObj(ret);\n s->fs.read(NULL, ret->data, ret->length);\n unregisterGCObj(ret);\n return ret;\n}\n\nstatic bool isSystem(const char *fn) {\n return fn[0] == '#';\n}\n\n//%\nvoid _userClean() {\n auto s = mountedStorage();\n DMESG(\"clearing user files\");\n s->fs.forceGC(isSystem);\n // if system files take more than 25% of storage size, we reformat\n // it likely means user code has written some 'system' files\n if (s->fs.freeSize() < 3 * s->fs.totalSize() / 4) {\n s->fs.format();\n }\n}\n\n//%\nRefCollection *_list(String prefix) {\n auto st = mountedStorage();\n st->fs.dirRewind();\n auto res = Array_::mk();\n registerGCObj(res);\n\n auto prefData = prefix->getUTF8Data();\n auto prefLen = prefix->getUTF8Size();\n auto wantsInternal = prefData[0] == '#';\n\n for (;;) {\n auto d = st->fs.dirRead();\n if (!d)\n break;\n if (!wantsInternal && d->name[0] == '#')\n continue;\n if (memcmp(d->name, prefData, prefLen) != 0)\n continue;\n auto str = mkString(d->name, -1);\n registerGCObj(str);\n res->head.push((TValue)str);\n unregisterGCObj(str);\n }\n unregisterGCObj(res);\n return res;\n}\n\n} // namespace settings\n",
2844
2844
  "settings.ts": "namespace settings {\n const RUN_KEY = \"#run\";\n const SCOPE_KEY = \"#scope\";\n const DEVICE_SECRETS_KEY = \"#secrets\";\n const SECRETS_KEY = \"__secrets\";\n\n //% shim=pxt::seedAddRandom\n declare function seedAddRandom(n: number): void;\n\n //% shim=settings::_set\n declare function _set(key: string, data: Buffer): int32;\n\n //% shim=settings::_remove\n declare function _remove(key: string): int32;\n\n //% shim=settings::_exists\n declare function _exists(key: string): boolean;\n\n //% shim=settings::_get\n declare function _get(key: string): Buffer;\n\n //% shim=settings::_userClean\n declare function _userClean(): void;\n\n //% shim=settings::_list\n declare function _list(prefix: string): string[];\n\n export function runNumber() {\n return readNumber(RUN_KEY) || 0\n }\n\n function setScope(scope: string) {\n if (!scope || scope.length > 100)\n control.panic(922)\n const currScope = readString(SCOPE_KEY)\n if (currScope != scope) {\n _userClean()\n writeString(SCOPE_KEY, scope)\n }\n }\n\n function initScopes() {\n const rn = runNumber() + 1\n writeNumber(RUN_KEY, rn)\n\n seedAddRandom(control.deviceSerialNumber() & 0x7fffffff)\n seedAddRandom(rn)\n\n setScope(control.programName())\n }\n\n initScopes()\n\n /** \n * Delete all non-system settings.\n */\n export function clear(): void {\n _userClean()\n }\n\n /**\n * Set named setting to a given buffer.\n */\n export function writeBuffer(key: string, value: Buffer) {\n if (_set(key, value)) {\n // if we're out of space, clear user storage\n _userClean()\n // and panic - reset should hopefully recreate needed files\n control.panic(920)\n }\n }\n\n /**\n * Set named settings to a given string.\n */\n export function writeString(key: string, value: string) {\n writeBuffer(key, control.createBufferFromUTF8(value))\n }\n\n /**\n * Set named settings to a given JSON object.\n */\n export function writeJSON(key: string, value: any) {\n writeString(key, JSON.stringify(value))\n }\n\n /**\n * Set named settings to a given number.\n */\n export function writeNumber(key: string, value: number) {\n writeBuffer(key, msgpack.packNumberArray([value]))\n }\n\n /**\n * Set named settings to a given array of numbers.\n */\n export function writeNumberArray(key: string, value: number[]) {\n writeBuffer(key, msgpack.packNumberArray(value))\n }\n\n /**\n * Read named setting as a buffer. Returns undefined when setting not found.\n */\n export function readBuffer(key: string) {\n return _get(key)\n }\n\n /**\n * Read named setting as a string.\n */\n export function readString(key: string) {\n const buf = readBuffer(key)\n if (!buf)\n return undefined\n else\n return buf.toString()\n }\n\n /**\n * Read named setting as a JSON object.\n */\n export function readJSON(key: string) {\n const s = readString(key)\n if (s)\n return JSON.parse(s)\n return undefined\n }\n\n /**\n * Read named setting as a number.\n */\n export function readNumber(key: string) {\n const buf = readBuffer(key)\n if (!buf)\n return undefined\n else {\n const nums = msgpack.unpackNumberArray(buf)\n if (nums && nums.length >= 1)\n return nums[0]\n return undefined\n }\n }\n\n /**\n * Read named setting as a number.\n */\n export function readNumberArray(key: string) {\n const buf = readBuffer(key)\n if (!buf)\n return undefined\n else\n return msgpack.unpackNumberArray(buf)\n }\n\n /**\n * Return a list of settings starting with a given prefix.\n */\n export function list(prefix?: string) {\n if (!prefix) prefix = \"\"\n return _list(prefix)\n }\n\n /**\n * Remove named setting.\n */\n export function remove(key: string) {\n _remove(key)\n }\n\n /**\n * Check if a named setting exists.\n */\n export function exists(key: string) {\n return _exists(key)\n }\n\n function clone(v: any): any {\n if (v == null) return null\n return JSON.parse(JSON.stringify(v))\n }\n\n function isKV(v: any) {\n return !!v && typeof v === \"object\" && !Array.isArray(v)\n }\n\n function jsonMergeFrom(trg: any, src: any) {\n if (!src) return;\n const keys = Object.keys(src)\n keys.forEach(k => {\n const srck = src[k];\n if (isKV(trg[k]) && isKV(srck))\n jsonMergeFrom(trg[k], srck);\n else\n trg[k] = clone(srck);\n });\n }\n\n //% fixedInstances\n export class SecretStore {\n constructor(private key: string) { }\n\n setSecret(name: string, value: any) {\n const secrets = this.readSecrets();\n secrets[name] = value;\n writeJSON(this.key, secrets);\n }\n\n updateSecret(name: string, value: any) {\n const secrets = this.readSecrets();\n const secret = secrets[name];\n if (secret === undefined)\n secrets[name] = value;\n else jsonMergeFrom(secret, value);\n writeJSON(this.key, secrets)\n }\n\n readSecret(name: string, ensure: boolean = false): any {\n const secrets = this.readSecrets();\n const secret = secrets[name];\n if (ensure && !secret)\n throw \"missing secret \" + name;\n return secret;\n }\n\n clearSecrets() {\n writeString(this.key, \"{}\");\n }\n\n readSecrets(): any {\n try {\n return readJSON(this.key) || {}\n } catch {\n control.dmesg(\"invalid secret format\")\n return {};\n }\n }\n }\n\n /**\n * Secrets shared by any program on the device\n */\n //% fixedInstance whenUsed block=\"device secrets\"\n export const deviceSecrets = new SecretStore(DEVICE_SECRETS_KEY);\n\n /**\n * Program secrets\n */\n //% fixedInstance whenUsed block=\"program secrets\"\n export const programSecrets = new SecretStore(SECRETS_KEY);\n}\n",
2845
2845
  "shims.d.ts": "\n"
@@ -2848,13 +2848,13 @@ var pxtTargetBundle = {
2848
2848
  "README.md": "# datalog\n",
2849
2849
  "enums.d.ts": "// Auto-generated. Do not edit.\n\n\n declare const enum FlashLogTimeStampFormat\n {\n //% block=\"none\"\n None = 0,\n //% block=\"milliseconds\"\n Milliseconds = 1,\n //% block=\"seconds\"\n Seconds = 10,\n //% block=\"minutes\"\n Minutes = 600,\n //% block=\"hours\"\n Hours = 36000,\n //% block=\"days\"\n Days = 864000,\n }\ndeclare namespace flashlog {\n}\n\n// Auto-generated. Do not edit. Really.\n",
2850
2850
  "flashlog.cpp": "#include \"pxt.h\"\n\n#if MICROBIT_CODAL\n#include \"MicroBitLog.h\"\n#endif\n\nenum class FlashLogTimeStampFormat\n{\n //% block=\"none\"\n None = 0,\n //% block=\"milliseconds\"\n Milliseconds = 1,\n //% block=\"seconds\"\n Seconds = 10,\n //% block=\"minutes\"\n Minutes = 600,\n //% block=\"hours\"\n Hours = 36000,\n //% block=\"days\"\n Days = 864000\n};\n\n/**\n * Storing structured data in flash.\n */\n//%\nnamespace flashlog {\n\n/**\n* Creates a new row in the log, ready to be populated by logData()\n**/\n//% help=flashlog/begin-row\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nint beginRow() {\n#if MICROBIT_CODAL\n return uBit.log.beginRow();\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n}\n\n/**\n* Populates the current row with the given key/value pair.\n**/\n//% help=flashlog/log-data\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nint logData(String key, String value) {\n if (NULL == key || NULL == value)\n return DEVICE_INVALID_PARAMETER;\n#if MICROBIT_CODAL\n return uBit.log.logData(MSTR(key), MSTR(value));\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n}\n\n/**\n* Inject the given row into the log as text, ignoring key/value pairs.\n**/\n//% help=flashlog/log-string\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nint logString(String value) {\n if (NULL == value)\n return DEVICE_INVALID_PARAMETER;\n#if MICROBIT_CODAL\n return uBit.log.logString(MSTR(value));\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n}\n\n/**\n* Complete a row in the log, and pushes to persistent storage.\n**/\n//% help=flashlog/end-row\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nint endRow() {\n#if MICROBIT_CODAL\n return uBit.log.endRow();\n#else\n return DEVICE_NOT_SUPPORTED;\n#endif\n}\n\n/**\n* Resets all data stored in persistent storage.\n**/\n//% help=flashlog/clear\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nvoid clear(bool fullErase) {\n#if MICROBIT_CODAL\n uBit.log.clear(fullErase);\n#endif\n}\n\n/**\n* Determines the format of the timestamp data to be added (if any).\n* If requested, time stamps will be automatically added to each row of data\n* as an integer value rounded down to the unit specified.\n*\n* @param format The format of timestamp to use.\n*/\n//% help=flashlog/set-timestamp\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nvoid setTimeStamp(FlashLogTimeStampFormat format) {\n#if MICROBIT_CODAL\n return uBit.log.setTimeStamp((codal::TimeStampFormat)format);\n#endif\n}\n\n/**\n * Defines if data logging should also be streamed over the serial port.\n *\n * @param enable True to enable serial port streaming, false to disable.\n*/\n//% help=flashlog/set-serial-mirroring\n//% parts=\"flashlog\"\n//% blockGap=8\n//% group=\"micro:bit (V2)\"\nvoid setSerialMirroring(bool enable) {\n#if MICROBIT_CODAL\n return uBit.log.setSerialMirroring(enable);\n#endif\n}\n\n}\n",
2851
- "pxt.json": "{\n \"name\": \"flashlog\",\n \"description\": \"Data logging to flash.\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"flashlog.cpp\",\n \"shims.d.ts\",\n \"enums.d.ts\"\n ],\n \"testFiles\": [\n \"test.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"searchOnly\": true,\n \"disablesVariants\": [\n \"mbdal\"\n ],\n \"icon\": \"/static/libs/flashlog.png\"\n}\n",
2851
+ "pxt.json": "{\n \"name\": \"flashlog\",\n \"description\": \"Data logging to flash.\",\n \"dependencies\": {\n \"core\": \"*\"\n },\n \"files\": [\n \"README.md\",\n \"flashlog.cpp\",\n \"shims.d.ts\",\n \"enums.d.ts\"\n ],\n \"testFiles\": [\n \"test.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"searchOnly\": true,\n \"disablesVariants\": [\n \"mbdal\"\n ],\n \"icon\": \"/static/libs/flashlog.png\"\n}\n",
2852
2852
  "shims.d.ts": "// Auto-generated. Do not edit.\n\n\n /**\n * Storing structured data in flash.\n */\n //%\ndeclare namespace flashlog {\n\n /**\n * Creates a new row in the log, ready to be populated by logData()\n **/\n //% help=flashlog/begin-row\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::beginRow\n function beginRow(): int32;\n\n /**\n * Populates the current row with the given key/value pair.\n **/\n //% help=flashlog/log-data\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::logData\n function logData(key: string, value: string): int32;\n\n /**\n * Inject the given row into the log as text, ignoring key/value pairs.\n **/\n //% help=flashlog/log-string\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::logString\n function logString(value: string): int32;\n\n /**\n * Complete a row in the log, and pushes to persistent storage.\n **/\n //% help=flashlog/end-row\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::endRow\n function endRow(): int32;\n\n /**\n * Resets all data stored in persistent storage.\n **/\n //% help=flashlog/clear\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::clear\n function clear(fullErase: boolean): void;\n\n /**\n * Determines the format of the timestamp data to be added (if any).\n * If requested, time stamps will be automatically added to each row of data\n * as an integer value rounded down to the unit specified.\n *\n * @param format The format of timestamp to use.\n */\n //% help=flashlog/set-timestamp\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::setTimeStamp\n function setTimeStamp(format: FlashLogTimeStampFormat): void;\n\n /**\n * Defines if data logging should also be streamed over the serial port.\n *\n * @param enable True to enable serial port streaming, false to disable.\n */\n //% help=flashlog/set-serial-mirroring\n //% parts=\"flashlog\"\n //% blockGap=8\n //% group=\"micro:bit (V2)\" shim=flashlog::setSerialMirroring\n function setSerialMirroring(enable: boolean): void;\n}\n\n// Auto-generated. Do not edit. Really.\n",
2853
2853
  "test.ts": "input.onButtonPressed(Button.AB, function() {\n flashlog.clear()\n})\nflashlog.setTimeStamp(FlashLogTimeStampFormat.Milliseconds)\nbasic.forever(function () {\n led.toggle(0, 0)\n const ax = input.acceleration(Dimension.X)\n\tflashlog.beginRow()\n flashlog.logData(`a.x`, ax)\n flashlog.logData(`a.y`, input.acceleration(Dimension.Y))\n flashlog.endRow()\n})\n"
2854
2854
  },
2855
2855
  "datalogger": {
2856
2856
  "datalogger.ts": "/**\n * Log data to flash storage\n */\n//% block=\"Data Logger\"\n//% icon=\"\\uf0ce\"\n//% color=\"#378273\"\nnamespace datalogger {\n export enum DeleteType {\n //% block=\"fast\"\n Fast,\n //% block=\"full\"\n Full\n }\n\n let onLogFullHandler: () => void;\n let _disabled = false;\n\n let initialized = false;\n function init() {\n if (initialized)\n return;\n initialized = true;\n\n includeTimestamp(FlashLogTimeStampFormat.Seconds);\n mirrorToSerial(true);\n\n control.onEvent(DAL.MICROBIT_ID_LOG, DAL.MICROBIT_LOG_EVT_LOG_FULL, () => {\n _disabled = true;\n if (onLogFullHandler) {\n onLogFullHandler();\n } else {\n basic.showLeds(`\n # . . . #\n # # . # #\n . . . . .\n . # # # .\n # . . . #\n `);\n basic.pause(1000);\n basic.clearScreen();\n basic.showString(\"928\");\n }\n });\n }\n\n export class ColumnValue {\n public value: string;\n constructor(\n public column: string,\n value: any\n ) {\n this.value = \"\" + value;\n }\n }\n\n /**\n * A column and value to log to flash storage\n * @param column the column to set\n * @param value the value to set.\n * @returns A new value that can be stored in flash storage using log data\n */\n //% block=\"column $column value $value\"\n //% value.shadow=math_number\n //% blockId=dataloggercreatecolumnvalue\n //% group=\"micro:bit (V2)\"\n //% weight=80 help=datalogger/create-cv\n export function createCV(column: string, value: any): ColumnValue {\n return new ColumnValue(column, value);\n }\n\n /**\n * Log data to flash storage\n * @param data Array of data to be logged to flash storage\n */\n //% block=\"log data $data\"\n //% blockId=dataloggerlogdata\n //% data.shadow=lists_create_with\n //% data.defl=dataloggercreatecolumnvalue\n //% group=\"micro:bit (V2)\"\n //% weight=100 help=datalogger/log-data\n export function logData(data: ColumnValue[]): void {\n if (!data || !data.length)\n return;\n init();\n\n if (_disabled)\n return;\n\n flashlog.beginRow();\n for (const cv of data) {\n flashlog.logData(cv.column, cv.value);\n }\n flashlog.endRow();\n }\n\n /**\n * Set the columns for future data logging\n * @param cols Array of the columns that will be logged.\n */\n //% block=\"set columns $cols\"\n //% blockId=dataloggersetcolumns\n //% data.shadow=list_create_with\n //% group=\"micro:bit (V2)\"\n //% weight=70 help=datalogger/set-columns\n export function setColumns(cols: string[]): void {\n if (!cols)\n return;\n\n logData(cols.map(col => createCV(col, \"\")));\n }\n\n /**\n * Delete all existing logs, including column headers. By default this only marks the log as\n * overwriteable / deletable in the future.\n * @param deleteType optional set whether a deletion will be fast or full\n */\n //% block=\"delete log||$deleteType\"\n //% blockId=dataloggerdeletelog\n //% group=\"micro:bit (V2)\"\n //% weight=60 help=datalogger/delete-log\n export function deleteLog(deleteType?: DeleteType): void {\n init();\n flashlog.clear(deleteType === DeleteType.Full);\n _disabled = false;\n }\n\n /**\n * Register an event to run when no more data can be logged.\n * @param handler code to run when the log is full and no more data can be stored.\n */\n //% block=\"on log full\"\n //% blockId=\"on log full\"\n //% group=\"micro:bit (V2)\"\n //% weight=40 help=datalogger/on-log-full\n export function onLogFull(handler: () => void): void {\n init();\n onLogFullHandler = handler;\n }\n\n /**\n * Set the format for timestamps\n * @param format Format in which to show the timestamp. Setting FlashLogTimeStampFormat.None will disable the timestamp.\n */\n //% block=\"set timestamp $format\"\n //% blockId=dataloggertoggleincludetimestamp\n //% format.defl=FlashLogTimeStampFormat.None\n //% group=\"micro:bit (V2)\"\n //% weight=30 help=datalogger/include-timestamp\n export function includeTimestamp(format: FlashLogTimeStampFormat): void {\n init();\n flashlog.setTimeStamp(format);\n }\n\n /**\n * Set whether data is mirrored to serial or not.\n * @param on if true, data that is logged will be mirrored to serial\n */\n //% block=\"mirror data to serial $on\"\n //% blockId=dataloggertogglemirrortoserial\n //% on.shadow=toggleOnOff\n //% on.defl=false\n //% weight=25 help=datalogger/mirror-to-serial\n export function mirrorToSerial(on: boolean): void {\n // TODO:/note intentionally does not have group, as having the same group for all\n // blocks in a category causes the group to be elided.\n init();\n flashlog.setSerialMirroring(on);\n }\n}",
2857
- "pxt.json": "{\n \"name\": \"datalogger\",\n \"description\": \"Data logging to flash memory. micro:bit (V2) only.\",\n \"dependencies\": {\n \"core\": \"*\",\n \"flashlog\": \"*\"\n },\n \"files\": [\n \"datalogger.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.10\",\n \"pxt\": \"7.4.12\"\n },\n \"disablesVariants\": [\n \"mbdal\"\n ],\n \"icon\": \"/static/libs/datalogger.png\"\n}\n"
2857
+ "pxt.json": "{\n \"name\": \"datalogger\",\n \"description\": \"Data logging to flash memory. micro:bit (V2) only.\",\n \"dependencies\": {\n \"core\": \"*\",\n \"flashlog\": \"*\"\n },\n \"files\": [\n \"datalogger.ts\"\n ],\n \"public\": true,\n \"targetVersions\": {\n \"target\": \"4.1.13\",\n \"pxt\": \"7.5.3\"\n },\n \"disablesVariants\": [\n \"mbdal\"\n ],\n \"icon\": \"/static/libs/datalogger.png\"\n}\n"
2858
2858
  }
2859
2859
  },
2860
2860
  "apiInfo": {
@@ -9597,6 +9597,13 @@ var pxtTargetBundle = {
9597
9597
  "weight": 30,
9598
9598
  "icon": "",
9599
9599
  "advanced": true,
9600
+ "groups": [
9601
+ "Pins",
9602
+ "Pulse",
9603
+ "I2C",
9604
+ "SPI",
9605
+ "micro:bit (V2)"
9606
+ ],
9600
9607
  "jsDoc": "Control currents in Pins for analog/digital signals, servos, i2c, ..."
9601
9608
  }
9602
9609
  },
@@ -10039,8 +10046,6 @@ var pxtTargetBundle = {
10039
10046
  "pulse": "PulseValue.High"
10040
10047
  },
10041
10048
  "help": "pins/on-pulsed",
10042
- "weight": 22,
10043
- "blockGap": "16",
10044
10049
  "advanced": true,
10045
10050
  "blockId": "pins_on_pulsed",
10046
10051
  "block": "on|pin %pin|pulsed %pulse",
@@ -10054,6 +10059,9 @@ var pxtTargetBundle = {
10054
10059
  "width": "250"
10055
10060
  }
10056
10061
  },
10062
+ "group": "Pulse",
10063
+ "weight": 25,
10064
+ "blockGap": "8",
10057
10065
  "paramHelp": {
10058
10066
  "name": "digital pin to register to, eg: DigitalPin.P0",
10059
10067
  "pulse": "the value of the pulse, eg: PulseValue.High"
@@ -10138,7 +10146,8 @@ var pxtTargetBundle = {
10138
10146
  "advanced": true,
10139
10147
  "blockId": "pins_pulse_duration",
10140
10148
  "block": "pulse duration (µs)",
10141
- "weight": 21,
10149
+ "group": "Pulse",
10150
+ "weight": 24,
10142
10151
  "blockGap": "8",
10143
10152
  "jsDoc": "Get the duration of the last pulse in microseconds. This function should be called from a ``onPulsed`` handler.",
10144
10153
  "_def": {
@@ -10166,7 +10175,6 @@ var pxtTargetBundle = {
10166
10175
  },
10167
10176
  "blockId": "pins_pulse_in",
10168
10177
  "block": "pulse in (µs)|pin %name|pulsed %value",
10169
- "weight": 20,
10170
10178
  "advanced": true,
10171
10179
  "help": "pins/pulse-in",
10172
10180
  "paramFieldEditor": {
@@ -10179,6 +10187,9 @@ var pxtTargetBundle = {
10179
10187
  "width": "250"
10180
10188
  }
10181
10189
  },
10190
+ "group": "Pulse",
10191
+ "weight": 23,
10192
+ "blockGap": "8",
10182
10193
  "explicitDefaults": [
10183
10194
  "maxDuration"
10184
10195
  ],
@@ -10291,6 +10302,7 @@ var pxtTargetBundle = {
10291
10302
  "width": "250"
10292
10303
  }
10293
10304
  },
10305
+ "group": "Servo",
10294
10306
  "paramHelp": {
10295
10307
  "name": "pin to write to, eg: AnalogPin.P0",
10296
10308
  "value": "angle or rotation speed, eg:180,90,0"
@@ -10406,6 +10418,7 @@ var pxtTargetBundle = {
10406
10418
  "width": "250"
10407
10419
  }
10408
10420
  },
10421
+ "group": "Servo",
10409
10422
  "paramHelp": {
10410
10423
  "name": "pin name",
10411
10424
  "micros": "pulse duration in micro seconds, eg:1500"
@@ -10480,7 +10493,6 @@ var pxtTargetBundle = {
10480
10493
  "blockId": "device_analog_set_pitch_pin",
10481
10494
  "block": "analog set pitch pin %name",
10482
10495
  "help": "pins/analog-set-pitch-pin",
10483
- "weight": 3,
10484
10496
  "advanced": true,
10485
10497
  "paramFieldEditor": {
10486
10498
  "name": "gridpicker"
@@ -10492,6 +10504,9 @@ var pxtTargetBundle = {
10492
10504
  "width": "250"
10493
10505
  }
10494
10506
  },
10507
+ "group": "Pins",
10508
+ "weight": 12,
10509
+ "blockGap": "8",
10495
10510
  "paramHelp": {
10496
10511
  "name": "pin to modulate pitch from"
10497
10512
  },
@@ -10617,9 +10632,10 @@ var pxtTargetBundle = {
10617
10632
  "blockId": "device_analog_pitch",
10618
10633
  "block": "analog pitch %frequency|for (ms) %ms",
10619
10634
  "help": "pins/analog-pitch",
10620
- "weight": 4,
10621
10635
  "async": "true",
10622
10636
  "advanced": true,
10637
+ "group": "Pins",
10638
+ "weight": 14,
10623
10639
  "blockGap": "8",
10624
10640
  "paramHelp": {
10625
10641
  "frequency": "frequency to modulate in Hz.",
@@ -10686,7 +10702,6 @@ var pxtTargetBundle = {
10686
10702
  "pull": "PinPullMode.PullUp"
10687
10703
  },
10688
10704
  "help": "pins/set-pull",
10689
- "weight": 3,
10690
10705
  "advanced": true,
10691
10706
  "blockId": "device_set_pull",
10692
10707
  "block": "set pull|pin %pin|to %pull",
@@ -10700,11 +10715,14 @@ var pxtTargetBundle = {
10700
10715
  "width": "250"
10701
10716
  }
10702
10717
  },
10718
+ "group": "Pins",
10719
+ "weight": 15,
10720
+ "blockGap": "8",
10703
10721
  "paramHelp": {
10704
10722
  "name": "pin to set the pull mode on, eg: DigitalPin.P0",
10705
10723
  "pull": "one of the mbed pull configurations, eg: PinPullMode.PullUp"
10706
10724
  },
10707
- "jsDoc": "Configure the pull directiion of of a pin.",
10725
+ "jsDoc": "Configure the pull direction of of a pin.",
10708
10726
  "_def": {
10709
10727
  "parts": [
10710
10728
  {
@@ -10779,7 +10797,6 @@ var pxtTargetBundle = {
10779
10797
  "type": "PinEventType.Edge"
10780
10798
  },
10781
10799
  "help": "pins/set-events",
10782
- "weight": 4,
10783
10800
  "advanced": true,
10784
10801
  "blockId": "device_set_pin_events",
10785
10802
  "block": "set pin %pin|to emit %type|events",
@@ -10793,6 +10810,9 @@ var pxtTargetBundle = {
10793
10810
  "width": "250"
10794
10811
  }
10795
10812
  },
10813
+ "group": "Pins",
10814
+ "weight": 13,
10815
+ "blockGap": "8",
10796
10816
  "paramHelp": {
10797
10817
  "name": "pin to set the event mode on, eg: DigitalPin.P0",
10798
10818
  "type": "the type of events for this pin to emit, eg: PinEventType.Edge"
@@ -10889,11 +10909,9 @@ var pxtTargetBundle = {
10889
10909
  "name": "DigitalPin.P1"
10890
10910
  },
10891
10911
  "help": "pins/neopixel-matrix-width",
10892
- "weight": 3,
10893
10912
  "advanced": true,
10894
10913
  "blockId": "pin_neopixel_matrix_width",
10895
10914
  "block": "neopixel matrix width|pin %pin %width",
10896
- "blockGap": "8",
10897
10915
  "paramFieldEditor": {
10898
10916
  "pin": "gridpicker"
10899
10917
  },
@@ -10907,6 +10925,9 @@ var pxtTargetBundle = {
10907
10925
  "paramMin": {
10908
10926
  "width": "2"
10909
10927
  },
10928
+ "group": "Pins",
10929
+ "weight": 11,
10930
+ "blockGap": "8",
10910
10931
  "explicitDefaults": [
10911
10932
  "width"
10912
10933
  ],
@@ -11041,10 +11062,12 @@ var pxtTargetBundle = {
11041
11062
  "retType": "number",
11042
11063
  "attributes": {
11043
11064
  "help": "pins/spi-write",
11044
- "weight": 5,
11045
11065
  "advanced": true,
11046
11066
  "blockId": "spi_write",
11047
11067
  "block": "spi write %value",
11068
+ "group": "SPI",
11069
+ "blockGap": "8",
11070
+ "weight": 53,
11048
11071
  "paramHelp": {
11049
11072
  "value": "Data to be sent to the SPI slave"
11050
11073
  },
@@ -11111,10 +11134,12 @@ var pxtTargetBundle = {
11111
11134
  "frequency": "1000000"
11112
11135
  },
11113
11136
  "help": "pins/spi-frequency",
11114
- "weight": 4,
11115
11137
  "advanced": true,
11116
11138
  "blockId": "spi_frequency",
11117
11139
  "block": "spi frequency %frequency",
11140
+ "group": "SPI",
11141
+ "blockGap": "8",
11142
+ "weight": 55,
11118
11143
  "paramHelp": {
11119
11144
  "frequency": "the clock frequency, eg: 1000000"
11120
11145
  },
@@ -11158,10 +11183,12 @@ var pxtTargetBundle = {
11158
11183
  "mode": "3"
11159
11184
  },
11160
11185
  "help": "pins/spi-format",
11161
- "weight": 3,
11162
11186
  "advanced": true,
11163
11187
  "blockId": "spi_format",
11164
11188
  "block": "spi format|bits %bits|mode %mode",
11189
+ "group": "SPI",
11190
+ "blockGap": "8",
11191
+ "weight": 54,
11165
11192
  "paramHelp": {
11166
11193
  "bits": "the number of bits, eg: 8",
11167
11194
  "mode": "the mode, eg: 3"
@@ -11233,7 +11260,6 @@ var pxtTargetBundle = {
11233
11260
  "kind": -3,
11234
11261
  "attributes": {
11235
11262
  "help": "pins/spi-pins",
11236
- "weight": 2,
11237
11263
  "advanced": true,
11238
11264
  "blockId": "spi_pins",
11239
11265
  "block": "spi set pins|MOSI %mosi|MISO %miso|SCK %sck",
@@ -11259,6 +11285,9 @@ var pxtTargetBundle = {
11259
11285
  "width": "250"
11260
11286
  }
11261
11287
  },
11288
+ "group": "SPI",
11289
+ "blockGap": "8",
11290
+ "weight": 51,
11262
11291
  "jsDoc": "Set the MOSI, MISO, SCK pins used by the SPI connection",
11263
11292
  "_def": {
11264
11293
  "parts": [
@@ -25307,6 +25336,37 @@ var pxtTargetBundle = {
25307
25336
  ],
25308
25337
  "pyQName": "music.set_play_tone"
25309
25338
  },
25339
+ "music.getFrequencyForNote": {
25340
+ "kind": -3,
25341
+ "retType": "number",
25342
+ "attributes": {
25343
+ "paramHelp": {
25344
+ "note": "The offset of the note within the octave"
25345
+ },
25346
+ "jsDoc": "Converts an octave and note offset into an integer frequency.\nReturns 0 if the note is out of range.\n* @param octave The octave of the note (1 - 8)\n\n@returns A frequency in HZ or 0 if out of range"
25347
+ },
25348
+ "parameters": [
25349
+ {
25350
+ "name": "octave"
25351
+ },
25352
+ {
25353
+ "name": "note",
25354
+ "description": "The offset of the note within the octave"
25355
+ }
25356
+ ],
25357
+ "pyQName": "music.get_frequency_for_note"
25358
+ },
25359
+ "music._bufferToMelody": {
25360
+ "kind": -3,
25361
+ "retType": "string[]",
25362
+ "parameters": [
25363
+ {
25364
+ "name": "melody",
25365
+ "type": "Buffer"
25366
+ }
25367
+ ],
25368
+ "pyQName": "music._buffer_to_melody"
25369
+ },
25310
25370
  "Melodies": {
25311
25371
  "kind": 6,
25312
25372
  "retType": "Melodies",
@@ -25767,6 +25827,18 @@ var pxtTargetBundle = {
25767
25827
  ],
25768
25828
  "pyQName": "music.get_melody"
25769
25829
  },
25830
+ "music._getMelodyBuffer": {
25831
+ "kind": -3,
25832
+ "retType": "Buffer",
25833
+ "parameters": [
25834
+ {
25835
+ "name": "melody",
25836
+ "type": "Melodies",
25837
+ "isEnum": true
25838
+ }
25839
+ ],
25840
+ "pyQName": "music._get_melody_buffer"
25841
+ },
25770
25842
  "pins.map": {
25771
25843
  "kind": -3,
25772
25844
  "retType": "number",
@@ -25915,7 +25987,8 @@ var pxtTargetBundle = {
25915
25987
  "advanced": true,
25916
25988
  "blockId": "pins_i2c_readnumber",
25917
25989
  "block": "i2c read number|at address %address|of format %format|repeated %repeat",
25918
- "weight": 7,
25990
+ "weight": 45,
25991
+ "group": "I2C",
25919
25992
  "jsDoc": "Read one number from 7-bit I2C address.",
25920
25993
  "_def": {
25921
25994
  "parts": [
@@ -26008,7 +26081,8 @@ var pxtTargetBundle = {
26008
26081
  "advanced": true,
26009
26082
  "blockId": "i2c_writenumber",
26010
26083
  "block": "i2c write number|at address %address|with value %value|of format %format|repeated %repeat",
26011
- "weight": 6,
26084
+ "weight": 44,
26085
+ "group": "I2C",
26012
26086
  "jsDoc": "Write one number to a 7-bit I2C address.",
26013
26087
  "_def": {
26014
26088
  "parts": [
@@ -27693,6 +27767,26 @@ var pxtTargetBundle = {
27693
27767
  }
27694
27768
  ]
27695
27769
  },
27770
+ "Fx.floor": {
27771
+ "kind": -3,
27772
+ "retType": "Fx8",
27773
+ "parameters": [
27774
+ {
27775
+ "name": "v",
27776
+ "type": "Fx8"
27777
+ }
27778
+ ]
27779
+ },
27780
+ "Fx.ceil": {
27781
+ "kind": -3,
27782
+ "retType": "Fx8",
27783
+ "parameters": [
27784
+ {
27785
+ "name": "v",
27786
+ "type": "Fx8"
27787
+ }
27788
+ ]
27789
+ },
27696
27790
  "Fx.leftShift": {
27697
27791
  "kind": -3,
27698
27792
  "retType": "Fx8",
@@ -28167,7 +28261,7 @@ var pxtTargetBundle = {
28167
28261
  }
28168
28262
  }
28169
28263
  },
28170
- "sha": "013c212e79d1fbd8d0a5c6d37beacc7e39d381f69ed38ea228b0d8d8ceeed100"
28264
+ "sha": "c8834f2ecedf4a8ffd9b837d6b9ba2ed1b897476d8b7cb1dc8b37274e541bd88"
28171
28265
  },
28172
28266
  "libs/radio": {
28173
28267
  "apis": {
@@ -28182,6 +28276,22 @@ var pxtTargetBundle = {
28182
28276
  "jsDoc": "Communicate data using radio packets"
28183
28277
  }
28184
28278
  },
28279
+ "radio.off": {
28280
+ "kind": -3,
28281
+ "attributes": {
28282
+ "help": "radio/off",
28283
+ "jsDoc": "Disables the radio for use as a multipoint sender/receiver.\nDisabling radio will help conserve battery power when it is not in use."
28284
+ },
28285
+ "parameters": []
28286
+ },
28287
+ "radio.on": {
28288
+ "kind": -3,
28289
+ "attributes": {
28290
+ "help": "radio/on",
28291
+ "jsDoc": "Initialises the radio for use as a multipoint sender/receiver\nOnly useful when the radio.off() is used beforehand."
28292
+ },
28293
+ "parameters": []
28294
+ },
28185
28295
  "radio.raiseEvent": {
28186
28296
  "kind": -3,
28187
28297
  "attributes": {
@@ -29583,7 +29693,7 @@ var pxtTargetBundle = {
29583
29693
  }
29584
29694
  }
29585
29695
  },
29586
- "sha": "16667039e4063927569707296c495c78a2bf8753821b2da12cca8313c4f7a3e9"
29696
+ "sha": "16e79fecbb542837731d573b7b38fe8046b926126cff44d92cc63532b45ab95b"
29587
29697
  },
29588
29698
  "libs/devices": {
29589
29699
  "apis": {
@@ -31630,7 +31740,7 @@ var pxtTargetBundle = {
31630
31740
  }
31631
31741
  }
31632
31742
  },
31633
- "sha": "268169185a5fbc4259ea015f1a31d3d01d63536f12044087f94dbd33165851a3"
31743
+ "sha": "52b7844eeff11c3d417ce2ba2387b70f8b3cc7ccb9f3fc74998368131b6bf2d8"
31634
31744
  },
31635
31745
  "libs/bluetooth": {
31636
31746
  "apis": {
@@ -32591,7 +32701,7 @@ var pxtTargetBundle = {
32591
32701
  }
32592
32702
  }
32593
32703
  },
32594
- "sha": "d3ccd9e93e6c5f39464b072c68f47bb7072575007470ee5aea08a647460902bb"
32704
+ "sha": "3b1a940bd61a86fd2704c900f23e6743a85524ca96110800dc06b4010a15c8fb"
32595
32705
  },
32596
32706
  "libs/servo": {
32597
32707
  "apis": {
@@ -33233,7 +33343,7 @@ var pxtTargetBundle = {
33233
33343
  }
33234
33344
  }
33235
33345
  },
33236
- "sha": "58a62738acb72f0d65a16499b42f80958b618efff9f1f50a8539573f80b95c33"
33346
+ "sha": "cfb76b2589256e78f3df6060503eef6c153903abf4e96218084fd5ef5ac15607"
33237
33347
  },
33238
33348
  "libs/radio-broadcast": {
33239
33349
  "apis": {
@@ -33248,6 +33358,22 @@ var pxtTargetBundle = {
33248
33358
  "jsDoc": "Communicate data using radio packets"
33249
33359
  }
33250
33360
  },
33361
+ "radio.off": {
33362
+ "kind": -3,
33363
+ "attributes": {
33364
+ "help": "radio/off",
33365
+ "jsDoc": "Disables the radio for use as a multipoint sender/receiver.\nDisabling radio will help conserve battery power when it is not in use."
33366
+ },
33367
+ "parameters": []
33368
+ },
33369
+ "radio.on": {
33370
+ "kind": -3,
33371
+ "attributes": {
33372
+ "help": "radio/on",
33373
+ "jsDoc": "Initialises the radio for use as a multipoint sender/receiver\nOnly useful when the radio.off() is used beforehand."
33374
+ },
33375
+ "parameters": []
33376
+ },
33251
33377
  "radio.raiseEvent": {
33252
33378
  "kind": -3,
33253
33379
  "attributes": {
@@ -34792,7 +34918,7 @@ var pxtTargetBundle = {
34792
34918
  }
34793
34919
  }
34794
34920
  },
34795
- "sha": "9028986c030b337848f5e67e81d128c610b502467c14149c668a94a26ae9f4ce"
34921
+ "sha": "4b18ac95ef885111c0f02e1b59c03f58c06e20647638971abcd7ece5a07ce128"
34796
34922
  },
34797
34923
  "libs/microphone": {
34798
34924
  "apis": {
@@ -35070,7 +35196,7 @@ var pxtTargetBundle = {
35070
35196
  }
35071
35197
  }
35072
35198
  },
35073
- "sha": "71f0ba452e1ff4552a9afd70a3e33d4585bfb8f81271b3dc7eb0dfc3e6934f95"
35199
+ "sha": "ba2366d4264a7d038df151746539c97c566cf51b5e27d72296998571958dfbdf"
35074
35200
  },
35075
35201
  "libs/settings": {
35076
35202
  "apis": {
@@ -35407,7 +35533,7 @@ var pxtTargetBundle = {
35407
35533
  }
35408
35534
  }
35409
35535
  },
35410
- "sha": "d2ef67cf80021d46bb394163187855cb039c8930d69aeec5fe04494e113e3808"
35536
+ "sha": "4751a07e6e9ccb5dc2c95b07191552929e86ddf08c64ec517de322b70768e33b"
35411
35537
  },
35412
35538
  "libs/flashlog": {
35413
35539
  "apis": {
@@ -35672,7 +35798,7 @@ var pxtTargetBundle = {
35672
35798
  }
35673
35799
  }
35674
35800
  },
35675
- "sha": "e69180aaa3be7394aca9450e3794f7294b027f71e5f85177b937846486dfe4fd"
35801
+ "sha": "d7b42aa4f9a76abc670cfff0fe5046eadcc388f20d64f01b0b7374686f4a39ff"
35676
35802
  },
35677
35803
  "libs/datalogger": {
35678
35804
  "apis": {
@@ -36393,7 +36519,7 @@ var pxtTargetBundle = {
36393
36519
  }
36394
36520
  }
36395
36521
  },
36396
- "sha": "c0f9e40218e804e15208c82b96bd97424b2906a88ecf397c213736c72202e664"
36522
+ "sha": "a17bd00023f62feaf0cd7b7b760149232847d1518922d94783e2ff6ea6b097af"
36397
36523
  },
36398
36524
  "libs/blocksprj": {
36399
36525
  "apis": {
@@ -36679,6 +36805,22 @@ var pxtTargetBundle = {
36679
36805
  "jsDoc": "Communicate data using radio packets"
36680
36806
  }
36681
36807
  },
36808
+ "radio.off": {
36809
+ "kind": -3,
36810
+ "attributes": {
36811
+ "help": "radio/off",
36812
+ "jsDoc": "Disables the radio for use as a multipoint sender/receiver.\nDisabling radio will help conserve battery power when it is not in use."
36813
+ },
36814
+ "parameters": []
36815
+ },
36816
+ "radio.on": {
36817
+ "kind": -3,
36818
+ "attributes": {
36819
+ "help": "radio/on",
36820
+ "jsDoc": "Initialises the radio for use as a multipoint sender/receiver\nOnly useful when the radio.off() is used beforehand."
36821
+ },
36822
+ "parameters": []
36823
+ },
36682
36824
  "radio.raiseEvent": {
36683
36825
  "kind": -3,
36684
36826
  "attributes": {
@@ -38080,7 +38222,7 @@ var pxtTargetBundle = {
38080
38222
  }
38081
38223
  }
38082
38224
  },
38083
- "sha": "8adfeef66e107d2530cd8498d88b30cf25ed1bb88ee0ac8a45475596b55b435d"
38225
+ "sha": "2274311a37d9be76122075bb799d82b05ef7ab46f2e741451da091a241defa59"
38084
38226
  },
38085
38227
  "libs/bluetoothprj": {
38086
38228
  "apis": {
@@ -39312,7 +39454,7 @@ var pxtTargetBundle = {
39312
39454
  }
39313
39455
  }
39314
39456
  },
39315
- "sha": "5fee716d2bdca76b241b408a8d6df252ac26250f09b2789b3360b780a6f93db4"
39457
+ "sha": "a42cb1c0aad2703f06619d6394e24506d7c159c8c27df2b3bc2951706af49fe9"
39316
39458
  },
39317
39459
  "libs/tsprj": {
39318
39460
  "apis": {
@@ -39598,6 +39740,22 @@ var pxtTargetBundle = {
39598
39740
  "jsDoc": "Communicate data using radio packets"
39599
39741
  }
39600
39742
  },
39743
+ "radio.off": {
39744
+ "kind": -3,
39745
+ "attributes": {
39746
+ "help": "radio/off",
39747
+ "jsDoc": "Disables the radio for use as a multipoint sender/receiver.\nDisabling radio will help conserve battery power when it is not in use."
39748
+ },
39749
+ "parameters": []
39750
+ },
39751
+ "radio.on": {
39752
+ "kind": -3,
39753
+ "attributes": {
39754
+ "help": "radio/on",
39755
+ "jsDoc": "Initialises the radio for use as a multipoint sender/receiver\nOnly useful when the radio.off() is used beforehand."
39756
+ },
39757
+ "parameters": []
39758
+ },
39601
39759
  "radio.raiseEvent": {
39602
39760
  "kind": -3,
39603
39761
  "attributes": {
@@ -40999,7 +41157,7 @@ var pxtTargetBundle = {
40999
41157
  }
41000
41158
  }
41001
41159
  },
41002
- "sha": "f954ff9b9cdbe845461bb499581bc9d26a7046a7e15979fa61f2d6e607b2fc7a"
41160
+ "sha": "ba26721543c78fe5929090b73a5c955863b69f8c98c62fa94b23a2960f13cdcb"
41003
41161
  }
41004
41162
  }
41005
41163
  }