Block layout fixes. Fixes to screen blocks. Adding print line API.

This commit is contained in:
Sam El-Husseini 2018-01-03 14:00:08 -08:00
parent cc020d5a81
commit 4d671f6cb0
12 changed files with 28 additions and 40 deletions

View File

@ -29,17 +29,12 @@
"brick.clearScreen": "Clears the screen", "brick.clearScreen": "Clears the screen",
"brick.lightPattern": "Pattern block.", "brick.lightPattern": "Pattern block.",
"brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", "brick.lightPattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
"brick.print": "Show text on the screen.", "brick.printLine": "Show text on the screen at a specific line.",
"brick.printLine|param|line": "the line number to print the text at, eg: 0",
"brick.printLine|param|text": "the text to print on the screen, eg: \"Hello world\"",
"brick.printPorts": "Prints the port states on the screen", "brick.printPorts": "Prints the port states on the screen",
"brick.print|param|text": "the text to print on the screen, eg: \"Hello world\"",
"brick.print|param|x": "the starting position's x coordinate, eg: 0",
"brick.print|param|y": "the starting position's x coordinate, eg: 0",
"brick.setLight": "Set lights.", "brick.setLight": "Set lights.",
"brick.setLight|param|pattern": "the lights pattern to use.", "brick.setLight|param|pattern": "the lights pattern to use.",
"brick.setPixel": "Sets a pixel on or off",
"brick.setPixel|param|on": "a value indicating if the pixel should be on or off",
"brick.setPixel|param|x": "the starting position's x coordinate, eg: 0",
"brick.setPixel|param|y": "the starting position's x coordinate, eg: 0",
"brick.showImage": "Shows an image on screen", "brick.showImage": "Shows an image on screen",
"brick.showImage|param|image": "image to draw", "brick.showImage|param|image": "image to draw",
"console": "Reading and writing data to the console output.\n\nReading and writing data to the console output.", "console": "Reading and writing data to the console output.\n\nReading and writing data to the console output.",

View File

@ -35,10 +35,9 @@
"brick.buttonUp|block": "up", "brick.buttonUp|block": "up",
"brick.clearScreen|block": "clear screen", "brick.clearScreen|block": "clear screen",
"brick.lightPattern|block": "%pattern", "brick.lightPattern|block": "%pattern",
"brick.printLine|block": "print %text| at line: %line",
"brick.printPorts|block": "print ports", "brick.printPorts|block": "print ports",
"brick.print|block": "print %text| at x: %x| y: %y",
"brick.setLight|block": "set light to %pattern=led_pattern", "brick.setLight|block": "set light to %pattern=led_pattern",
"brick.setPixel|block": "set pixel %on| at x: %x| y: %y",
"brick.showImage|block": "show image %image=screen_image_picker", "brick.showImage|block": "show image %image=screen_image_picker",
"brick|block": "brick", "brick|block": "brick",
"console.logValue|block": "console|log value %name|= %value", "console.logValue|block": "console|log value %name|= %value",

View File

