Fix pattern enum decompilation and setSpeed when no speed is set.
This commit is contained in:
		@@ -3,6 +3,16 @@
 | 
				
			|||||||
  "ButtonEvent.Down|block": "down",
 | 
					  "ButtonEvent.Down|block": "down",
 | 
				
			||||||
  "ButtonEvent.LongClick|block": "long click",
 | 
					  "ButtonEvent.LongClick|block": "long click",
 | 
				
			||||||
  "ButtonEvent.Up|block": "up",
 | 
					  "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",
 | 
				
			||||||
  "control.raiseEvent|block": "raise event|from %src|with value %value",
 | 
					  "control.raiseEvent|block": "raise event|from %src|with value %value",
 | 
				
			||||||
  "control|block": "control",
 | 
					  "control|block": "control",
 | 
				
			||||||
  "input.buttonDown|block": "button down",
 | 
					  "input.buttonDown|block": "button down",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,15 +3,35 @@
 | 
				
			|||||||
 * Patterns for lights under the buttons.
 | 
					 * Patterns for lights under the buttons.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
const enum LightsPattern {
 | 
					const enum LightsPattern {
 | 
				
			||||||
 | 
					    //% block=Off enumval=0
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    Off = 0,
 | 
					    Off = 0,
 | 
				
			||||||
 | 
					    //% block=Green enumval=1
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    Green = 1,
 | 
					    Green = 1,
 | 
				
			||||||
 | 
					    //% block=Red enumval=2
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    Red = 2,
 | 
					    Red = 2,
 | 
				
			||||||
 | 
					    //% block=Orange enumval=3
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    Orange = 3,
 | 
					    Orange = 3,
 | 
				
			||||||
 | 
					    //% block="Flashing Green" enumval=4
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    GreenFlash = 4,
 | 
					    GreenFlash = 4,
 | 
				
			||||||
 | 
					    //% block="Flashing Red" enumval=5
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    RedFlash = 5,
 | 
					    RedFlash = 5,
 | 
				
			||||||
 | 
					    //% block="Flashing Orange" enumval=6
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    OrangeFlash = 6,
 | 
					    OrangeFlash = 6,
 | 
				
			||||||
 | 
					    //% block="Pulsing Green" enumval=7
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    GreenPulse = 7,
 | 
					    GreenPulse = 7,
 | 
				
			||||||
 | 
					    //% block="Pulsing Red" enumval=8
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    RedPulse = 8,
 | 
					    RedPulse = 8,
 | 
				
			||||||
 | 
					    //% block="Pulsing Orange" enumval=9
 | 
				
			||||||
 | 
					    //% blockIdentity=output.getPattern
 | 
				
			||||||
    OrangePulse = 9,
 | 
					    OrangePulse = 9,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -238,7 +258,7 @@ namespace output {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    //% blockId=led_pattern block="%pattern"
 | 
					    //% blockId=led_pattern block="%pattern"
 | 
				
			||||||
    //% shim=TD_ID colorSecondary="#6e9a36"
 | 
					    //% shim=TD_ID colorSecondary="#6e9a36"
 | 
				
			||||||
    //% blockHidden=true
 | 
					    //% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
 | 
				
			||||||
    export function getPattern(pattern: LightsPattern): number {
 | 
					    export function getPattern(pattern: LightsPattern): number {
 | 
				
			||||||
        return pattern;
 | 
					        return pattern;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ enum OutputType {
 | 
				
			|||||||
namespace output {
 | 
					namespace output {
 | 
				
			||||||
    let pwmMM: MMap
 | 
					    let pwmMM: MMap
 | 
				
			||||||
    let motorMM: MMap
 | 
					    let motorMM: MMap
 | 
				
			||||||
 | 
					    let currentSpeed: number[] = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const enum MotorDataOff {
 | 
					    const enum MotorDataOff {
 | 
				
			||||||
        TachoCounts = 0, // int32
 | 
					        TachoCounts = 0, // int32
 | 
				
			||||||
@@ -32,6 +33,12 @@ namespace output {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        stop(Output.ALL)
 | 
					        stop(Output.ALL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        currentSpeed[Output.A] = -1;
 | 
				
			||||||
 | 
					        currentSpeed[Output.B] = -1;
 | 
				
			||||||
 | 
					        currentSpeed[Output.C] = -1;
 | 
				
			||||||
 | 
					        currentSpeed[Output.D] = -1;
 | 
				
			||||||
 | 
					        currentSpeed[Output.ALL] = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let buf = output.createBuffer(1)
 | 
					        let buf = output.createBuffer(1)
 | 
				
			||||||
        buf[0] = DAL.opProgramStart
 | 
					        buf[0] = DAL.opProgramStart
 | 
				
			||||||
        writePWM(buf)
 | 
					        writePWM(buf)
 | 
				
			||||||
@@ -65,10 +72,11 @@ namespace output {
 | 
				
			|||||||
    export function turn(out: Output, ms: number, useBrake = false) {
 | 
					    export function turn(out: Output, ms: number, useBrake = false) {
 | 
				
			||||||
        // TODO: use current power / speed configuration
 | 
					        // TODO: use current power / speed configuration
 | 
				
			||||||
        output.step(out, {
 | 
					        output.step(out, {
 | 
				
			||||||
            power: 100,
 | 
					            speed: 100,
 | 
				
			||||||
            step1: 0,
 | 
					            step1: 0,
 | 
				
			||||||
            step2: ms,
 | 
					            step2: ms,
 | 
				
			||||||
            step3: 0,
 | 
					            step3: 0,
 | 
				
			||||||
 | 
					            useSteps: false,
 | 
				
			||||||
            useBrake: useBrake
 | 
					            useBrake: useBrake
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -92,6 +100,7 @@ namespace output {
 | 
				
			|||||||
    //% blockId=output_start block="turn motor %out|on"
 | 
					    //% blockId=output_start block="turn motor %out|on"
 | 
				
			||||||
    //% weight=95 group="Motors"
 | 
					    //% weight=95 group="Motors"
 | 
				
			||||||
    export function start(out: Output) {
 | 
					    export function start(out: Output) {
 | 
				
			||||||
 | 
					        if (currentSpeed[out] == -1) setSpeed(out, 50)
 | 
				
			||||||
        let b = mkCmd(out, DAL.opOutputStart, 0)
 | 
					        let b = mkCmd(out, DAL.opOutputStart, 0)
 | 
				
			||||||
        writePWM(b)
 | 
					        writePWM(b)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -154,6 +163,7 @@ namespace output {
 | 
				
			|||||||
    //% weight=81 group="Motors"
 | 
					    //% weight=81 group="Motors"
 | 
				
			||||||
    //% speed.min=-100 speed.max=100
 | 
					    //% speed.min=-100 speed.max=100
 | 
				
			||||||
    export function setSpeed(out: Output, speed: number) {
 | 
					    export function setSpeed(out: Output, speed: number) {
 | 
				
			||||||
 | 
					        currentSpeed[out] = speed;
 | 
				
			||||||
        let b = mkCmd(out, DAL.opOutputSpeed, 1)
 | 
					        let b = mkCmd(out, DAL.opOutputSpeed, 1)
 | 
				
			||||||
        b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-100, 100, speed))
 | 
					        b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-100, 100, speed))
 | 
				
			||||||
        writePWM(b)
 | 
					        writePWM(b)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,6 +94,7 @@ namespace screen {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    //% blockId=screen_drawText block="print %text| at x: %x| y: %y"
 | 
					    //% blockId=screen_drawText block="print %text| at x: %x| y: %y"
 | 
				
			||||||
    //% weight=99 group="Screen" blockNamespace=output inlineInputMode="inline"
 | 
					    //% weight=99 group="Screen" blockNamespace=output inlineInputMode="inline"
 | 
				
			||||||
 | 
					    //% x.min=0 x.max=178 y.min=0 y.max=128
 | 
				
			||||||
    export function drawText(text: string, x: number, y: number, mode = Draw.Normal) {
 | 
					    export function drawText(text: string, x: number, y: number, mode = Draw.Normal) {
 | 
				
			||||||
        x |= 0
 | 
					        x |= 0
 | 
				
			||||||
        y |= 0
 | 
					        y |= 0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +1,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//% color="#D42878"
 | 
					//% color="#D42878"
 | 
				
			||||||
//% groups="['Brick buttons']"
 | 
					//% groups='["Brick buttons"]'
 | 
				
			||||||
namespace input {
 | 
					namespace input {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//% color="#8AC044" weight=90 icon="\uf185"
 | 
					//% color="#8AC044" weight=90 icon="\uf185"
 | 
				
			||||||
//% groups="['Lights', 'Screen', Motors']"
 | 
					//% groups='["Lights", "Screen", "Motors"]'
 | 
				
			||||||
namespace output {
 | 
					namespace output {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user