Various UI fixes. Block refactoring and adding touch and color blocks.

This commit is contained in:
Sam El-Husseini
2017-10-03 02:28:44 -04:00
parent 4977358718
commit 84d80131d4
17 changed files with 165 additions and 41 deletions

View File

@ -122,6 +122,8 @@
"loops.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.",
"loops.pause": "Pause for the specified time in milliseconds",
"loops.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
"loops.timePicker": "Get the time field editor",
"loops.timePicker|param|ms": "time duration in milliseconds, eg: 500, 1000",
"serial": "Reading and writing data over a serial connection.",
"serial.writeBuffer": "Send a buffer across the serial connection.",
"serial.writeLine": "Write a line of text to the serial port.",

View File

@ -10,7 +10,7 @@
"Array.unshift|block": "%list| insert %value| at beginning",
"Array|block": "Array",
"Math.constrain|block": "constrain %value|between %low|and %high",
"Math.map|block": "map %value|from %fromLow|%fromHigh|to %toLow|%toHigh",
"Math.map|block": "map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh",
"Math.randomRange|block": "pick random %min|to %limit",
"Math|block": "Math",
"String.charAt|block": "char from %this=text|at %pos",
@ -30,7 +30,8 @@
"control.waitMicros|block": "wait (µs)%micros",
"control|block": "control",
"loops.forever|block": "forever",
"loops.pause|block": "pause (ms) %pause",
"loops.pause|block": "pause %ms=timePicker|ms",
"loops.timePicker|block": "%ms",
"loops|block": "loops",
"serial.writeBuffer|block": "serial|write buffer %buffer",
"serial.writeLine|block": "serial|write line %text",

View File

@ -79,7 +79,7 @@ declare namespace loops {
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
*/
//% help=loops/pause weight=99
//% async block="pause (ms) %pause"
//% async block="pause %ms=timePicker|ms"
//% blockId=device_pause shim=loops::pause
function pause(ms: int32): void;
}
@ -151,7 +151,7 @@ declare namespace serial {
/**
* Send a buffer across the serial connection.
*/
//% help=serial/write-buffer advanced=true weight=6
//% help=serial/write-buffer weight=6
//% blockId=serial_writebuffer block="serial|write buffer %buffer" shim=serial::writeBuffer
function writeBuffer(buffer: Buffer): void;
}

View File

@ -84,16 +84,15 @@ namespace input {
* Check if button is currently pressed or not.
* @param button the button to query the request
*/
//% help=input/button/is-pressed weight=79
//% help=input/button/is-pressed
//% block="%button|is pressed"
//% blockId=buttonIsPressed
//% blockGap=8
//% parts="buttonpair"
//% blockNamespace=input
//% group="Brick buttons"
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
//% weight=81 blockGap=8
isPressed() {
return this._isPressed
}
@ -102,15 +101,15 @@ namespace input {
* See if the button was pressed again since the last time you checked.
* @param button the button to query the request
*/
//% help=input/button/was-pressed weight=78
//% help=input/button/was-pressed
//% block="%button|was pressed"
//% blockId=buttonWasPressed
//% parts="buttonpair" blockGap=8
//% blockNamespace=input advanced=true
//% group="Brick buttons"
//% parts="buttonpair"
//% blockNamespace=input
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
//% weight=80 blockGap=8
wasPressed() {
const r = this._wasPressed
this._wasPressed = false
@ -123,14 +122,15 @@ namespace input {
* @param event the kind of button gesture that needs to be detected
* @param body code to run when the event is raised
*/
//% help=input/button/on-event weight=99 blockGap=8
//% help=input/button/on-event
//% blockId=buttonEvent block="on %button|%event"
//% parts="buttonpair"
//% blockNamespace=input
//% group="Brick buttons"
//% group="Buttons"
//% button.fieldEditor="gridpicker"
//% button.fieldOptions.width=220
//% button.fieldOptions.columns=3
//% weight=99
onEvent(ev: ButtonEvent, body: () => void) {
control.onEvent(this._id, ev, body)
}

View File

@ -21,6 +21,7 @@ const enum ColorSensorColor {
namespace input {
//% fixedInstances
export class ColorSensor extends internal.UartSensor {
constructor() {
super()
@ -34,22 +35,52 @@ namespace input {
this._setMode(m)
}
/**
* Get current ambient light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=input/color/ambient-light
//% block="%color| ambient light"
//% blockId=colorGetAmbient
//% parts="colorsensor"
//% blockNamespace=input
//% weight=65 blockGap=8
getAmbientLight() {
this.setMode(ColorSensorMode.Ambient)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
getReflectedLight() {
/**
* Get current reflected light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=input/color/refelected-light
//% block="%color| reflected light"
//% blockId=colorGetReflected
//% parts="colorsensor"
//% blockNamespace=input
//% weight=64 blockGap=8
getReflectedLight(): number {
this.setMode(ColorSensorMode.Reflect)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/**
* Get the current color from the color sensor.
* @param color the color sensor to query the request
*/
//% help=input/color/color
//% block="%color| color"
//% blockId=colorGetColor
//% parts="colorsensor"
//% blockNamespace=input
//% weight=66 blockGap=8
getColor(): ColorSensorColor {
this.setMode(ColorSensorMode.Color)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
}
//% whenUsed
//% whenUsed block="color sensor" weight=95 fixedInstance
export const color: ColorSensor = new ColorSensor()
}

View File

@ -1,4 +1,6 @@
namespace input {
//% fixedInstances
export class TouchSensor extends internal.AnalogSensor {
button: Button;
@ -23,6 +25,6 @@ namespace input {
//% whenUsed
export const touchSensorImpl: TouchSensor = new TouchSensor()
//% whenUsed
//% whenUsed block="touch sensor" weight=95 fixedInstance
export const touchSensor: Button = touchSensorImpl.button
}

View File

@ -1,6 +1,5 @@
//% color="#D42878"
//% groups='["Brick buttons"]'
namespace input {
}

View File

@ -29,14 +29,14 @@
"Sounds.Siren|block": "siren",
"Sounds.Wawawawaa|block": "wawawawaa",
"music.beat|block": "%fraction|beat",
"music.changeTempoBy|block": "change tempo by (bpm)|%value",
"music.changeTempoBy|block": "change tempo by %value|(bpm)",
"music.noteFrequency|block": "%note",
"music.playSoundUntilDone|block": "play sound %sound=music_sounds|until done",
"music.playSound|block": "play sound %sound=music_sounds",
"music.playTone|block": "play tone|at %note=device_note|for %duration=device_beat",
"music.rest|block": "rest|for %duration=device_beat",
"music.ringTone|block": "ring tone|at %note=device_note",
"music.setTempo|block": "set tempo to (bpm)|%value",
"music.setTempo|block": "set tempo to %value|(bpm)",
"music.setVolume|block": "set volume %volume",
"music.sounds|block": "%name",
"music.stopAllSounds|block": "stop all sounds",

View File

@ -67,10 +67,11 @@ static void _playTone(uint16_t frequency, uint16_t duration, uint8_t volume)
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% help=music/play-tone
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
//% parts="headphone" async blockGap=8
//% parts="headphone" async
//% blockNamespace=music
//% weight=76 blockGap=8
void playTone(int frequency, int ms) {
if (frequency <= 0) {
_stopSound();

View File

@ -18,10 +18,11 @@ declare namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% help=music/play-tone
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
//% parts="headphone" async blockGap=8
//% blockNamespace=music shim=music::playTone
//% parts="headphone" async
//% blockNamespace=music
//% weight=76 blockGap=8 shim=music::playTone
function playTone(frequency: int32, ms: int32): void;
}