added led.enable (#294)

* added led.enable

* fixed simulator support for led.enable
This commit is contained in:
Peli de Halleux 2016-10-28 08:34:04 -07:00 committed by GitHub
parent c6e38bd7a9
commit 76adc3c00a
8 changed files with 98 additions and 20 deletions

View File

@ -91,3 +91,10 @@ basic.showString("d", 150)
You will not see the LED at position `0,0` lit up because the `show string` function overwrites the whole display buffer. You will not see the LED at position `0,0` lit up because the `show string` function overwrites the whole display buffer.
### Pins: P3, P4, P6, P7, P9, P10
These pins are coupled to the LED matrix display, and also its associated ambient light sensing mode.
To disable the display driver feature (which will automatically disable the light sensing feature) use the function [led.enable](/reference/led/enable).
More information at http://tech.microbit.org/hardware/edgeconnector_ds/ .

View File

@ -17,8 +17,9 @@ led.plotAll();
led.screenshot(); led.screenshot();
led.toggleAll(); led.toggleAll();
led.setDisplayMode(DisplayMode.BackAndWhite); led.setDisplayMode(DisplayMode.BackAndWhite);
led.enable(false)
``` ```
### See Also ### See Also
[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode) [plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode), [enabled](/reference/led/enable)

View File

@ -0,0 +1,33 @@
# Enable
Turns the LED screen on and off
```sig
led.enable(false);
```
### Parameters
* ``on`` is a [boolean](/reference/types/boolean) that defines the on/off state of the screen
### Example: Turning off the screen
This program turns off the screen when pressing button ``B``
```typescript
input.onButtonPressed(Button.B, () => {
led.enable(false)
});
```
### Pins: P3, P4, P6, P7, P9, P10
These pins are coupled to the LED matrix display, and also its associated ambient light sensing mode.
To disable the display driver feature (which will automatically disable the light sensing feature) call the DAL function ``led.enable(false)``.
To turn the display driver back on again later, call ``led.enable(true)``.
More information at http://tech.microbit.org/hardware/edgeconnector_ds/ .
### See also
[unplot](/reference/led/unplot), [point](/reference/led/point), [LED screen](/device/screen)

View File

@ -84,14 +84,24 @@ namespace led {
/** /**
* Sets the display mode between black and white and greyscale for rendering LEDs. * Sets the display mode between black and white and greyscale for rendering LEDs.
* @param mode TODO * @param mode mode the display mode in which the screen operates
*/ */
//% weight=1 help=led/set-display-mode //% weight=1 help=led/set-display-mode
//% parts="ledmatrix" //% parts="ledmatrix" advanced=true
void setDisplayMode(DisplayMode_ mode) { void setDisplayMode(DisplayMode_ mode) {
uBit.display.setDisplayMode((DisplayMode)mode); uBit.display.setDisplayMode((DisplayMode)mode);
} }
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable icon="\uf04d"
//% advanced=true parts="ledmatrix"
void enable(bool on) {
if (on) uBit.display.enable();
else uBit.display.disable();
}
/** /**
* Takes a screenshot of the LED screen and returns an image. * Takes a screenshot of the LED screen and returns an image.
*/ */

11
libs/core/shims.d.ts vendored
View File

@ -488,12 +488,19 @@ declare namespace led {
/** /**
* Sets the display mode between black and white and greyscale for rendering LEDs. * Sets the display mode between black and white and greyscale for rendering LEDs.
* @param mode TODO * @param mode mode the display mode in which the screen operates
*/ */
//% weight=1 help=led/set-display-mode //% weight=1 help=led/set-display-mode
//% parts="ledmatrix" shim=led::setDisplayMode //% parts="ledmatrix" advanced=true shim=led::setDisplayMode
function setDisplayMode(mode: DisplayMode): void; function setDisplayMode(mode: DisplayMode): void;
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable icon="\uf04d"
//% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void;
/** /**
* Takes a screenshot of the LED screen and returns an image. * Takes a screenshot of the LED screen and returns an image.
*/ */

View File

@ -9,6 +9,7 @@ namespace pxsim {
brigthness = 255; brigthness = 255;
displayMode = DisplayMode.bw; displayMode = DisplayMode.bw;
font: Image = createFont(); font: Image = createFont();
disabled: boolean;
animationQ: AnimationQueue; animationQ: AnimationQueue;
@ -284,4 +285,8 @@ namespace pxsim.led {
board().ledMatrixState.image.copyTo(0, 5, img, 0); board().ledMatrixState.image.copyTo(0, 5, img, 0);
return img; return img;
} }
export function enable(on: boolean) {
board().ledMatrixState.disabled = !on;
runtime.queueDisplayUpdate();
}
} }

View File

@ -101,8 +101,16 @@ namespace pxsim.visuals {
} }
public updateState() { public updateState() {
let bw = this.state.displayMode == pxsim.DisplayMode.bw if (this.state.disabled) {
let img = this.state.image; this.leds.forEach((led, i) => {
let sel = (<SVGStylable><any>led)
sel.style.opacity = 0 + "";
});
return;
}
const bw = this.state.displayMode == pxsim.DisplayMode.bw
const img = this.state.image;
this.leds.forEach((led, i) => { this.leds.forEach((led, i) => {
let sel = (<SVGStylable><any>led) let sel = (<SVGStylable><any>led)
let dx = i % this.DRAW_SIZE; let dx = i % this.DRAW_SIZE;

View File

@ -334,12 +334,19 @@ namespace pxsim.visuals {
svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp); svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp);
}); });
let bw = state.ledMatrixState.displayMode == pxsim.DisplayMode.bw if (state.ledMatrixState.disabled) {
let img = state.ledMatrixState.image;
this.leds.forEach((led, i) => { this.leds.forEach((led, i) => {
let sel = (<SVGStylable><any>led) const sel = (<SVGStylable><any>led)
sel.style.opacity = "0";
})
} else {
const bw = state.ledMatrixState.displayMode == pxsim.DisplayMode.bw
const img = state.ledMatrixState.image;
this.leds.forEach((led, i) => {
const sel = (<SVGStylable><any>led)
sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + ""; sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + "";
}) })
}
this.updatePins(); this.updatePins();
this.updateTilt(); this.updateTilt();
this.updateHeading(); this.updateHeading();