upgrading various simulator parts
This commit is contained in:
parent
433e8c8805
commit
88934881f9
@ -18,6 +18,9 @@ namespace pxsim {
|
|||||||
speakerState: SpeakerState;
|
speakerState: SpeakerState;
|
||||||
fileSystem: FileSystemState;
|
fileSystem: FileSystemState;
|
||||||
|
|
||||||
|
// visual
|
||||||
|
view: SVGElement;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ namespace pxsim {
|
|||||||
break;
|
break;
|
||||||
case "serial":
|
case "serial":
|
||||||
let data = (<SimulatorSerialMessage>msg).data || "";
|
let data = (<SimulatorSerialMessage>msg).data || "";
|
||||||
this.serialState.recieveData(data);
|
this.serialState.receiveData(data);
|
||||||
break;
|
break;
|
||||||
case "radiopacket":
|
case "radiopacket":
|
||||||
let packet = <SimulatorRadioPacketMessage>msg;
|
let packet = <SimulatorRadioPacketMessage>msg;
|
||||||
@ -121,16 +124,22 @@ namespace pxsim {
|
|||||||
fnArgs: fnArgs,
|
fnArgs: fnArgs,
|
||||||
maxWidth: "100%",
|
maxWidth: "100%",
|
||||||
maxHeight: "100%",
|
maxHeight: "100%",
|
||||||
|
highContrast: msg.highContrast
|
||||||
};
|
};
|
||||||
const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
|
const viewHost = new visuals.BoardHost(pxsim.visuals.mkBoardView({
|
||||||
visual: boardDef.visual
|
visual: boardDef.visual,
|
||||||
|
highContrast: msg.highContrast
|
||||||
}), opts);
|
}), opts);
|
||||||
|
|
||||||
document.body.innerHTML = ""; // clear children
|
document.body.innerHTML = ""; // clear children
|
||||||
document.body.appendChild(viewHost.getView());
|
document.body.appendChild(this.view = viewHost.getView());
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
screenshot(): string {
|
||||||
|
return svg.toDataUri(new XMLSerializer().serializeToString(this.view));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initRuntimeWithDalBoard() {
|
export function initRuntimeWithDalBoard() {
|
||||||
|
@ -28,7 +28,7 @@ namespace pxsim {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
public print() {
|
public print() {
|
||||||
console.log(`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 {
|
||||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||||
@ -131,15 +131,33 @@ 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)
|
||||||
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
|
let cb = getResume();
|
||||||
runtime.queueDisplayUpdate()
|
let first = true;
|
||||||
basic.pause(interval);
|
|
||||||
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
|
interval,
|
||||||
|
frame: () => {
|
||||||
|
if (first) {
|
||||||
|
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
|
||||||
|
first = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
whenDone: cb
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function plotImage(leds: Image, offset: number): void {
|
export function plotImage(leds: Image, offset: number): void {
|
||||||
pxtrt.nullCheck(leds)
|
pxtrt.nullCheck(leds)
|
||||||
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
|
|
||||||
runtime.queueDisplayUpdate()
|
board().ledMatrixState.animationQ.enqueue({
|
||||||
|
interval: 0,
|
||||||
|
frame: () => {
|
||||||
|
leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function height(leds: Image): number {
|
export function height(leds: Image): number {
|
||||||
@ -216,15 +234,16 @@ namespace pxsim.ImageMethods {
|
|||||||
|
|
||||||
namespace pxsim.basic {
|
namespace pxsim.basic {
|
||||||
export function showNumber(x: number, interval: number) {
|
export function showNumber(x: number, interval: number) {
|
||||||
if (interval < 0) return;
|
if (interval <= 0)
|
||||||
|
interval = 1;
|
||||||
let leds = createImageFromString(x.toString());
|
let leds = createImageFromString(x.toString());
|
||||||
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval);
|
if (x < 0 || x >= 10) ImageMethods.scrollImage(leds, 1, interval);
|
||||||
else showLeds(leds, interval * 5);
|
else showLeds(leds, interval * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showString(s: string, interval: number) {
|
export function showString(s: string, interval: number) {
|
||||||
if (interval < 0) return;
|
if (interval <= 0)
|
||||||
|
interval = 1;
|
||||||
if (s.length == 0) {
|
if (s.length == 0) {
|
||||||
clearScreen();
|
clearScreen();
|
||||||
pause(interval * 5);
|
pause(interval * 5);
|
||||||
@ -254,7 +273,16 @@ namespace pxsim.basic {
|
|||||||
|
|
||||||
namespace pxsim.led {
|
namespace pxsim.led {
|
||||||
export function plot(x: number, y: number) {
|
export function plot(x: number, y: number) {
|
||||||
board().ledMatrixState.image.set(x, y, 255);
|
board().ledMatrixState.image.set(x, y, 0xff);
|
||||||
|
runtime.queueDisplayUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function plotBrightness(x: number, y: number, brightness: number) {
|
||||||
|
const state = board().ledMatrixState;
|
||||||
|
brightness = Math.max(0, Math.min(0xff, brightness));
|
||||||
|
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
||||||
|
state.displayMode = DisplayMode.greyscale;
|
||||||
|
state.image.set(x, y, brightness);
|
||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +300,7 @@ namespace pxsim.led {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setBrightness(value: number): void {
|
export function setBrightness(value: number): void {
|
||||||
board().ledMatrixState.brigthness = value;
|
board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
|
||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +314,7 @@ namespace pxsim.led {
|
|||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function displayMode() : DisplayMode {
|
export function displayMode(): DisplayMode {
|
||||||
return board().ledMatrixState.displayMode;
|
return board().ledMatrixState.displayMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
namespace pxsim {
|
namespace pxsim {
|
||||||
|
const SERIAL_BUFFER_LENGTH = 16;
|
||||||
export class SerialState {
|
export class SerialState {
|
||||||
serialIn: string[] = [];
|
serialIn: string[] = [];
|
||||||
|
|
||||||
public recieveData(data: string) {
|
public receiveData(data: string) {
|
||||||
this.serialIn.push();
|
this.serialIn.push();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,18 +14,15 @@ namespace pxsim {
|
|||||||
|
|
||||||
serialOutBuffer: string = "";
|
serialOutBuffer: string = "";
|
||||||
writeSerial(s: string) {
|
writeSerial(s: string) {
|
||||||
for (let i = 0; i < s.length; ++i) {
|
this.serialOutBuffer += s;
|
||||||
let c = s[i];
|
if (/\n/.test(this.serialOutBuffer) || this.serialOutBuffer.length > SERIAL_BUFFER_LENGTH) {
|
||||||
this.serialOutBuffer += c;
|
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||||
if (c == "\n") {
|
type: 'serial',
|
||||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
data: this.serialOutBuffer,
|
||||||
type: "serial",
|
id: runtime.id,
|
||||||
data: this.serialOutBuffer,
|
sim: true
|
||||||
id: runtime.id
|
})
|
||||||
})
|
this.serialOutBuffer = '';
|
||||||
this.serialOutBuffer = ""
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,4 +49,8 @@ namespace pxsim.serial {
|
|||||||
export function redirect(tx: number, rx: number, rate: number) {
|
export function redirect(tx: number, rx: number, rate: number) {
|
||||||
// TODO?
|
// TODO?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function redirectToUSB() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user