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

@ -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
}