various missing float -> int (#1364)
This commit is contained in:
parent
c6fa65763b
commit
2cf0bba259
@ -23,7 +23,7 @@ namespace pxsim {
|
|||||||
return this.value > 100 ? 1 : 0;
|
return this.value > 100 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWritePin(value: number) {
|
digitalWritePin(value: number) {
|
||||||
this.mode = PinFlags.Digital | PinFlags.Output;
|
this.mode = PinFlags.Digital | PinFlags.Output;
|
||||||
this.value = value > 0 ? 200 : 0;
|
this.value = value > 0 ? 200 : 0;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
@ -39,18 +39,21 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
analogWritePin(value: number) {
|
analogWritePin(value: number) {
|
||||||
|
value = value >> 0;
|
||||||
this.mode = PinFlags.Analog | PinFlags.Output;
|
this.mode = PinFlags.Analog | PinFlags.Output;
|
||||||
this.value = Math.max(0, Math.min(1023, value));
|
this.value = Math.max(0, Math.min(1023, value));
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
analogSetPeriod(micros: number) {
|
analogSetPeriod(micros: number) {
|
||||||
|
micros = micros >> 0;
|
||||||
this.mode = PinFlags.Analog | PinFlags.Output;
|
this.mode = PinFlags.Analog | PinFlags.Output;
|
||||||
this.period = micros;
|
this.period = micros;
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
servoWritePin(value: number) {
|
servoWritePin(value: number) {
|
||||||
|
value = value >> 0;
|
||||||
this.analogSetPeriod(20000);
|
this.analogSetPeriod(20000);
|
||||||
this.servoAngle = Math.max(0, Math.min(180, value));
|
this.servoAngle = Math.max(0, Math.min(180, value));
|
||||||
runtime.queueDisplayUpdate();
|
runtime.queueDisplayUpdate();
|
||||||
|
@ -31,14 +31,21 @@ namespace pxsim {
|
|||||||
console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||||
}
|
}
|
||||||
public get(x: number, y: number): number {
|
public get(x: number, y: number): number {
|
||||||
|
x = x >> 0;
|
||||||
|
y = y >> 0;
|
||||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||||
return this.data[y * this.width + x];
|
return this.data[y * this.width + x];
|
||||||
}
|
}
|
||||||
public set(x: number, y: number, v: number) {
|
public set(x: number, y: number, v: number) {
|
||||||
|
x = x >> 0;
|
||||||
|
y = y >> 0;
|
||||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return;
|
if (x < 0 || x >= this.width || y < 0 || y >= 5) return;
|
||||||
this.data[y * this.width + x] = Math.max(0, Math.min(255, v));
|
this.data[y * this.width + x] = Math.max(0, Math.min(255, v));
|
||||||
}
|
}
|
||||||
public copyTo(xSrcIndex: number, length: number, target: Image, xTargetIndex: number): void {
|
public copyTo(xSrcIndex: number, length: number, target: Image, xTargetIndex: number): void {
|
||||||
|
xSrcIndex = xSrcIndex >> 0;
|
||||||
|
length = length >> 0;
|
||||||
|
xTargetIndex = xTargetIndex >> 0;
|
||||||
for (let x = 0; x < length; x++) {
|
for (let x = 0; x < length; x++) {
|
||||||
for (let y = 0; y < 5; y++) {
|
for (let y = 0; y < 5; y++) {
|
||||||
let value = this.get(xSrcIndex + x, y);
|
let value = this.get(xSrcIndex + x, y);
|
||||||
@ -47,12 +54,14 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public shiftLeft(cols: number) {
|
public shiftLeft(cols: number) {
|
||||||
|
cols = cols >> 0;
|
||||||
for (let x = 0; x < this.width; ++x)
|
for (let x = 0; x < this.width; ++x)
|
||||||
for (let y = 0; y < 5; ++y)
|
for (let y = 0; y < 5; ++y)
|
||||||
this.set(x, y, x < this.width - cols ? this.get(x + cols, y) : 0);
|
this.set(x, y, x < this.width - cols ? this.get(x + cols, y) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public shiftRight(cols: number) {
|
public shiftRight(cols: number) {
|
||||||
|
cols = cols >> 0;
|
||||||
for (let x = this.width - 1; x >= 0; --x)
|
for (let x = this.width - 1; x >= 0; --x)
|
||||||
for (let y = 0; y < 5; ++y)
|
for (let y = 0; y < 5; ++y)
|
||||||
this.set(x, y, x >= cols ? this.get(x - cols, y) : 0);
|
this.set(x, y, x >= cols ? this.get(x - cols, y) : 0);
|
||||||
@ -65,12 +74,14 @@ namespace pxsim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createInternalImage(width: number): Image {
|
export function createInternalImage(width: number): Image {
|
||||||
|
width = width >> 0;
|
||||||
let img = createImage(width)
|
let img = createImage(width)
|
||||||
pxsim.runtime.unregisterLiveObject(img, true)
|
pxsim.runtime.unregisterLiveObject(img, true)
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createImage(width: number): Image {
|
export function createImage(width: number): Image {
|
||||||
|
width = width >> 0;
|
||||||
return new Image(width, new Array(width * 5));
|
return new Image(width, new Array(width * 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +142,8 @@ namespace pxsim.images {
|
|||||||
namespace pxsim.ImageMethods {
|
namespace pxsim.ImageMethods {
|
||||||
export function showImage(leds: Image, offset: number, interval: number) {
|
export function showImage(leds: Image, offset: number, interval: number) {
|
||||||
pxtrt.nullCheck(leds)
|
pxtrt.nullCheck(leds)
|
||||||
|
offset = offset >> 0;
|
||||||
|
interval = interval >> 0;
|
||||||
let cb = getResume();
|
let cb = getResume();
|
||||||
let first = true;
|
let first = true;
|
||||||
|
|
||||||
@ -151,6 +164,7 @@ namespace pxsim.ImageMethods {
|
|||||||
|
|
||||||
export function plotImage(leds: Image, offset: number): void {
|
export function plotImage(leds: Image, offset: number): void {
|
||||||
pxtrt.nullCheck(leds)
|
pxtrt.nullCheck(leds)
|
||||||
|
offset = offset >> 0;
|
||||||
|
|
||||||
leds = clampPixelBrightness(leds);
|
leds = clampPixelBrightness(leds);
|
||||||
board().ledMatrixState.animationQ.enqueue({
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
@ -207,6 +221,8 @@ namespace pxsim.ImageMethods {
|
|||||||
|
|
||||||
export function scrollImage(leds: Image, stride: number, interval: number): void {
|
export function scrollImage(leds: Image, stride: number, interval: number): void {
|
||||||
pxtrt.nullCheck(leds)
|
pxtrt.nullCheck(leds)
|
||||||
|
stride = stride >> 0;
|
||||||
|
interval = interval >> 0;
|
||||||
if (stride == 0) stride = 1;
|
if (stride == 0) stride = 1;
|
||||||
|
|
||||||
let cb = getResume();
|
let cb = getResume();
|
||||||
@ -253,6 +269,7 @@ namespace pxsim.ImageMethods {
|
|||||||
|
|
||||||
namespace pxsim.basic {
|
namespace pxsim.basic {
|
||||||
export function showNumber(x: number, interval: number) {
|
export function showNumber(x: number, interval: number) {
|
||||||
|
interval = interval >> 0;
|
||||||
if (interval <= 0)
|
if (interval <= 0)
|
||||||
interval = 1;
|
interval = 1;
|
||||||
let leds = createImageFromString(x.toString());
|
let leds = createImageFromString(x.toString());
|
||||||
@ -261,6 +278,7 @@ namespace pxsim.basic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function showString(s: string, interval: number) {
|
export function showString(s: string, interval: number) {
|
||||||
|
interval = interval >> 0;
|
||||||
if (interval <= 0)
|
if (interval <= 0)
|
||||||
interval = 1;
|
interval = 1;
|
||||||
if (s.length == 0) {
|
if (s.length == 0) {
|
||||||
@ -299,6 +317,7 @@ namespace pxsim.led {
|
|||||||
|
|
||||||
export function plotBrightness(x: number, y: number, brightness: number) {
|
export function plotBrightness(x: number, y: number, brightness: number) {
|
||||||
const state = board().ledMatrixState;
|
const state = board().ledMatrixState;
|
||||||
|
brightness = brightness >> 0;
|
||||||
brightness = Math.max(0, Math.min(led.brightness(), brightness));
|
brightness = Math.max(0, Math.min(led.brightness(), brightness));
|
||||||
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
||||||
state.displayMode = DisplayMode.greyscale;
|
state.displayMode = DisplayMode.greyscale;
|
||||||
@ -320,6 +339,7 @@ namespace pxsim.led {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setBrightness(value: number): void {
|
export function setBrightness(value: number): void {
|
||||||
|
value = value >> 0;
|
||||||
board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
|
board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
|
||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user