Merge branch 'master' into tutorialmode

This commit is contained in:
Sam El-Husseini 2017-01-05 08:19:39 -08:00
commit c5128aa497
24 changed files with 184 additions and 88 deletions

View File

@ -18,7 +18,7 @@ Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/
## ~ ## ~
```sig ```sig
bluetooth.advertiseUrl("https://pxt.microbit.org/", true); bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
``` ```
### Parameters ### Parameters
@ -30,7 +30,7 @@ bluetooth.advertiseUrl("https://pxt.microbit.org/", true);
### Example: Broadcast a secret code ### Example: Broadcast a secret code
```blocks ```blocks
bluetooth.advertiseUrl("https://pxt.io?secret=42", true); bluetooth.advertiseUrl("https://pxt.io?secret=42", 7, true);
``` ```
## See Also ## See Also

View File

@ -7,7 +7,7 @@ using namespace pxt;
/** /**
* Support for additional Bluetooth services. * Support for additional Bluetooth services.
*/ */
//% color=#0082FB weight=20 //% color=#0082FB weight=20 icon="\uf294"
namespace bluetooth { namespace bluetooth {
MicroBitUARTService *uart = NULL; MicroBitUARTService *uart = NULL;

View File

@ -1,7 +1,7 @@
/** /**
* Support for additional Bluetooth services. * Support for additional Bluetooth services.
*/ */
//% color=#0082FB weight=20 //% color=#0082FB weight=20 icon="\uf294"
namespace bluetooth { namespace bluetooth {
/** /**
* Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device. * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device.

View File

@ -4,7 +4,7 @@
/** /**
* Support for additional Bluetooth services. * Support for additional Bluetooth services.
*/ */
//% color=#0082FB weight=20 //% color=#0082FB weight=20 icon="\uf294"
declare namespace bluetooth { declare namespace bluetooth {
/** /**

View File

@ -4,7 +4,7 @@
/** /**
* Provides access to basic micro:bit functionality. * Provides access to basic micro:bit functionality.
*/ */
//% color=#0078D7 weight=100 //% color=#0078D7 weight=100 icon="\uf00a"
namespace basic { namespace basic {
/** /**
@ -13,7 +13,7 @@ namespace basic {
*/ */
//% help=basic/show-number //% help=basic/show-number
//% weight=96 //% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec" //% blockId=device_show_number block="show|number %number" blockGap=8
//% async //% async
//% parts="ledmatrix" //% parts="ledmatrix"
void showNumber(int value, int interval = 150) { void showNumber(int value, int interval = 150) {
@ -50,7 +50,7 @@ namespace basic {
*/ */
//% help=basic/show-string //% help=basic/show-string
//% weight=87 blockGap=8 //% weight=87 blockGap=8
//% block="show|string %text" icon="\uf031" //% block="show|string %text"
//% async //% async
//% blockId=device_print_message //% blockId=device_print_message
//% parts="ledmatrix" //% parts="ledmatrix"
@ -73,7 +73,7 @@ namespace basic {
* Turn off all LEDs * Turn off all LEDs
*/ */
//% help=basic/clear-screen weight=79 //% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d" //% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" //% parts="ledmatrix"
void clearScreen() { void clearScreen() {
uBit.display.image.clear(); uBit.display.image.clear();

View File

@ -1,7 +1,7 @@
/** /**
* Runtime and event utilities. * Runtime and event utilities.
*/ */
//% weight=1 color="#333333" //% weight=1 color="#333333" icon="\uf233"
//% advanced=true //% advanced=true
namespace control { namespace control {

View File

@ -153,16 +153,20 @@ namespace Array_ {
//% //%
int length(RefCollection *c) { return c->length(); } int length(RefCollection *c) { return c->length(); }
//% //%
void setLength(RefCollection *c, int newLength) { c->setLength(newLength); }
//%
void push(RefCollection *c, uint32_t x) { c->push(x); } void push(RefCollection *c, uint32_t x) { c->push(x); }
//% //%
uint32_t pop(RefCollection *c) { return c->pop(); } uint32_t pop(RefCollection *c) { return c->pop(); }
//% //%
uint32_t getAt(RefCollection *c, int x) { return c->getAt(x); } uint32_t getAt(RefCollection *c, int x) { return c->getAt(x); }
//% //%
void removeAt(RefCollection *c, int x) { c->removeAt(x); }
//%
void setAt(RefCollection *c, int x, uint32_t y) { c->setAt(x, y); } void setAt(RefCollection *c, int x, uint32_t y) { c->setAt(x, y); }
//% //%
uint32_t removeAt(RefCollection *c, int x) { return c->removeAt(x); }
//%
void insertAt(RefCollection *c, int x, uint32_t value) { c->insertAt(x, value); }
//%
int indexOf(RefCollection *c, uint32_t x, int start) { return c->indexOf(x, start); } int indexOf(RefCollection *c, uint32_t x, int start) { return c->indexOf(x, start); }
//% //%
int removeElement(RefCollection *c, uint32_t x) { return c->removeElement(x); } int removeElement(RefCollection *c, uint32_t x) { return c->removeElement(x); }

View File

@ -21,7 +21,7 @@ enum LedSpriteProperty {
/** /**
* A single-LED sprite game engine * A single-LED sprite game engine
*/ */
//% color=#008272 weight=32 //% color=#008272 weight=32 icon="\uf11b"
//% advanced=true //% advanced=true
namespace game { namespace game {
let _score: number = 0; let _score: number = 0;

View File

@ -3,7 +3,7 @@
/** /**
* Creation, manipulation and display of LED images. * Creation, manipulation and display of LED images.
*/ */
//% color=#5C2D91 weight=31 //% color=#5C2D91 weight=31 icon="\uf03e"
//% advanced=true //% advanced=true
namespace images { namespace images {
/** /**

View File

@ -112,7 +112,7 @@ enum class Gesture {
EightG = MICROBIT_ACCELEROMETER_EVT_8G EightG = MICROBIT_ACCELEROMETER_EVT_8G
}; };
//% color=300 weight=99 //% color=300 weight=99 icon="\uf192"
namespace input { namespace input {
/** /**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed * Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
@ -120,7 +120,7 @@ namespace input {
* @param body code to run when event is raised * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" //% blockId=device_button_event block="on button|%NAME|pressed"
//% parts="buttonpair" //% parts="buttonpair"
void onButtonPressed(Button button, Action body) { void onButtonPressed(Button button, Action body) {
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body); registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
@ -132,7 +132,7 @@ namespace input {
* @param body code to run when gesture is raised * @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" //% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" //% parts="accelerometer"
void onGesture(Gesture gesture, Action body) { void onGesture(Gesture gesture, Action body) {
int gi = (int)gesture; int gi = (int)gesture;
@ -149,7 +149,7 @@ namespace input {
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094" //% blockId=device_pin_event block="on pin %name|pressed"
void onPinPressed(TouchPin name, Action body) { void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@ -165,7 +165,7 @@ namespace input {
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" //% blockId=device_pin_released block="on pin %NAME|released"
//% advanced=true //% advanced=true
void onPinReleased(TouchPin name, Action body) { void onPinReleased(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
@ -200,7 +200,7 @@ namespace input {
* @param name pin used to detect the touch, eg: TouchPin.P0 * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
//% blockGap=8 //% blockGap=8
bool pinIsPressed(TouchPin name) { bool pinIsPressed(TouchPin name) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
@ -218,7 +218,7 @@ namespace input {
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024) * Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
* @param dimension TODO * @param dimension TODO
*/ */
//% help=input/acceleration weight=58 icon="\uf135" //% help=input/acceleration weight=58
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer" //% parts="accelerometer"
int acceleration(Dimension dimension) { int acceleration(Dimension dimension) {
@ -235,7 +235,7 @@ namespace input {
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
*/ */
//% help=input/light-level weight=57 //% help=input/light-level weight=57
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" //% blockId=device_get_light_level block="light level" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
int lightLevel() { int lightLevel() {
return uBit.display.readLightLevel(); return uBit.display.readLightLevel();
@ -245,7 +245,7 @@ namespace input {
* Get the current compass heading in degrees. * Get the current compass heading in degrees.
*/ */
//% help=input/compass-heading //% help=input/compass-heading
//% weight=56 icon="\uf14e" //% weight=56
//% blockId=device_heading block="compass heading (°)" blockGap=8 //% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass" //% parts="compass"
int compassHeading() { int compassHeading() {
@ -256,7 +256,7 @@ namespace input {
/** /**
* Gets the temperature in Celsius degrees (°C). * Gets the temperature in Celsius degrees (°C).
*/ */
//% weight=55 icon="\uf06d" //% weight=55
//% help=input/temperature //% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8 //% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer" //% parts="thermometer"
@ -269,7 +269,7 @@ namespace input {
* @param kind TODO * @param kind TODO
*/ */
//% help=input/rotation weight=52 //% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" //% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8
//% parts="accelerometer" advanced=true //% parts="accelerometer" advanced=true
int rotation(Rotation kind) { int rotation(Rotation kind) {
switch (kind) { switch (kind) {
@ -284,7 +284,7 @@ namespace input {
* @param dimension TODO * @param dimension TODO
*/ */
//% help=input/magnetic-force weight=51 //% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" //% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass" //% parts="compass"
//% advanced=true //% advanced=true
int magneticForce(Dimension dimension) { int magneticForce(Dimension dimension) {
@ -304,7 +304,7 @@ namespace input {
* Gets the number of milliseconds elapsed since power on. * Gets the number of milliseconds elapsed since power on.
*/ */
//% help=input/running-time weight=50 //% help=input/running-time weight=50
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017" //% blockId=device_get_running_time block="running time (ms)"
//% advanced=true //% advanced=true
int runningTime() { int runningTime() {
return system_timer_current_time(); return system_timer_current_time();
@ -321,7 +321,7 @@ namespace input {
* @param range a value describe the maximum strengh of acceleration measured * @param range a value describe the maximum strengh of acceleration measured
*/ */
//% help=input/set-accelerometer-range //% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135" //% blockId=device_set_accelerometer_range block="set accelerometer|range %range"
//% weight=5 //% weight=5
//% parts="accelerometer" //% parts="accelerometer"
//% advanced=true //% advanced=true

View File

@ -1,7 +1,7 @@
/** /**
* Events and data from sensors * Events and data from sensors
*/ */
//% color=#B4009E weight=99 //% color=#B4009E weight=99 icon="\uf192"
namespace input { namespace input {
/** /**
* Attaches code to run when the screen is facing up. * Attaches code to run when the screen is facing up.

View File

@ -8,7 +8,7 @@ enum class DisplayMode_ {
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE // TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
}; };
//% color=3 weight=35 //% color=3 weight=35 icon="\uf205"
namespace led { namespace led {
/** /**
@ -17,7 +17,7 @@ namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/plot weight=78 //% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8 //% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
void plot(int x, int y) { void plot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 1); uBit.display.image.setPixelValue(x, y, 1);
@ -29,7 +29,7 @@ namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/unplot weight=77 //% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8 //% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
void unplot(int x, int y) { void unplot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 0); uBit.display.image.setPixelValue(x, y, 0);
@ -41,7 +41,7 @@ namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/point weight=76 //% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c" //% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" //% parts="ledmatrix"
bool point(int x, int y) { bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y); int pix = uBit.display.image.getPixelValue(x, y);
@ -52,7 +52,7 @@ namespace led {
* Get the screen brightness from 0 (off) to 255 (full bright). * Get the screen brightness from 0 (off) to 255 (full bright).
*/ */
//% help=led/brightness weight=60 //% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 //% blockId=device_get_brightness block="brightness" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true //% advanced=true
int brightness() { int brightness() {
@ -64,7 +64,7 @@ namespace led {
* @param value the brightness value, eg:255, 127, 0 * @param value the brightness value, eg:255, 127, 0
*/ */
//% help=led/set-brightness weight=59 //% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042" //% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true //% advanced=true
void setBrightness(int value) { void setBrightness(int value) {
@ -75,7 +75,7 @@ namespace led {
* Cancels the current animation and clears other pending animations. * Cancels the current animation and clears other pending animations.
*/ */
//% weight=50 help=led/stop-animation //% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d" //% blockId=device_stop_animation block="stop animation"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true //% advanced=true
void stopAnimation() { void stopAnimation() {
@ -95,7 +95,7 @@ namespace led {
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d" //% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" //% advanced=true parts="ledmatrix"
void enable(bool on) { void enable(bool on) {
if (on) uBit.display.enable(); if (on) uBit.display.enable();

View File

@ -1,7 +1,7 @@
/** /**
* Control of the LED screen. * Control of the LED screen.
*/ */
//% color=#5C2D91 weight=97 //% color=#5C2D91 weight=97 icon="\uf205"
namespace led { namespace led {
// what's the current high value // what's the current high value

View File

@ -129,7 +129,7 @@ enum BeatFraction {
/** /**
* Generation of music tones through pin ``P0``. * Generation of music tones through pin ``P0``.
*/ */
//% color=#D83B01 weight=98 //% color=#D83B01 weight=98 icon="\uf025"
namespace music { namespace music {
let beatsPerMinute: number = 120; let beatsPerMinute: number = 120;
@ -139,7 +139,7 @@ namespace music {
* @param ms tone duration in milliseconds (ms) * @param ms tone duration in milliseconds (ms)
*/ */
//% help=music/play-tone weight=90 //% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8 //% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" blockGap=8
//% parts="headphone" //% parts="headphone"
export function playTone(frequency: number, ms: number): void { export function playTone(frequency: number, ms: number): void {
pins.analogPitch(frequency, ms); pins.analogPitch(frequency, ms);
@ -150,7 +150,7 @@ namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz) * @param frequency pitch of the tone to play in Hertz (Hz)
*/ */
//% help=music/ring-tone weight=80 //% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8 //% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
//% parts="headphone" //% parts="headphone"
export function ringTone(frequency: number): void { export function ringTone(frequency: number): void {
pins.analogPitch(frequency, 0); pins.analogPitch(frequency, 0);

View File

@ -1,7 +1,7 @@
/** /**
* Control currents in Pins for analog/digital signals, servos, i2c, ... * Control currents in Pins for analog/digital signals, servos, i2c, ...
*/ */
//% color=#A80000 weight=30 //% color=#A80000 weight=30 icon="\uf140"
//% advanced=true //% advanced=true
namespace pins { namespace pins {
/** /**

View File

@ -246,6 +246,25 @@ namespace pxt {
return; return;
} }
void Segment::ensure(uint16_t newSize)
{
if (newSize < size)
{
return;
}
growByMin(newSize);
}
void Segment::setLength(uint32_t newLength)
{
if (newLength > size)
{
ensure(length);
}
length = newLength;
return;
}
void Segment::push(uint32_t value) void Segment::push(uint32_t value)
{ {
this->set(length, value); this->set(length, value);
@ -269,17 +288,64 @@ namespace pxt {
return 0; return 0;
} }
void Segment::remove(uint32_t i) //this function removes an element at index i and shifts the rest of the elements to
//left to fill the gap
uint32_t Segment::remove(uint32_t i)
{ {
#ifdef DEBUG_BUILD #ifdef DEBUG_BUILD
printf("In Segment::remove\n"); printf("In Segment::remove index:%u\n", i);
this->print(); this->print();
#endif #endif
if (i < length) if (i < length)
{ {
data[i] = Segment::MissingValue; //value to return
uint32_t ret = data[i];
if (i + 1 < length)
{
//Move the rest of the elements to fill in the gap.
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
} }
return; length--;
data[length] = Segment::MissingValue;
#ifdef DEBUG_BUILD
printf("After Segment::remove index:%u\n", i);
this->print();
#endif
return ret;
}
error(ERR_OUT_OF_BOUNDS);
return 0;
}
//this function inserts element value at index i by shifting the rest of the elements right.
void Segment::insert(uint32_t i, uint32_t value)
{
#ifdef DEBUG_BUILD
printf("In Segment::insert index:%u value:%u\n", i, value);
this->print();
#endif
if (i < length)
{
ensure(length + 1);
if (i + 1 < length)
{
//Move the rest of the elements to fill in the gap.
memmove(data + i + 1, data + i, (length - i) * sizeof(uint32_t));
}
data[i] = value;
length++;
}
else
{
//This is insert beyond the length, just call set which will adjust the length
set(i, value);
}
#ifdef DEBUG_BUILD
printf("After Segment::insert index:%u\n", i);
this->print();
#endif
} }
void Segment::print() void Segment::print()
@ -365,17 +431,34 @@ namespace pxt {
} }
} }
void RefCollection::removeAt(int i) uint32_t RefCollection::removeAt(int i)
{ {
if (!head.isValidIndex((uint32_t)i)) if (!head.isValidIndex((uint32_t)i))
{ {
return; error(ERR_OUT_OF_BOUNDS);
return 0;
} }
if (isRef()) if (isRef())
{ {
decr(head.get(i)); decr(head.get(i));
} }
head.remove(i); return head.remove(i);
}
void RefCollection::insertAt(int i, uint32_t value)
{
if (i < length())
{
head.insert(i, value);
if (isRef())
{
incr(value);
}
}
else
{
error(ERR_OUT_OF_BOUNDS);
}
} }
void RefCollection::setAt(int i, uint32_t value) void RefCollection::setAt(int i, uint32_t value)

View File

@ -180,6 +180,7 @@ namespace pxt {
static uint16_t growthFactor(uint16_t size); static uint16_t growthFactor(uint16_t size);
void growByMin(uint16_t minSize); void growByMin(uint16_t minSize);
void growBy(uint16_t newSize); void growBy(uint16_t newSize);
void ensure(uint16_t newSize);
public: public:
Segment() : data (nullptr), length(0), size(0) {}; Segment() : data (nullptr), length(0), size(0) {};
@ -188,11 +189,13 @@ namespace pxt {
void set(uint32_t i, uint32_t value); void set(uint32_t i, uint32_t value);
uint32_t getLength() { return length;}; uint32_t getLength() { return length;};
void setLength(uint32_t newLength);
void push(uint32_t value); void push(uint32_t value);
uint32_t pop(); uint32_t pop();
void remove(uint32_t i); uint32_t remove(uint32_t i);
void insert(uint32_t i, uint32_t value);
//Returns true if there is a valid index greater than or equal to 'i', returns false otherwise //Returns true if there is a valid index greater than or equal to 'i', returns false otherwise
//If 'i' is valid returns it in 'result', if not tries to find the next valid //If 'i' is valid returns it in 'result', if not tries to find the next valid
@ -225,11 +228,17 @@ namespace pxt {
void print(); void print();
uint32_t length() { return head.getLength();} uint32_t length() { return head.getLength();}
void setLength(uint32_t newLength) { head.setLength(newLength); }
void push(uint32_t x); void push(uint32_t x);
uint32_t pop(); uint32_t pop();
uint32_t getAt(int x); uint32_t getAt(int i);
void removeAt(int x); void setAt(int i, uint32_t x);
void setAt(int x, uint32_t y); //removes the element at index i and shifts the other elements left
uint32_t removeAt(int i);
//inserts the element at index i and moves the other elements right.
void insertAt(int i, uint32_t x);
int indexOf(uint32_t x, int start); int indexOf(uint32_t x, int start);
int removeElement(uint32_t x); int removeElement(uint32_t x);
}; };

View File

@ -34,7 +34,7 @@ enum Delimiters {
Hash = 6, Hash = 6,
}; };
//% weight=2 color=30 //% weight=2 color=30 icon="\uf287"
//% advanced=true //% advanced=true
namespace serial { namespace serial {
// note that at least one // followed by % is needed per declaration! // note that at least one // followed by % is needed per declaration!

View File

@ -1,7 +1,7 @@
/** /**
* Reading and writing data over a serial connection. * Reading and writing data over a serial connection.
*/ */
//% weight=2 color=#002050 //% weight=2 color=#002050 icon="\uf287"
//% advanced=true //% advanced=true
namespace serial { namespace serial {
/** /**

56
libs/core/shims.d.ts vendored
View File

@ -4,7 +4,7 @@
/** /**
* Creation, manipulation and display of LED images. * Creation, manipulation and display of LED images.
*/ */
//% color=#5C2D91 weight=31 //% color=#5C2D91 weight=31 icon="\uf03e"
//% advanced=true //% advanced=true
declare namespace images { declare namespace images {
@ -126,7 +126,7 @@ declare interface Image {
/** /**
* Provides access to basic micro:bit functionality. * Provides access to basic micro:bit functionality.
*/ */
//% color=#0078D7 weight=100 //% color=#0078D7 weight=100 icon="\uf00a"
declare namespace basic { declare namespace basic {
/** /**
@ -135,7 +135,7 @@ declare namespace basic {
*/ */
//% help=basic/show-number //% help=basic/show-number
//% weight=96 //% weight=96
//% blockId=device_show_number block="show|number %number" blockGap=8 icon="\uf1ec" //% blockId=device_show_number block="show|number %number" blockGap=8
//% async //% async
//% parts="ledmatrix" interval.defl=150 shim=basic::showNumber //% parts="ledmatrix" interval.defl=150 shim=basic::showNumber
function showNumber(value: number, interval?: number): void; function showNumber(value: number, interval?: number): void;
@ -160,7 +160,7 @@ declare namespace basic {
*/ */
//% help=basic/show-string //% help=basic/show-string
//% weight=87 blockGap=8 //% weight=87 blockGap=8
//% block="show|string %text" icon="\uf031" //% block="show|string %text"
//% async //% async
//% blockId=device_print_message //% blockId=device_print_message
//% parts="ledmatrix" interval.defl=150 shim=basic::showString //% parts="ledmatrix" interval.defl=150 shim=basic::showString
@ -170,7 +170,7 @@ declare namespace basic {
* Turn off all LEDs * Turn off all LEDs
*/ */
//% help=basic/clear-screen weight=79 //% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen" icon="\uf12d" //% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" shim=basic::clearScreen //% parts="ledmatrix" shim=basic::clearScreen
function clearScreen(): void; function clearScreen(): void;
@ -211,7 +211,7 @@ declare namespace basic {
//% color=300 weight=99 //% color=300 weight=99 icon="\uf192"
declare namespace input { declare namespace input {
/** /**
@ -220,7 +220,7 @@ declare namespace input {
* @param body code to run when event is raised * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" //% blockId=device_button_event block="on button|%NAME|pressed"
//% parts="buttonpair" shim=input::onButtonPressed //% parts="buttonpair" shim=input::onButtonPressed
function onButtonPressed(button: Button, body: () => void): void; function onButtonPressed(button: Button, body: () => void): void;
@ -230,7 +230,7 @@ declare namespace input {
* @param body code to run when gesture is raised * @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" //% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" shim=input::onGesture //% parts="accelerometer" shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void; function onGesture(gesture: Gesture, body: () => void): void;
@ -240,7 +240,7 @@ declare namespace input {
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094" shim=input::onPinPressed //% blockId=device_pin_event block="on pin %name|pressed" shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void; function onPinPressed(name: TouchPin, body: () => void): void;
/** /**
@ -249,7 +249,7 @@ declare namespace input {
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" //% blockId=device_pin_released block="on pin %NAME|released"
//% advanced=true shim=input::onPinReleased //% advanced=true shim=input::onPinReleased
function onPinReleased(name: TouchPin, body: () => void): void; function onPinReleased(name: TouchPin, body: () => void): void;
@ -269,7 +269,7 @@ declare namespace input {
* @param name pin used to detect the touch, eg: TouchPin.P0 * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
//% blockGap=8 shim=input::pinIsPressed //% blockGap=8 shim=input::pinIsPressed
function pinIsPressed(name: TouchPin): boolean; function pinIsPressed(name: TouchPin): boolean;
@ -277,7 +277,7 @@ declare namespace input {
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024) * Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
* @param dimension TODO * @param dimension TODO
*/ */
//% help=input/acceleration weight=58 icon="\uf135" //% help=input/acceleration weight=58
//% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8
//% parts="accelerometer" shim=input::acceleration //% parts="accelerometer" shim=input::acceleration
function acceleration(dimension: Dimension): number; function acceleration(dimension: Dimension): number;
@ -286,7 +286,7 @@ declare namespace input {
* Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.
*/ */
//% help=input/light-level weight=57 //% help=input/light-level weight=57
//% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" //% blockId=device_get_light_level block="light level" blockGap=8
//% parts="ledmatrix" shim=input::lightLevel //% parts="ledmatrix" shim=input::lightLevel
function lightLevel(): number; function lightLevel(): number;
@ -294,7 +294,7 @@ declare namespace input {
* Get the current compass heading in degrees. * Get the current compass heading in degrees.
*/ */
//% help=input/compass-heading //% help=input/compass-heading
//% weight=56 icon="\uf14e" //% weight=56
//% blockId=device_heading block="compass heading (°)" blockGap=8 //% blockId=device_heading block="compass heading (°)" blockGap=8
//% parts="compass" shim=input::compassHeading //% parts="compass" shim=input::compassHeading
function compassHeading(): number; function compassHeading(): number;
@ -302,7 +302,7 @@ declare namespace input {
/** /**
* Gets the temperature in Celsius degrees (°C). * Gets the temperature in Celsius degrees (°C).
*/ */
//% weight=55 icon="\uf06d" //% weight=55
//% help=input/temperature //% help=input/temperature
//% blockId=device_temperature block="temperature (°C)" blockGap=8 //% blockId=device_temperature block="temperature (°C)" blockGap=8
//% parts="thermometer" shim=input::temperature //% parts="thermometer" shim=input::temperature
@ -313,7 +313,7 @@ declare namespace input {
* @param kind TODO * @param kind TODO
*/ */
//% help=input/rotation weight=52 //% help=input/rotation weight=52
//% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" //% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8
//% parts="accelerometer" advanced=true shim=input::rotation //% parts="accelerometer" advanced=true shim=input::rotation
function rotation(kind: Rotation): number; function rotation(kind: Rotation): number;
@ -322,7 +322,7 @@ declare namespace input {
* @param dimension TODO * @param dimension TODO
*/ */
//% help=input/magnetic-force weight=51 //% help=input/magnetic-force weight=51
//% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" //% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8
//% parts="compass" //% parts="compass"
//% advanced=true shim=input::magneticForce //% advanced=true shim=input::magneticForce
function magneticForce(dimension: Dimension): number; function magneticForce(dimension: Dimension): number;
@ -331,7 +331,7 @@ declare namespace input {
* Gets the number of milliseconds elapsed since power on. * Gets the number of milliseconds elapsed since power on.
*/ */
//% help=input/running-time weight=50 //% help=input/running-time weight=50
//% blockId=device_get_running_time block="running time (ms)" icon="\uf017" //% blockId=device_get_running_time block="running time (ms)"
//% advanced=true shim=input::runningTime //% advanced=true shim=input::runningTime
function runningTime(): number; function runningTime(): number;
@ -346,7 +346,7 @@ declare namespace input {
* @param range a value describe the maximum strengh of acceleration measured * @param range a value describe the maximum strengh of acceleration measured
*/ */
//% help=input/set-accelerometer-range //% help=input/set-accelerometer-range
//% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135" //% blockId=device_set_accelerometer_range block="set accelerometer|range %range"
//% weight=5 //% weight=5
//% parts="accelerometer" //% parts="accelerometer"
//% advanced=true shim=input::setAccelerometerRange //% advanced=true shim=input::setAccelerometerRange
@ -427,7 +427,7 @@ declare namespace control {
//% color=3 weight=35 //% color=3 weight=35 icon="\uf205"
declare namespace led { declare namespace led {
/** /**
@ -436,7 +436,7 @@ declare namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/plot weight=78 //% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8 //% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::plot //% parts="ledmatrix" shim=led::plot
function plot(x: number, y: number): void; function plot(x: number, y: number): void;
@ -446,7 +446,7 @@ declare namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/unplot weight=77 //% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8 //% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::unplot //% parts="ledmatrix" shim=led::unplot
function unplot(x: number, y: number): void; function unplot(x: number, y: number): void;
@ -456,7 +456,7 @@ declare namespace led {
* @param y TODO * @param y TODO
*/ */
//% help=led/point weight=76 //% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y" icon="\uf10c" //% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" shim=led::point //% parts="ledmatrix" shim=led::point
function point(x: number, y: number): boolean; function point(x: number, y: number): boolean;
@ -464,7 +464,7 @@ declare namespace led {
* Get the screen brightness from 0 (off) to 255 (full bright). * Get the screen brightness from 0 (off) to 255 (full bright).
*/ */
//% help=led/brightness weight=60 //% help=led/brightness weight=60
//% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 //% blockId=device_get_brightness block="brightness" blockGap=8
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true shim=led::brightness //% advanced=true shim=led::brightness
function brightness(): number; function brightness(): number;
@ -474,7 +474,7 @@ declare namespace led {
* @param value the brightness value, eg:255, 127, 0 * @param value the brightness value, eg:255, 127, 0
*/ */
//% help=led/set-brightness weight=59 //% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value" icon="\uf042" //% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true shim=led::setBrightness //% advanced=true shim=led::setBrightness
function setBrightness(value: number): void; function setBrightness(value: number): void;
@ -483,7 +483,7 @@ declare namespace led {
* Cancels the current animation and clears other pending animations. * Cancels the current animation and clears other pending animations.
*/ */
//% weight=50 help=led/stop-animation //% weight=50 help=led/stop-animation
//% blockId=device_stop_animation block="stop animation" icon="\uf04d" //% blockId=device_stop_animation block="stop animation"
//% parts="ledmatrix" //% parts="ledmatrix"
//% advanced=true shim=led::stopAnimation //% advanced=true shim=led::stopAnimation
function stopAnimation(): void; function stopAnimation(): void;
@ -499,7 +499,7 @@ declare namespace led {
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d" //% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" shim=led::enable //% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void; function enable(on: boolean): void;
@ -658,7 +658,7 @@ declare namespace pins {
//% weight=2 color=30 //% weight=2 color=30 icon="\uf287"
//% advanced=true //% advanced=true
declare namespace serial { declare namespace serial {

View File

@ -24,7 +24,7 @@ using namespace pxt;
// payload: string length (9), string (10 ... 28) // payload: string length (9), string (10 ... 28)
#define PACKET_TYPE_STRING 2 #define PACKET_TYPE_STRING 2
//% color=270 weight=34 //% color=270 weight=34 icon="\uf012"
namespace radio { namespace radio {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
/** /**
* Communicate data using radio packets * Communicate data using radio packets
*/ */
//% color=#E3008C weight=34 //% color=#E3008C weight=34 icon="\uf012"
namespace radio { namespace radio {
export class Packet { export class Packet {
/** /**

View File

@ -2,7 +2,7 @@
//% color=270 weight=34 //% color=270 weight=34 icon="\uf012"
declare namespace radio { declare namespace radio {
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "pxt-microbit", "name": "pxt-microbit",
"version": "0.7.12", "version": "0.7.14",
"description": "micro:bit target for PXT", "description": "micro:bit target for PXT",
"keywords": [ "keywords": [
"JavaScript", "JavaScript",
@ -34,6 +34,6 @@
"semantic-ui-less": "^2.2.4" "semantic-ui-less": "^2.2.4"
}, },
"dependencies": { "dependencies": {
"pxt-core": "0.7.13" "pxt-core": "0.8.3"
} }
} }