various missing float -> int (#1364)

This commit is contained in:
Peli de Halleux 2018-10-09 09:45:10 -07:00 committed by GitHub
parent c6fa65763b
commit 2cf0bba259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -23,7 +23,7 @@ namespace pxsim {
return this.value > 100 ? 1 : 0;
}
digitalWritePin(value: number) {
digitalWritePin(value: number) {
this.mode = PinFlags.Digital | PinFlags.Output;
this.value = value > 0 ? 200 : 0;
runtime.queueDisplayUpdate();
@ -39,18 +39,21 @@ namespace pxsim {
}
analogWritePin(value: number) {
value = value >> 0;
this.mode = PinFlags.Analog | PinFlags.Output;
this.value = Math.max(0, Math.min(1023, value));
runtime.queueDisplayUpdate();
}
analogSetPeriod(micros: number) {
micros = micros >> 0;
this.mode = PinFlags.Analog | PinFlags.Output;
this.period = micros;
runtime.queueDisplayUpdate();
}
servoWritePin(value: number) {
value = value >> 0;
this.analogSetPeriod(20000);
this.servoAngle = Math.max(0, Math.min(180, value));
runtime.queueDisplayUpdate();

View File

@ -31,14 +31,21 @@ namespace pxsim {
console.debug(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
}
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;
return this.data[y * this.width + x];
}
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;
this.data[y * this.width + x] = Math.max(0, Math.min(255, v));
}
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 y = 0; y < 5; y++) {
let value = this.get(xSrcIndex + x, y);
@ -47,12 +54,14 @@ namespace pxsim {
}
}
public shiftLeft(cols: number) {
cols = cols >> 0;
for (let x = 0; x < this.width; ++x)
for (let y = 0; y < 5; ++y)
this.set(x, y, x < this.width - cols ? this.get(x + cols, y) : 0);
}
public shiftRight(cols: number) {
cols = cols >> 0;
for (let x = this.width - 1; x >= 0; --x)
for (let y = 0; y < 5; ++y)
this.set(x, y, x >= cols ? this.get(x - cols, y) : 0);
@ -65,12 +74,14 @@ namespace pxsim {
}
export function createInternalImage(width: number): Image {
width = width >> 0;
let img = createImage(width)
pxsim.runtime.unregisterLiveObject(img, true)
return img
}
export function createImage(width: number): Image {
width = width >> 0;
return new Image(width, new Array(width * 5));
}
@ -131,6 +142,8 @@ namespace pxsim.images {
namespace pxsim.ImageMethods {
export function showImage(leds: Image, offset: number, interval: number) {
pxtrt.nullCheck(leds)
offset = offset >> 0;
interval = interval >> 0;
let cb = getResume();
let first = true;
@ -151,6 +164,7 @@ namespace pxsim.ImageMethods {
export function plotImage(leds: Image, offset: number): void {
pxtrt.nullCheck(leds)
offset = offset >> 0;
leds = clampPixelBrightness(leds);
board().ledMatrixState.animationQ.enqueue({
@ -207,6 +221,8 @@ namespace pxsim.ImageMethods {
export function scrollImage(leds: Image, stride: number, interval: number): void {
pxtrt.nullCheck(leds)
stride = stride >> 0;
interval = interval >> 0;
if (stride == 0) stride = 1;
let cb = getResume();
@ -253,6 +269,7 @@ namespace pxsim.ImageMethods {
namespace pxsim.basic {
export function showNumber(x: number, interval: number) {
interval = interval >> 0;
if (interval <= 0)
interval = 1;
let leds = createImageFromString(x.toString());
@ -261,6 +278,7 @@ namespace pxsim.basic {
}
export function showString(s: string, interval: number) {
interval = interval >> 0;
if (interval <= 0)
interval = 1;
if (s.length == 0) {
@ -299,6 +317,7 @@ namespace pxsim.led {
export function plotBrightness(x: number, y: number, brightness: number) {
const state = board().ledMatrixState;
brightness = brightness >> 0;
brightness = Math.max(0, Math.min(led.brightness(), brightness));
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
state.displayMode = DisplayMode.greyscale;
@ -320,6 +339,7 @@ namespace pxsim.led {
}
export function setBrightness(value: number): void {
value = value >> 0;
board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
runtime.queueDisplayUpdate()
}