@ -105,7 +105,7 @@ namespace brick {
//% blockId=buttonWasPressed //% blockId=buttonWasPressed
//% parts="brick" //% parts="brick"
//% blockNamespace=brick //% blockNamespace=brick
//% weight=80 blockGap=8 //% weight=80
//% group="Buttons" //% group="Buttons"
wasPressed() { wasPressed() {
const r = this._wasPressed const r = this._wasPressed

View File

@ -80,15 +80,6 @@ namespace brick {
} }
} }
/**
* Sets a pixel on or off
* @param on a value indicating if the pixel should be on or off
* @param x the starting position's x coordinate, eg: 0
* @param y the starting position's x coordinate, eg: 0
*/
//% blockId=screen_setpixel block="set pixel %on| at x: %x| y: %y"
//% weight=98 group="Screen"
//% x.min=0 x.max=178 y.min=0 y.max=128 on.fieldEditor=toggleonoff
export function setPixel(on: boolean, x: number, y: number) { export function setPixel(on: boolean, x: number, y: number) {
x |= 0 x |= 0
y |= 0 y |= 0
@ -97,14 +88,20 @@ namespace brick {
} }
/** /**
* Show text on the screen. * Show text on the screen at a specific line.
* @param text the text to print on the screen, eg: "Hello world" * @param text the text to print on the screen, eg: "Hello world"
* @param x the starting position's x coordinate, eg: 0 * @param line the line number to print the text at, eg: 0
* @param y the starting position's x coordinate, eg: 0
*/ */
//% blockId=screen_print block="print %text| at x: %x| y: %y" //% blockId=screen_print block="print %text| at line: %line"
//% weight=99 group="Screen" inlineInputMode="inline" blockGap=8 //% weight=98 group="Screen" inlineInputMode="inline" blockGap=8
//% x.min=0 x.max=178 y.min=0 y.max=128 //% line.min=0 line.max=9
export function printLine(text: string, line: number) {
const NUM_LINES = 9;
const offset = 5;
const y = offset + (Math.clamp(0, NUM_LINES, line) / (NUM_LINES + 2)) * DAL.LCD_HEIGHT;
brick.print(text, offset, y);
}
export function print(text: string, x: number, y: number, mode = Draw.Normal) { export function print(text: string, x: number, y: number, mode = Draw.Normal) {
x |= 0 x |= 0
y |= 0 y |= 0
@ -140,7 +137,7 @@ namespace brick {
* @param image image to draw * @param image image to draw
*/ */
//% blockId=screen_show_image block="show image %image=screen_image_picker" //% blockId=screen_show_image block="show image %image=screen_image_picker"
//% weight=95 group="Screen" blockGap=8 //% weight=100 group="Screen" blockGap=8
export function showImage(image: Image, delay: number = 400) { export function showImage(image: Image, delay: number = 400) {
if (!image) return; if (!image) return;
image.draw(0, 0, Draw.Normal); image.draw(0, 0, Draw.Normal);
@ -166,7 +163,7 @@ namespace brick {
* Clears the screen * Clears the screen
*/ */
//% blockId=screen_clear_screen block="clear screen" //% blockId=screen_clear_screen block="clear screen"
//% weight=94 group="Screen" blockGap=8 //% weight=90 group="Screen"
export function clearScreen() { export function clearScreen() {
screen.clear(); screen.clear();
} }

View File

@ -112,7 +112,7 @@ namespace sensors {
//% blockId=remotebuttonWasPressed //% blockId=remotebuttonWasPressed
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=80 blockGap=8 //% weight=80
//% group="Remote Infrared Beacon" //% group="Remote Infrared Beacon"
wasPressed() { wasPressed() {
return this.button.wasPressed(); return this.button.wasPressed();
@ -238,7 +238,7 @@ namespace sensors {
//% blockId=infraredGetRemoteCommand //% blockId=infraredGetRemoteCommand
//% parts="infrared" //% parts="infrared"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=65 blockGap=8 //% weight=65
//% group="Infrared Sensor" //% group="Infrared Sensor"
remoteCommand(): number { remoteCommand(): number {
this._setMode(IrSensorMode.RemoteControl) this._setMode(IrSensorMode.RemoteControl)

View File

@ -2,8 +2,6 @@
"Sound.buffer": "Returns the underlaying Buffer object.", "Sound.buffer": "Returns the underlaying Buffer object.",
"Sound.play": "Play sound.", "Sound.play": "Play sound.",
"music": "Generation of music tones.", "music": "Generation of music tones.",
"music._soundPicker": "A sound",
"music._soundPicker|param|sound": "the sound",
"music.beat": "Return the duration of a beat in milliseconds (the beat fraction).", "music.beat": "Return the duration of a beat in milliseconds (the beat fraction).",
"music.beat|param|fraction": "the fraction of the current whole note, eg: BeatFraction.Half", "music.beat|param|fraction": "the fraction of the current whole note, eg: BeatFraction.Half",
"music.changeTempoBy": "Change the tempo up or down by some amount of beats per minute (bpm).", "music.changeTempoBy": "Change the tempo up or down by some amount of beats per minute (bpm).",

View File

@ -20,7 +20,6 @@
"Note.GSharp|block": "G#", "Note.GSharp|block": "G#",
"SoundOutputDestination.Pin|block": "pin", "SoundOutputDestination.Pin|block": "pin",
"SoundOutputDestination.Speaker|block": "speaker", "SoundOutputDestination.Speaker|block": "speaker",
"music._soundPicker|block": "%sound",
"music.beat|block": "%fraction|beat", "music.beat|block": "%fraction|beat",
"music.changeTempoBy|block": "change tempo by %value|(bpm)", "music.changeTempoBy|block": "change tempo by %value|(bpm)",
"music.noteFrequency|block": "%note", "music.noteFrequency|block": "%note",

View File

@ -170,7 +170,7 @@ void playTone(int frequency, int ms) {
//% blockId=music_stop_all_sounds block="stop all sounds" //% blockId=music_stop_all_sounds block="stop all sounds"
//% parts="headphone" //% parts="headphone"
//% blockNamespace=music //% blockNamespace=music
//% weight=76 blockGap=8 //% weight=97
void stopAllSounds() { void stopAllSounds() {
if (currentSample) { if (currentSample) {
samplePtr = currentSample->length; samplePtr = currentSample->length;

View File

@ -32,7 +32,7 @@ declare namespace music {
//% blockId=music_stop_all_sounds block="stop all sounds" //% blockId=music_stop_all_sounds block="stop all sounds"
//% parts="headphone" //% parts="headphone"
//% blockNamespace=music //% blockNamespace=music
//% weight=76 blockGap=8 shim=music::stopAllSounds //% weight=97 shim=music::stopAllSounds
function stopAllSounds(): void; function stopAllSounds(): void;
/** Makes a sound bound to a buffer in WAV format. */ /** Makes a sound bound to a buffer in WAV format. */

View File

@ -264,7 +264,7 @@ namespace music {
* @param sound the sound to play * @param sound the sound to play
*/ */
//% blockId=music_play_sound_effect_until_done block="play sound effect %sound|until done" //% blockId=music_play_sound_effect_until_done block="play sound effect %sound|until done"
//% weight=98 //% weight=98 blockGap=8
export function playSoundEffectUntilDone(sound: Sound) { export function playSoundEffectUntilDone(sound: Sound) {
if (!sound) return; if (!sound) return;
sound.play(); sound.play();
@ -276,7 +276,7 @@ namespace music {
*/ */
//% blockId=music_sound_picker block="%sound" shim=TD_ID //% blockId=music_sound_picker block="%sound" shim=TD_ID
//% weight=0 blockHidden=1 //% weight=0 blockHidden=1
export function _soundPicker(sound: Sound): Sound { export function __soundPicker(sound: Sound): Sound {
return sound; return sound;
} }
@ -285,7 +285,7 @@ namespace music {
* @param sound the sound to play * @param sound the sound to play
*/ */
//% blockId=music_play_sound_effect block="play sound effect %sound" //% blockId=music_play_sound_effect block="play sound effect %sound"
//% weight=99 //% weight=99 blockGap=8
export function playSoundEffect(sound: Sound) { export function playSoundEffect(sound: Sound) {
if (!sound || numSoundsPlaying >= soundsLimit) return; if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++; numSoundsPlaying++;

View File

@ -75,7 +75,7 @@ namespace sensors {
//% blockId=touchIsPressed //% blockId=touchIsPressed
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=81 blockGap=8 //% weight=81
//% group="Touch Sensor" //% group="Touch Sensor"
isPressed() { isPressed() {
return this.button.isPressed(); return this.button.isPressed();

View File

@ -75,7 +75,7 @@ namespace sensors {
//% blockId=sonarGetDistance //% blockId=sonarGetDistance
//% parts="ultrasonicsensor" //% parts="ultrasonicsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=65 blockGap=8 //% weight=65
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
distance(): number { distance(): number {
// it supposedly also has an inch mode, but we stick to cm // it supposedly also has an inch mode, but we stick to cm