simplifiying brick light api (#231)
This commit is contained in:
parent
1453b7e0a3
commit
3815d2fd3b
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BrickLight": "Patterns for lights under the buttons.",
|
||||
"ButtonEvent": "User interaction on buttons",
|
||||
"Draw": "Drawing modes",
|
||||
"Image.buffer": "Returns the underlaying Buffer object.",
|
||||
@ -6,7 +7,6 @@
|
||||
"Image.draw": "Draw an image on the screen.",
|
||||
"Image.height": "Returns the height of an image.",
|
||||
"Image.width": "Returns the width of an image.",
|
||||
"LightsPattern": "Patterns for lights under the buttons.",
|
||||
"MMap.getNumber": "Read a number in specified format from the buffer.",
|
||||
"MMap.ioctl": "Perform ioctl(2) on the underlaying file",
|
||||
"MMap.length": "Returns the length of a Buffer object.",
|
||||
@ -28,11 +28,9 @@
|
||||
"brick.buttonRight": "Right button on the EV3 Brick.",
|
||||
"brick.buttonUp": "Up button on the EV3 Brick.",
|
||||
"brick.clearScreen": "Clears the screen",
|
||||
"brick.lightPattern": "Pattern block.",
|
||||
"brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
|
||||
"brick.printPorts": "Prints the port states on the screen",
|
||||
"brick.setLight": "Set lights.",
|
||||
"brick.setLight|param|pattern": "the lights pattern to use.",
|
||||
"brick.setLight|param|pattern": "the lights pattern to use. eg: BrickLight.Orange",
|
||||
"brick.showImage": "Shows an image on screen",
|
||||
"brick.showImage|param|image": "image to draw",
|
||||
"brick.showNumber": "Shows a number on the screen",
|
||||
|
@ -1,17 +1,17 @@
|
||||
{
|
||||
"BrickLight.GreenFlash|block": "green flash",
|
||||
"BrickLight.GreenPulse|block": "green pulse",
|
||||
"BrickLight.Green|block": "green",
|
||||
"BrickLight.Off|block": "off",
|
||||
"BrickLight.OrangeFlash|block": "orange flash",
|
||||
"BrickLight.OrangePulse|block": "orange pulse",
|
||||
"BrickLight.Orange|block": "orange",
|
||||
"BrickLight.RedFlash|block": "red flash",
|
||||
"BrickLight.RedPulse|block": "red pulse",
|
||||
"BrickLight.Red|block": "red",
|
||||
"ButtonEvent.Click|block": "click",
|
||||
"ButtonEvent.Down|block": "down",
|
||||
"ButtonEvent.Up|block": "up",
|
||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||
"LightsPattern.GreenPulse|block": "Pulsing Green",
|
||||
"LightsPattern.Green|block": "Green",
|
||||
"LightsPattern.Off|block": "Off",
|
||||
"LightsPattern.OrangeFlash|block": "Flashing Orange",
|
||||
"LightsPattern.OrangePulse|block": "Pulsing Orange",
|
||||
"LightsPattern.Orange|block": "Orange",
|
||||
"LightsPattern.RedFlash|block": "Flashing Red",
|
||||
"LightsPattern.RedPulse|block": "Pulsing Red",
|
||||
"LightsPattern.Red|block": "Red",
|
||||
"MoveUnit.Degrees|block": "degrees",
|
||||
"MoveUnit.MilliSeconds|block": "milliseconds",
|
||||
"MoveUnit.Rotations|block": "rotations",
|
||||
@ -36,9 +36,8 @@
|
||||
"brick.buttonRight|block": "button right",
|
||||
"brick.buttonUp|block": "button up",
|
||||
"brick.clearScreen|block": "clear screen",
|
||||
"brick.lightPattern|block": "%pattern",
|
||||
"brick.printPorts|block": "print ports",
|
||||
"brick.setLight|block": "set light to %pattern=led_pattern",
|
||||
"brick.setLight|block": "set light to %pattern",
|
||||
"brick.showImage|block": "show image %image=screen_image_picker",
|
||||
"brick.showNumber|block": "show number %name|at line %line",
|
||||
"brick.showString|block": "show string %text|at line %line",
|
||||
@ -93,7 +92,6 @@
|
||||
"{id:category}Serial": "Serial",
|
||||
"{id:group}Buttons": "Buttons",
|
||||
"{id:group}Counters": "Counters",
|
||||
"{id:group}Light": "Light",
|
||||
"{id:group}More": "More",
|
||||
"{id:group}Move": "Move",
|
||||
"{id:group}Screen": "Screen",
|
||||
|
@ -2,35 +2,35 @@
|
||||
/**
|
||||
* Patterns for lights under the buttons.
|
||||
*/
|
||||
const enum LightsPattern {
|
||||
//% block=Off enumval=0
|
||||
const enum BrickLight {
|
||||
//% block=off enumval=0
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Off = 0,
|
||||
//% block=Green enumval=1
|
||||
//% block=green enumval=1
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Green = 1,
|
||||
//% block=Red enumval=2
|
||||
//% block=red enumval=2
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Red = 2,
|
||||
//% block=Orange enumval=3
|
||||
//% block=orange enumval=3
|
||||
//% blockIdentity=brick.lightPattern
|
||||
Orange = 3,
|
||||
//% block="Flashing Green" enumval=4
|
||||
//% block="green flash" enumval=4
|
||||
//% blockIdentity=brick.lightPattern
|
||||
GreenFlash = 4,
|
||||
//% block="Flashing Red" enumval=5
|
||||
//% block="red flash" enumval=5
|
||||
//% blockIdentity=brick.lightPattern
|
||||
RedFlash = 5,
|
||||
//% block="Flashing Orange" enumval=6
|
||||
//% block="orange flash" enumval=6
|
||||
//% blockIdentity=brick.lightPattern
|
||||
OrangeFlash = 6,
|
||||
//% block="Pulsing Green" enumval=7
|
||||
//% block="green pulse" enumval=7
|
||||
//% blockIdentity=brick.lightPattern
|
||||
GreenPulse = 7,
|
||||
//% block="Pulsing Red" enumval=8
|
||||
//% block="red pulse" enumval=8
|
||||
//% blockIdentity=brick.lightPattern
|
||||
RedPulse = 8,
|
||||
//% block="Pulsing Orange" enumval=9
|
||||
//% block="orange pulse" enumval=9
|
||||
//% blockIdentity=brick.lightPattern
|
||||
OrangePulse = 9,
|
||||
}
|
||||
@ -252,32 +252,21 @@ namespace control {
|
||||
}
|
||||
|
||||
namespace brick {
|
||||
let currPattern: LightsPattern
|
||||
// the brick starts with the red color
|
||||
let currPattern: BrickLight = BrickLight.Red;
|
||||
|
||||
/**
|
||||
* Set lights.
|
||||
* @param pattern the lights pattern to use.
|
||||
* @param pattern the lights pattern to use. eg: BrickLight.Orange
|
||||
*/
|
||||
//% blockId=setLights block="set light to %pattern=led_pattern"
|
||||
//% blockId=setLights block="set light to %pattern"
|
||||
//% weight=100 group="Buttons"
|
||||
export function setLight(pattern: number): void {
|
||||
export function setLight(pattern: BrickLight): void {
|
||||
if (currPattern === pattern)
|
||||
return
|
||||
currPattern = pattern
|
||||
let cmd = output.createBuffer(2)
|
||||
currPattern = pattern;
|
||||
const cmd = output.createBuffer(2)
|
||||
cmd[0] = pattern + 48
|
||||
brick.internal.getBtnsMM().write(cmd)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pattern block.
|
||||
* @param pattern the lights pattern to use. eg: LightsPattern.Green
|
||||
*/
|
||||
//% blockId=led_pattern block="%pattern"
|
||||
//% shim=TD_ID colorSecondary="#6e9a36" group="Light"
|
||||
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
|
||||
export function lightPattern(pattern: LightsPattern): number {
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ screen.clear()
|
||||
brick.print("PXT!", 10, 30, Draw.Quad)
|
||||
|
||||
brick.drawRect(40, 40, 20, 10, Draw.Fill)
|
||||
brick.setLight(LightsPattern.Orange)
|
||||
brick.setLight(BrickLight.Orange)
|
||||
|
||||
brick.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent)
|
||||
|
||||
@ -12,7 +12,7 @@ brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, () => {
|
||||
brick.drawRect(10, 70, 20, 10, Draw.Fill)
|
||||
brick.setLight(LightsPattern.Red)
|
||||
brick.setLight(BrickLight.Red)
|
||||
brick.setFont(brick.microbitFont())
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user