don't allow decimals in led x y fields (#1389)
This commit is contained in:
parent
a5ee26ec4b
commit
1b7c51e5b5
@ -20,6 +20,7 @@ namespace led {
|
||||
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
void plot(int x, int y) {
|
||||
uBit.display.image.setPixelValue(x, y, 0xff);
|
||||
}
|
||||
@ -34,6 +35,7 @@ namespace led {
|
||||
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
//% advanced=true
|
||||
void plotBrightness(int x, int y, int brightness) {
|
||||
brightness = max(0, min(0xff, brightness));
|
||||
@ -52,6 +54,7 @@ namespace led {
|
||||
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
void unplot(int x, int y) {
|
||||
uBit.display.image.setPixelValue(x, y, 0);
|
||||
}
|
||||
@ -65,6 +68,7 @@ namespace led {
|
||||
//% blockId=device_point block="point|x %x|y %y"
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
bool point(int x, int y) {
|
||||
int pix = uBit.display.image.getPixelValue(x, y);
|
||||
return pix > 0;
|
||||
|
@ -62,6 +62,7 @@
|
||||
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
export function toggle(x: number, y: number): void {
|
||||
if (led.point(x, y)) {
|
||||
led.unplot(x, y);
|
||||
|
7
libs/core/shims.d.ts
vendored
7
libs/core/shims.d.ts
vendored
@ -467,6 +467,7 @@ declare namespace led {
|
||||
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
|
||||
//% advanced=true shim=led::plotBrightness
|
||||
function plotBrightness(x: int32, y: int32, brightness: int32): void;
|
||||
|
||||
@ -478,7 +479,8 @@ declare namespace led {
|
||||
//% help=led/unplot weight=77
|
||||
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::unplot
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::unplot
|
||||
function unplot(x: int32, y: int32): void;
|
||||
|
||||
/**
|
||||
@ -489,7 +491,8 @@ declare namespace led {
|
||||
//% help=led/point weight=76
|
||||
//% blockId=device_point block="point|x %x|y %y"
|
||||
//% parts="ledmatrix"
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::point
|
||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1 shim=led::point
|
||||
function point(x: int32, y: int32): boolean;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user