From dde16fec14d43e6be6eb5bce331b770891c8e2d7 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 11 Oct 2016 09:29:44 -0700 Subject: [PATCH 1/6] re-enabling sharing after bug has been fixed --- pxtarget.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxtarget.json b/pxtarget.json index 59572e13..4cd7e1fd 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -14,7 +14,7 @@ "cloud": { "workspace": false, "packages": true, - "sharing": false, + "sharing": true, "publish": false, "preferredPackages": [ "Microsoft/pxt-neopixel", From 6e64e80c05ad05b8d05c3e74b01d3179073d0a2e Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 11 Oct 2016 09:37:53 -0700 Subject: [PATCH 2/6] Revert "re-enabling sharing after bug has been fixed" This reverts commit dde16fec14d43e6be6eb5bce331b770891c8e2d7. --- pxtarget.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxtarget.json b/pxtarget.json index 4cd7e1fd..59572e13 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -14,7 +14,7 @@ "cloud": { "workspace": false, "packages": true, - "sharing": true, + "sharing": false, "publish": false, "preferredPackages": [ "Microsoft/pxt-neopixel", From 9f5ebdfb787006c2ec8a7f17fe4aeb4388e69b27 Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Tue, 11 Oct 2016 13:48:25 -0700 Subject: [PATCH 3/6] Adding advanced attribute to blocks and categories (#273) --- libs/core/control.cpp | 19 +++++++------ libs/core/control.ts | 1 + libs/core/game.ts | 3 +- libs/core/images.cpp | 7 +++-- libs/core/input.cpp | 14 +++++++--- libs/core/led.cpp | 13 +++++---- libs/core/pins.ts | 1 + libs/core/serial.cpp | 9 +++--- libs/core/serial.ts | 1 + libs/core/shims.d.ts | 34 +++++++++++++++-------- libs/radio/radio.cpp | 64 +++++++++++++++++++++++-------------------- libs/radio/shims.d.ts | 12 +++++--- 12 files changed, 107 insertions(+), 71 deletions(-) diff --git a/libs/core/control.cpp b/libs/core/control.cpp index 0869c2a2..13f5543c 100644 --- a/libs/core/control.cpp +++ b/libs/core/control.cpp @@ -110,6 +110,7 @@ enum EventBusValue { }; //% weight=1 color="#333333" +//% advanced=true namespace control { void fiberDone(void *a) { @@ -131,7 +132,7 @@ namespace control { */ //% weight=30 async help=control/reset blockGap=8 //% blockId="control_reset" block="reset" - void reset() { + void reset() { microbit_reset(); } @@ -153,16 +154,16 @@ namespace control { */ //% 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 //% mode.defl=CREATE_AND_FIRE - void raiseEvent(int src, int value, EventCreationMode mode) { - MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode); + void raiseEvent(int src, int value, EventCreationMode mode) { + MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode); } /** * Raises an event in the event bus. */ - //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" + //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% blockExternalInputs=1 - void onEvent(int src, int value, Action handler) { + void onEvent(int src, int value, Action handler) { registerWithDal(src, value, handler); } @@ -174,7 +175,7 @@ namespace control { int eventValue() { return pxt::lastEvent.value; } - + /** * Gets the timestamp of the last event executed on the bus */ @@ -183,15 +184,15 @@ namespace control { int eventTimestamp() { return pxt::lastEvent.timestamp; } - + /** * Gets a friendly name for the device derived from the its serial number */ //% blockId="control_device_name" block="device name" weight=10 blockGap=8 StringData* deviceName() { - return ManagedString(microbit_friendly_name()).leakData(); + return ManagedString(microbit_friendly_name()).leakData(); } - + /** * Derive a unique, consistent serial number of this device from internal data. */ diff --git a/libs/core/control.ts b/libs/core/control.ts index d6d14894..d9cd8f75 100644 --- a/libs/core/control.ts +++ b/libs/core/control.ts @@ -2,6 +2,7 @@ * Runtime and event utilities. */ //% weight=1 color="#333333" +//% advanced=true namespace control { /** diff --git a/libs/core/game.ts b/libs/core/game.ts index 95d310bf..c84ae864 100644 --- a/libs/core/game.ts +++ b/libs/core/game.ts @@ -1,5 +1,5 @@ enum Direction { - //% block=right + //% block=right Right, //% block=left Left @@ -22,6 +22,7 @@ enum LedSpriteProperty { * A single-LED sprite game engine */ //% color=#008272 weight=32 +//% advanced=true namespace game { let _score: number = 0; let _life: number = 3; diff --git a/libs/core/images.cpp b/libs/core/images.cpp index 3ee992d8..ec93716d 100644 --- a/libs/core/images.cpp +++ b/libs/core/images.cpp @@ -4,6 +4,7 @@ * Creation, manipulation and display of LED images. */ //% color=#5C2D91 weight=31 +//% advanced=true namespace images { /** * Creates an image that fits on the LED screen. @@ -29,7 +30,7 @@ namespace images { namespace ImageMethods { /** * Plots the image at a given column to the screen - */ + */ //% help=images/plot-image //% parts="ledmatrix" void plotImage(Image i, int xOffset = 0) { @@ -46,7 +47,7 @@ namespace ImageMethods { void showImage(Image sprite, int xOffset) { uBit.display.print(MicroBitImage(sprite), -xOffset, 0, 0); } - + /** * Draws the ``index``-th frame of the image on the screen. * @param xOffset column index to start displaying the image @@ -57,7 +58,7 @@ namespace ImageMethods { // TODO showImage() used in original implementation plotImage(i, xOffset * 5); } - + /** * Scrolls an image . * @param frameOffset x offset moved on each animation step, eg: 5, 1, -1 diff --git a/libs/core/input.cpp b/libs/core/input.cpp index 9708257f..3d8637ba 100644 --- a/libs/core/input.cpp +++ b/libs/core/input.cpp @@ -89,7 +89,7 @@ enum class Gesture { * Raised when the screen is pointing right */ //% block="tilt right" - TiltRight = MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT, + TiltRight = MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT, /** * Raised when the board is falling! */ @@ -132,7 +132,7 @@ namespace input { if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3) uBit.accelerometer.setRange(4); else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6) - uBit.accelerometer.setRange(8); + uBit.accelerometer.setRange(8); registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body); } @@ -143,6 +143,7 @@ namespace input { */ //% help=input/on-pin-pressed weight=83 //% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" + //% advanced=true void onPinPressed(TouchPin name, Action body) { auto pin = getPin((int)name); if (!pin) return; @@ -159,6 +160,7 @@ namespace input { */ //% help=input/on-pin-released weight=6 blockGap=8 //% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" + //% advanced=true void onPinReleased(TouchPin name, Action body) { auto pin = getPin((int)name); if (!pin) return; @@ -193,6 +195,7 @@ namespace input { //% help=input/pin-is-pressed weight=56 //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockGap=8 + //% advanced=true bool pinIsPressed(TouchPin name) { auto pin = getPin((int)name); return pin && pin->isTouched(); @@ -201,7 +204,7 @@ namespace input { /** * Get the current compass heading in degrees. */ - //% help=input/compass-heading + //% help=input/compass-heading //% weight=56 icon="\uf14e" //% blockId=device_heading block="compass heading (°)" blockGap=8 //% parts="compass" @@ -268,7 +271,7 @@ namespace input { case Rotation::Pitch: return uBit.accelerometer.getPitch(); case Rotation::Roll: return uBit.accelerometer.getRoll(); } - return 0; + return 0; } /** @@ -278,6 +281,7 @@ namespace input { //% help=input/magnetic-force weight=51 //% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" //% parts="compass" + //% advanced=true int magneticForce(Dimension dimension) { if (!uBit.compass.isCalibrated()) uBit.compass.calibrate(); @@ -296,6 +300,7 @@ namespace input { */ //% help=input/running-time weight=50 //% blockId=device_get_running_time block="running time (ms)" icon="\uf017" + //% advanced=true int runningTime() { return system_timer_current_time(); } @@ -314,6 +319,7 @@ namespace input { //% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135" //% weight=5 //% parts="accelerometer" + //% advanced=true void setAccelerometerRange(AcceleratorRange range) { uBit.accelerometer.setRange((int)range); } diff --git a/libs/core/led.cpp b/libs/core/led.cpp index 66e0a708..029fc1bf 100644 --- a/libs/core/led.cpp +++ b/libs/core/led.cpp @@ -19,7 +19,7 @@ namespace led { //% help=led/plot weight=78 //% blockId=device_plot block="plot|x %x|y %y" icon="\uf205" blockGap=8 //% parts="ledmatrix" - void plot(int x, int y) { + void plot(int x, int y) { uBit.display.image.setPixelValue(x, y, 1); } @@ -31,7 +31,7 @@ namespace led { //% help=led/unplot weight=77 //% blockId=device_unplot block="unplot|x %x|y %y" icon="\uf204" blockGap=8 //% parts="ledmatrix" - void unplot(int x, int y) { + void unplot(int x, int y) { uBit.display.image.setPixelValue(x, y, 0); } @@ -54,6 +54,7 @@ namespace led { //% help=led/brightness weight=60 //% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 //% parts="ledmatrix" + //% advanced=true int brightness() { return uBit.display.getBrightness(); } @@ -65,7 +66,8 @@ namespace led { //% help=led/set-brightness weight=59 //% blockId=device_set_brightness block="set brightness %value" icon="\uf042" //% parts="ledmatrix" - void setBrightness(int value) { + //% advanced=true + void setBrightness(int value) { uBit.display.setBrightness(value); } @@ -75,7 +77,8 @@ namespace led { //% weight=50 help=led/stop-animation //% blockId=device_stop_animation block="stop animation" icon="\uf04d" //% parts="ledmatrix" - void stopAnimation() { + //% advanced=true + void stopAnimation() { uBit.display.stopAnimation(); } @@ -85,7 +88,7 @@ namespace led { */ //% weight=1 help=led/set-display-mode //% parts="ledmatrix" - void setDisplayMode(DisplayMode_ mode) { + void setDisplayMode(DisplayMode_ mode) { uBit.display.setDisplayMode((DisplayMode)mode); } diff --git a/libs/core/pins.ts b/libs/core/pins.ts index 53f4e54a..2b9bc3c1 100644 --- a/libs/core/pins.ts +++ b/libs/core/pins.ts @@ -2,6 +2,7 @@ * Control currents in Pins for analog/digital signals, servos, i2c, ... */ //% color=#A80000 weight=30 +//% advanced=true namespace pins { /** * 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. diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index 47f9dda0..b50de6b7 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -20,9 +20,10 @@ enum class BaudRate { }; //% weight=2 color=30 +//% advanced=true namespace serial { // note that at least one // followed by % is needed per declaration! - + /** * Reads a line of text from the serial port. */ @@ -39,10 +40,10 @@ namespace serial { //% help=serial/write-string //% weight=87 //% blockId=serial_writestring block="serial write string %text" - void writeString(StringData *text) { + void writeString(StringData *text) { uBit.serial.send(ManagedString(text)); } - + /** * Registers an event to be fired when one of the delimiter is matched * @param delimiters the characters to match received characters against. eg:"\n" @@ -53,7 +54,7 @@ namespace serial { uBit.serial.eventOn(ManagedString(delimiters)); registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body); } - + /** * Dynamically configuring the serial instance to use pins other than USBTX and USBRX. * @param tx the new transmission pins diff --git a/libs/core/serial.ts b/libs/core/serial.ts index 1e401af7..cd632c5e 100644 --- a/libs/core/serial.ts +++ b/libs/core/serial.ts @@ -2,6 +2,7 @@ * Reading and writing data over a serial connection. */ //% weight=2 color=#002050 +//% advanced=true namespace serial { /** * Prints a line of text to the serial diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 42dc3fa1..82dd5acd 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -5,6 +5,7 @@ * Creation, manipulation and display of LED images. */ //% color=#5C2D91 weight=31 + //% advanced=true declare namespace images { /** @@ -238,7 +239,8 @@ declare namespace input { * @param body the code to run when the pin is pressed */ //% 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" icon="\uf094" + //% advanced=true shim=input::onPinPressed function onPinPressed(name: TouchPin, body: () => void): void; /** @@ -247,7 +249,8 @@ declare namespace input { * @param body the code to run when the pin is released */ //% help=input/on-pin-released weight=6 blockGap=8 - //% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" shim=input::onPinReleased + //% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" + //% advanced=true shim=input::onPinReleased function onPinReleased(name: TouchPin, body: () => void): void; /** @@ -266,13 +269,14 @@ declare namespace input { */ //% help=input/pin-is-pressed weight=56 //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" - //% blockGap=8 shim=input::pinIsPressed + //% blockGap=8 + //% advanced=true shim=input::pinIsPressed function pinIsPressed(name: TouchPin): boolean; /** * Get the current compass heading in degrees. */ - //% help=input/compass-heading + //% help=input/compass-heading //% weight=56 icon="\uf14e" //% blockId=device_heading block="compass heading (°)" blockGap=8 //% parts="compass" shim=input::compassHeading @@ -319,14 +323,16 @@ declare namespace input { */ //% help=input/magnetic-force weight=51 //% blockId=device_get_magnetic_force block="magnetic force (µT)|%NAME" blockGap=8 icon="\uf076" - //% parts="compass" shim=input::magneticForce + //% parts="compass" + //% advanced=true shim=input::magneticForce function magneticForce(dimension: Dimension): number; /** * Gets the number of milliseconds elapsed since power on. */ //% help=input/running-time weight=50 - //% blockId=device_get_running_time block="running time (ms)" icon="\uf017" shim=input::runningTime + //% blockId=device_get_running_time block="running time (ms)" icon="\uf017" + //% advanced=true shim=input::runningTime function runningTime(): number; /** @@ -342,13 +348,15 @@ declare namespace input { //% help=input/set-accelerometer-range //% blockId=device_set_accelerometer_range block="set accelerometer|range %range" icon="\uf135" //% weight=5 - //% parts="accelerometer" shim=input::setAccelerometerRange + //% parts="accelerometer" + //% advanced=true shim=input::setAccelerometerRange function setAccelerometerRange(range: AcceleratorRange): void; } //% weight=1 color="#333333" + //% advanced=true declare namespace control { /** @@ -386,7 +394,7 @@ declare namespace control { /** * Raises an event in the event bus. */ - //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" + //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% blockExternalInputs=1 shim=control::onEvent function onEvent(src: number, value: number, handler: () => void): void; @@ -457,7 +465,8 @@ declare namespace led { */ //% help=led/brightness weight=60 //% blockId=device_get_brightness block="brightness" icon="\uf042" blockGap=8 - //% parts="ledmatrix" shim=led::brightness + //% parts="ledmatrix" + //% advanced=true shim=led::brightness function brightness(): number; /** @@ -466,7 +475,8 @@ declare namespace led { */ //% help=led/set-brightness weight=59 //% blockId=device_set_brightness block="set brightness %value" icon="\uf042" - //% parts="ledmatrix" shim=led::setBrightness + //% parts="ledmatrix" + //% advanced=true shim=led::setBrightness function setBrightness(value: number): void; /** @@ -474,7 +484,8 @@ declare namespace led { */ //% weight=50 help=led/stop-animation //% blockId=device_stop_animation block="stop animation" icon="\uf04d" - //% parts="ledmatrix" shim=led::stopAnimation + //% parts="ledmatrix" + //% advanced=true shim=led::stopAnimation function stopAnimation(): void; /** @@ -636,6 +647,7 @@ declare namespace pins { //% weight=2 color=30 + //% advanced=true declare namespace serial { /** diff --git a/libs/radio/radio.cpp b/libs/radio/radio.cpp index 7b4dac5a..ab783592 100644 --- a/libs/radio/radio.cpp +++ b/libs/radio/radio.cpp @@ -9,12 +9,12 @@ namespace radio { // ------------------------------------------------------------------------- // Radio - // ------------------------------------------------------------------------- + // ------------------------------------------------------------------------- bool radioEnabled = false; bool transmitSerialNumber = false; - + PacketBuffer packet; - + int radioEnable() { int r = uBit.radio.enable(); if (r != MICROBIT_OK) { @@ -32,7 +32,7 @@ namespace radio { if (radioEnable() != MICROBIT_OK) return; uBit.radio.event.eventReceived(MicroBitEvent(MES_BROADCAST_GENERAL_ID, message, CREATE_ONLY)); } - + void onBroadcastMessageReceived(int message, Action f) { if (radioEnable() != MICROBIT_OK) return; registerWithDal(MES_BROADCAST_GENERAL_ID, message, f); @@ -40,18 +40,18 @@ namespace radio { /** * Broadcasts a number over radio to any connected micro:bit in the group. - */ + */ //% help=radio/send-number //% weight=60 //% blockId=radio_datagram_send block="radio send number %value" blockGap=8 - void sendNumber(int value) { - if (radioEnable() != MICROBIT_OK) return; + void sendNumber(int value) { + if (radioEnable() != MICROBIT_OK) return; uint32_t t = system_timer_current_time(); uint32_t sn = transmitSerialNumber ? microbit_serial_number() : 0; - uint32_t buf[] = { (uint32_t)value, t, sn }; + uint32_t buf[] = { (uint32_t)value, t, sn }; uBit.radio.datagram.send((uint8_t*)buf, 3*sizeof(uint32_t)); } - + /** * Broadcasts a name / value pair along with the device serial number * and running time to any connected micro:bit in the group. @@ -64,8 +64,8 @@ namespace radio { void sendValue(StringData* name, int value) { if (radioEnable() != MICROBIT_OK) return; - ManagedString n(name); - uint32_t t = system_timer_current_time(); + ManagedString n(name); + uint32_t t = system_timer_current_time(); uint32_t sn = transmitSerialNumber ? microbit_serial_number() : 0; uint8_t buf[32]; uint32_t* buf32 = (uint32_t*)buf; @@ -75,28 +75,28 @@ namespace radio { buf32[2] = sn; // 4 bytes: serial number uint8_t len = min(MAX_FIELD_NAME_LENGTH, n.length()); // 1 byte: string length if (len > 0) { - buf[12] = len; // - memcpy(buf + 13, n.toCharArray(), len); // 13-25: field name + buf[12] = len; // + memcpy(buf + 13, n.toCharArray(), len); // 13-25: field name } uBit.radio.datagram.send(buf, 13 + len); } - + /** * Broadcasts a number over radio to any connected micro:bit in the group. - */ + */ //% help=radio/send-string //% weight=58 //% blockId=radio_datagram_send_string block="radio send string %msg" void sendString(StringData* msg) { - if (radioEnable() != MICROBIT_OK) return; - + if (radioEnable() != MICROBIT_OK) return; + ManagedString s(msg); if (s.length() > MICROBIT_RADIO_MAX_PACKET_SIZE) s = s.substring(0, MICROBIT_RADIO_MAX_PACKET_SIZE); - + uBit.radio.datagram.send(s); } - + /** * Reads a value sent with `stream value` and writes it * to the serial stream as JSON @@ -104,29 +104,30 @@ namespace radio { //% help=radio/write-value-to-serial //% weight=3 //% blockId=radio_write_value_serial block="radio write value to serial" + //% advanced=true void writeValueToSerial() { if (radioEnable() != MICROBIT_OK) return; PacketBuffer p = uBit.radio.datagram.recv(); int length = p.length(); uint8_t* bytes = p.getBytes(); int value; - + uBit.serial.send("{"); if (length >= 4) { memcpy(&value, bytes, 4); uBit.serial.send("\"v\":"); uBit.serial.send(value); if(length >= 8) { memcpy(&value, bytes + 4, 4); - uBit.serial.send(",\"t\":"); uBit.serial.send(value); + uBit.serial.send(",\"t\":"); uBit.serial.send(value); if (length >= 12) { memcpy(&value, bytes + 8, 4); - uBit.serial.send(",\"s\":"); uBit.serial.send(value); + uBit.serial.send(",\"s\":"); uBit.serial.send(value); if (length >= 13) { char name[MAX_FIELD_NAME_LENGTH+1]; uint8_t len = min(MAX_FIELD_NAME_LENGTH, bytes[12]); memcpy(name, bytes + 13, len); name[len] = 0; - uBit.serial.send(",\"n\":\""); uBit.serial.send(name); uBit.serial.send("\""); + uBit.serial.send(",\"n\":\""); uBit.serial.send(name); uBit.serial.send("\""); } } } @@ -151,7 +152,7 @@ namespace radio { } return 0; } - + /** * Reads the next packet as a number from the radio queue. */ @@ -173,12 +174,12 @@ namespace radio { //% blockId=radio_datagram_received_event block="radio on data received" blockGap=8 void onDataReceived(Action body) { if (radioEnable() != MICROBIT_OK) return; - registerWithDal(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, body); + registerWithDal(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, body); // make the the receive buffer has a free spot receiveNumber(); } - + /** * Reads the next packet as a string and returns it. */ @@ -188,9 +189,9 @@ namespace radio { StringData* receiveString() { if (radioEnable() != MICROBIT_OK) return ManagedString().leakData(); packet = uBit.radio.datagram.recv(); - return ManagedString(packet).leakData(); + return ManagedString(packet).leakData(); } - + /** * Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator. * namespace=radio @@ -198,6 +199,7 @@ namespace radio { //% help=radio/received-signal-strength //% weight=40 //% blockId=radio_datagram_rssi block="radio received signal strength" + //% advanced=true int receivedSignalStrength() { if (radioEnable() != MICROBIT_OK) return 0; return packet.getRSSI(); @@ -214,7 +216,7 @@ namespace radio { if (radioEnable() != MICROBIT_OK) return; uBit.radio.setGroup(id); } - + /** * Change the output power level of the transmitter to the given value. * @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest. eg: 7 @@ -222,17 +224,19 @@ namespace radio { //% help=radio/set-transmit-power //% weight=9 blockGap=8 //% blockId=radio_set_transmit_power block="radio set transmit power %power" + //% advanced=true void setTransmitPower(int power) { if (radioEnable() != MICROBIT_OK) return; uBit.radio.setTransmitPower(power); } - + /** * Set the radio to transmit the serial number in each message. */ //% help=radio/set-transmit-serial-number //% weight=8 blockGap=8 //% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit" + //% advanced=true void setTransmitSerialNumber(bool transmit) { if (radioEnable() != MICROBIT_OK) return; transmitSerialNumber = transmit; diff --git a/libs/radio/shims.d.ts b/libs/radio/shims.d.ts index 5a85fbff..c2952d94 100644 --- a/libs/radio/shims.d.ts +++ b/libs/radio/shims.d.ts @@ -38,7 +38,8 @@ declare namespace radio { */ //% help=radio/write-value-to-serial //% weight=3 - //% blockId=radio_write_value_serial block="radio write value to serial" shim=radio::writeValueToSerial + //% blockId=radio_write_value_serial block="radio write value to serial" + //% advanced=true shim=radio::writeValueToSerial function writeValueToSerial(): void; /** @@ -79,7 +80,8 @@ declare namespace radio { */ //% help=radio/received-signal-strength //% weight=40 - //% blockId=radio_datagram_rssi block="radio received signal strength" shim=radio::receivedSignalStrength + //% blockId=radio_datagram_rssi block="radio received signal strength" + //% advanced=true shim=radio::receivedSignalStrength function receivedSignalStrength(): number; /** @@ -97,7 +99,8 @@ declare namespace radio { */ //% help=radio/set-transmit-power //% weight=9 blockGap=8 - //% blockId=radio_set_transmit_power block="radio set transmit power %power" shim=radio::setTransmitPower + //% blockId=radio_set_transmit_power block="radio set transmit power %power" + //% advanced=true shim=radio::setTransmitPower function setTransmitPower(power: number): void; /** @@ -105,7 +108,8 @@ declare namespace radio { */ //% help=radio/set-transmit-serial-number //% weight=8 blockGap=8 - //% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit" shim=radio::setTransmitSerialNumber + //% blockId=radio_set_transmit_serial_number block="radio set transmit serial number %transmit" + //% advanced=true shim=radio::setTransmitSerialNumber function setTransmitSerialNumber(transmit: boolean): void; } From 0ffccdca856066eec143fcd3d82845f87a5756b8 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 11 Oct 2016 17:51:09 -0700 Subject: [PATCH 4/6] Bump pxt-core to 0.4.52 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01edc113..9c06db27 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.51" + "pxt-core": "0.4.52" } } From f7ed06108df6e372ee303ee4cd09b87c5f3f3c3a Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 11 Oct 2016 19:36:00 -0700 Subject: [PATCH 5/6] Inputorg (#275) * use typescript from workspace * fixed tracking in localhost * updated ordering of input/radio --- .vscode/settings.json | 3 +- docfiles/apptracking.html | 2 +- docfiles/tracking.html | 2 +- docs/reference.md | 7 +++- libs/core/input.cpp | 77 +++++++++++++++++++-------------------- libs/core/shims.d.ts | 46 +++++++++++------------ libs/radio/radio.cpp | 3 +- libs/radio/shims.d.ts | 3 +- 8 files changed, 73 insertions(+), 70 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f782196d..373c9928 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,6 @@ "**/pxt_modules/**": true }, "tslint.enable": true, - "tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib" + "tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib", + "typescript.tsdk": "./node_modules/typescript/lib" } \ No newline at end of file diff --git a/docfiles/apptracking.html b/docfiles/apptracking.html index 159aa331..9517ea8a 100644 --- a/docfiles/apptracking.html +++ b/docfiles/apptracking.html @@ -2,5 +2,5 @@ (function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" "); for(g=0;g diff --git a/docfiles/tracking.html b/docfiles/tracking.html index 548da3a0..cb37031e 100644 --- a/docfiles/tracking.html +++ b/docfiles/tracking.html @@ -2,5 +2,5 @@ (function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" "); for(g=0;g diff --git a/docs/reference.md b/docs/reference.md index ef289ef6..4482a39b 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -10,6 +10,10 @@ input.onButtonPressed(Button.A, () => { music.playTone(0, 0); led.plot(0, 0); radio.sendNumber(0); +``` +## Advanced + +```namespaces game.addScore(1); images.createImage(` . . . . . @@ -24,7 +28,8 @@ control.inBackground(() => { }); ``` -## Advanced + +## Bluetooth ```namespaces devices.tellCameraTo(MesCameraEvent.TakePhoto); diff --git a/libs/core/input.cpp b/libs/core/input.cpp index 3d8637ba..5e6a7f11 100644 --- a/libs/core/input.cpp +++ b/libs/core/input.cpp @@ -143,7 +143,6 @@ namespace input { */ //% help=input/on-pin-pressed weight=83 //% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" - //% advanced=true void onPinPressed(TouchPin name, Action body) { auto pin = getPin((int)name); if (!pin) return; @@ -173,7 +172,7 @@ namespace input { /** * Get the button state (pressed or not) for ``A`` and ``B``. */ - //% help=input/button-is-pressed weight=57 + //% help=input/button-is-pressed weight=60 //% block="button|%NAME|is pressed" //% blockId=device_get_button2 //% icon="\uf192" blockGap=8 @@ -192,15 +191,48 @@ namespace input { * Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * @param name pin used to detect the touch */ - //% help=input/pin-is-pressed weight=56 + //% help=input/pin-is-pressed weight=58 //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockGap=8 - //% advanced=true bool pinIsPressed(TouchPin name) { auto pin = getPin((int)name); return pin && pin->isTouched(); } + int getAccelerationStrength() { + double x = uBit.accelerometer.getX(); + double y = uBit.accelerometer.getY(); + double z = uBit.accelerometer.getZ(); + return (int)sqrt(x*x+y*y+z*z); + } + + /** + * 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 + */ + //% help=input/acceleration weight=58 icon="\uf135" + //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 + //% parts="accelerometer" + int acceleration(Dimension dimension) { + switch (dimension) { + case Dimension::X: return uBit.accelerometer.getX(); + case Dimension::Y: return uBit.accelerometer.getY(); + case Dimension::Z: return uBit.accelerometer.getZ(); + case Dimension::Strength: return getAccelerationStrength(); + } + return 0; + } + + /** + * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. + */ + //% help=input/light-level weight=57 + //% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" + //% parts="ledmatrix" + int lightLevel() { + return uBit.display.readLightLevel(); + } + /** * Get the current compass heading in degrees. */ @@ -224,48 +256,13 @@ namespace input { return uBit.thermometer.getTemperature(); } - int getAccelerationStrength() { - double x = uBit.accelerometer.getX(); - double y = uBit.accelerometer.getY(); - double z = uBit.accelerometer.getZ(); - return (int)sqrt(x*x+y*y+z*z); - } - - /** - * 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 - */ - //% help=input/acceleration weight=54 icon="\uf135" - //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 - //% parts="accelerometer" - int acceleration(Dimension dimension) { - switch (dimension) { - case Dimension::X: return uBit.accelerometer.getX(); - case Dimension::Y: return uBit.accelerometer.getY(); - case Dimension::Z: return uBit.accelerometer.getZ(); - case Dimension::Strength: return getAccelerationStrength(); - } - return 0; - } - - - /** - * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. - */ - //% help=input/light-level weight=53 - //% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" - //% parts="ledmatrix" - int lightLevel() { - return uBit.display.readLightLevel(); - } - /** * The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees. * @param kind TODO */ //% help=input/rotation weight=52 //% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" - //% parts="accelerometer" + //% parts="accelerometer" advanced=true int rotation(Rotation kind) { switch (kind) { case Rotation::Pitch: return uBit.accelerometer.getPitch(); diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 82dd5acd..c649e7de 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -239,8 +239,7 @@ declare namespace input { * @param body the code to run when the pin is pressed */ //% help=input/on-pin-pressed weight=83 - //% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" - //% advanced=true shim=input::onPinPressed + //% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" shim=input::onPinPressed function onPinPressed(name: TouchPin, body: () => void): void; /** @@ -256,7 +255,7 @@ declare namespace input { /** * Get the button state (pressed or not) for ``A`` and ``B``. */ - //% help=input/button-is-pressed weight=57 + //% help=input/button-is-pressed weight=60 //% block="button|%NAME|is pressed" //% blockId=device_get_button2 //% icon="\uf192" blockGap=8 @@ -267,12 +266,28 @@ declare namespace input { * Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * @param name pin used to detect the touch */ - //% help=input/pin-is-pressed weight=56 + //% help=input/pin-is-pressed weight=58 //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" - //% blockGap=8 - //% advanced=true shim=input::pinIsPressed + //% blockGap=8 shim=input::pinIsPressed function pinIsPressed(name: TouchPin): boolean; + /** + * 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 + */ + //% help=input/acceleration weight=58 icon="\uf135" + //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 + //% parts="accelerometer" shim=input::acceleration + function acceleration(dimension: Dimension): number; + + /** + * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. + */ + //% help=input/light-level weight=57 + //% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" + //% parts="ledmatrix" shim=input::lightLevel + function lightLevel(): number; + /** * Get the current compass heading in degrees. */ @@ -291,30 +306,13 @@ declare namespace input { //% parts="thermometer" shim=input::temperature function temperature(): number; - /** - * 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 - */ - //% help=input/acceleration weight=54 icon="\uf135" - //% blockId=device_acceleration block="acceleration (mg)|%NAME" blockGap=8 - //% parts="accelerometer" shim=input::acceleration - function acceleration(dimension: Dimension): number; - - /** - * Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright. - */ - //% help=input/light-level weight=53 - //% blockId=device_get_light_level block="light level" blockGap=8 icon="\uf185" - //% parts="ledmatrix" shim=input::lightLevel - function lightLevel(): number; - /** * The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees. * @param kind TODO */ //% help=input/rotation weight=52 //% blockId=device_get_rotation block="rotation (°)|%NAME" blockGap=8 icon="\uf197" - //% parts="accelerometer" shim=input::rotation + //% parts="accelerometer" advanced=true shim=input::rotation function rotation(kind: Rotation): number; /** diff --git a/libs/radio/radio.cpp b/libs/radio/radio.cpp index ab783592..a67980cb 100644 --- a/libs/radio/radio.cpp +++ b/libs/radio/radio.cpp @@ -210,7 +210,7 @@ namespace radio { * @ param id the group id between ``0`` and ``255``, 1 eg */ //% help=radio/set-group - //% weight=10 blockGap=8 + //% weight=10 blockGap=8 advanced=true //% blockId=radio_set_group block="radio set group %ID" void setGroup(int id) { if (radioEnable() != MICROBIT_OK) return; @@ -232,6 +232,7 @@ namespace radio { /** * Set the radio to transmit the serial number in each message. + * @param transmit value indicating if the serial number is transmitted, eg: true */ //% help=radio/set-transmit-serial-number //% weight=8 blockGap=8 diff --git a/libs/radio/shims.d.ts b/libs/radio/shims.d.ts index c2952d94..f483c2d7 100644 --- a/libs/radio/shims.d.ts +++ b/libs/radio/shims.d.ts @@ -89,7 +89,7 @@ declare namespace radio { * @ param id the group id between ``0`` and ``255``, 1 eg */ //% help=radio/set-group - //% weight=10 blockGap=8 + //% weight=10 blockGap=8 advanced=true //% blockId=radio_set_group block="radio set group %ID" shim=radio::setGroup function setGroup(id: number): void; @@ -105,6 +105,7 @@ declare namespace radio { /** * Set the radio to transmit the serial number in each message. + * @param transmit value indicating if the serial number is transmitted, eg: true */ //% help=radio/set-transmit-serial-number //% weight=8 blockGap=8 From 895a099ebf253fd91f9485130ffffc06ed73654c Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 11 Oct 2016 19:36:36 -0700 Subject: [PATCH 6/6] 0.4.44 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c06db27..b784a76c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.43", + "version": "0.4.44", "description": "micro:bit target for PXT", "keywords": [ "JavaScript",