Bump V3.0.22 (#110)
* change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin Co-authored-by: Juri <gitkraken@juriwolf.de>
This commit is contained in:
@ -16,6 +16,7 @@ namespace pxsim.input {
|
||||
|
||||
export function isGesture(gesture: number): boolean {
|
||||
const b = accForGesture(gesture);
|
||||
b.accelerometer.activate();
|
||||
return b.accelerometer.getGesture() == gesture;
|
||||
}
|
||||
|
||||
@ -33,28 +34,25 @@ namespace pxsim.input {
|
||||
acc.activate(AccelerometerFlag.Z);
|
||||
return acc.getZ();
|
||||
default:
|
||||
acc.activate();
|
||||
return Math.floor(Math.sqrt(acc.instantaneousAccelerationSquared()));
|
||||
acc.activate(AccelerometerFlag.Strength);
|
||||
return acc.getStrength();
|
||||
}
|
||||
}
|
||||
|
||||
export function rotation(kind: number): number {
|
||||
const b = board().accelerometerState;
|
||||
const acc = b.accelerometer;
|
||||
acc.activate();
|
||||
const x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
const y = acc.getY(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
const z = acc.getZ(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||
|
||||
const roll = Math.atan2(y, z);
|
||||
const pitch = Math.atan(-x / (y * Math.sin(roll) + z * Math.cos(roll)));
|
||||
|
||||
let r = 0;
|
||||
switch (kind) {
|
||||
case 0: r = pitch; break;
|
||||
case 1: r = roll; break;
|
||||
case 0: {
|
||||
acc.activate(AccelerometerFlag.Pitch);
|
||||
return acc.getPitch();
|
||||
}
|
||||
case 1: {
|
||||
acc.activate(AccelerometerFlag.Roll);
|
||||
return acc.getRoll();
|
||||
}
|
||||
default: return 0;
|
||||
}
|
||||
return Math.floor(r / Math.PI * 180);
|
||||
}
|
||||
|
||||
export function setAccelerometerRange(range: number) {
|
||||
@ -117,8 +115,11 @@ namespace pxsim {
|
||||
|
||||
export enum AccelerometerFlag {
|
||||
X = 1,
|
||||
Y = 2,
|
||||
Z = 4
|
||||
Y = 1 << 1,
|
||||
Z = 1 << 2,
|
||||
Strength = 1 << 3,
|
||||
Pitch = 1 << 4,
|
||||
Roll = 1 << 5
|
||||
}
|
||||
|
||||
export class Accelerometer {
|
||||
@ -148,7 +149,7 @@ namespace pxsim {
|
||||
this.isActive = true;
|
||||
this.runtime.queueDisplayUpdate();
|
||||
}
|
||||
if (flags)
|
||||
if (!!flags)
|
||||
this.flags |= flags;
|
||||
}
|
||||
|
||||
@ -169,7 +170,29 @@ namespace pxsim {
|
||||
board().bus.queue(this.id, DAL.MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE)
|
||||
}
|
||||
|
||||
public instantaneousAccelerationSquared() {
|
||||
public getStrength() {
|
||||
return Math.floor(Math.sqrt(this.instantaneousAccelerationSquared()));
|
||||
}
|
||||
|
||||
updateEnvironmentGlobals() {
|
||||
// update debugger
|
||||
if (this.isActive) {
|
||||
if (this.flags & AccelerometerFlag.X)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.x")] = this.sample.x;
|
||||
if (this.flags & AccelerometerFlag.Y)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.y")] = this.sample.y;
|
||||
if (this.flags & AccelerometerFlag.Z)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.z")] = this.sample.z;
|
||||
if (this.flags & AccelerometerFlag.Strength)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.strength")] = Math.sqrt(this.instantaneousAccelerationSquared());
|
||||
if (this.flags & AccelerometerFlag.Pitch)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.pitch")] = this.getPitch();
|
||||
if (this.flags & AccelerometerFlag.Roll)
|
||||
this.runtime.environmentGlobals[pxsim.localization.lf("acceleration.roll")] = this.getRoll();
|
||||
}
|
||||
}
|
||||
|
||||
private instantaneousAccelerationSquared() {
|
||||
// Use pythagoras theorem to determine the combined force acting on the device.
|
||||
return this.sample.x * this.sample.x + this.sample.y * this.sample.y + this.sample.z * this.sample.z;
|
||||
}
|
||||
@ -294,7 +317,6 @@ namespace pxsim {
|
||||
* @endcode
|
||||
*/
|
||||
public getX(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
|
||||
this.activate();
|
||||
switch (system) {
|
||||
case MicroBitCoordinateSystem.SIMPLE_CARTESIAN:
|
||||
return -this.sample.x;
|
||||
@ -319,7 +341,6 @@ namespace pxsim {
|
||||
* @endcode
|
||||
*/
|
||||
public getY(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
|
||||
this.activate();
|
||||
switch (system) {
|
||||
case MicroBitCoordinateSystem.SIMPLE_CARTESIAN:
|
||||
return -this.sample.y;
|
||||
@ -344,7 +365,6 @@ namespace pxsim {
|
||||
* @endcode
|
||||
*/
|
||||
public getZ(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
|
||||
this.activate();
|
||||
switch (system) {
|
||||
case MicroBitCoordinateSystem.NORTH_EAST_DOWN:
|
||||
return -this.sample.z;
|
||||
@ -365,7 +385,6 @@ namespace pxsim {
|
||||
* @endcode
|
||||
*/
|
||||
public getPitch(): number {
|
||||
this.activate();
|
||||
return Math.floor((360 * this.getPitchRadians()) / (2 * Math.PI));
|
||||
}
|
||||
|
||||
@ -384,7 +403,6 @@ namespace pxsim {
|
||||
* @endcode
|
||||
*/
|
||||
public getRoll(): number {
|
||||
this.activate();
|
||||
return Math.floor((360 * this.getRollRadians()) / (2 * Math.PI));
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace pxsim.pins {
|
||||
export function setPull(pinId: number, pull: number) {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
pin.pull = pull;
|
||||
pin.setPull(pull);
|
||||
}
|
||||
|
||||
export function analogReadPin(pinId: number): number {
|
||||
@ -61,7 +61,7 @@ namespace pxsim.pins {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
pin.mode = PinFlags.Analog | PinFlags.Output;
|
||||
pin.value = value ? value : 0;
|
||||
pin.value = value | 0;
|
||||
runtime.queueDisplayUpdate();
|
||||
}
|
||||
|
||||
@ -101,22 +101,38 @@ namespace pxsim.pins {
|
||||
pin.pitch = true;
|
||||
}
|
||||
|
||||
export function analogSetPitchVolume(volume: number) {
|
||||
const ec = board().edgeConnectorState;
|
||||
ec.pitchVolume = Math.max(0, Math.min(0xff, volume | 0));
|
||||
}
|
||||
|
||||
export function analogPitchVolume() {
|
||||
const ec = board().edgeConnectorState;
|
||||
return ec.pitchVolume;
|
||||
}
|
||||
|
||||
export function analogPitch(frequency: number, ms: number) {
|
||||
// update analog output
|
||||
let pins = board().edgeConnectorState.pins;
|
||||
let pin = pins.filter(pin => !!pin && pin.pitch)[0] || pins[0];
|
||||
const b = board();
|
||||
if (!b) return;
|
||||
const ec = b.edgeConnectorState;
|
||||
const pins = ec.pins;
|
||||
const pin = pins.filter(pin => !!pin && pin.pitch)[0] || pins[0];
|
||||
const pitchVolume = ec.pitchVolume | 0;
|
||||
pin.mode = PinFlags.Analog | PinFlags.Output;
|
||||
if (frequency <= 0) {
|
||||
if (frequency <= 0 || pitchVolume <= 0) {
|
||||
pin.value = 0;
|
||||
pin.period = 0;
|
||||
} else {
|
||||
pin.value = 512;
|
||||
const v = 1 << (pitchVolume >> 5);
|
||||
pin.value = v;
|
||||
pin.period = 1000000 / frequency;
|
||||
}
|
||||
runtime.queueDisplayUpdate();
|
||||
|
||||
let cb = getResume();
|
||||
AudioContextManager.tone(frequency, 1);
|
||||
const v = pitchVolume / 0xff;
|
||||
AudioContextManager.tone(frequency, v);
|
||||
if (ms <= 0) cb();
|
||||
else {
|
||||
setTimeout(() => {
|
||||
@ -129,4 +145,11 @@ namespace pxsim.pins {
|
||||
}, ms);
|
||||
}
|
||||
}
|
||||
|
||||
export function pushButton(pinId: number) {
|
||||
const b = board();
|
||||
if (!b) return;
|
||||
const ec = b.edgeConnectorState;
|
||||
// TODO support buttons here
|
||||
}
|
||||
}
|
@ -86,9 +86,11 @@ namespace pxsim {
|
||||
|
||||
export class EdgeConnectorState {
|
||||
pins: Pin[];
|
||||
pitchVolume: number;
|
||||
|
||||
constructor(public props: EdgeConnectorProps) {
|
||||
this.pins = props.pins.map(id => id != undefined ? new Pin(id) : null);
|
||||
this.pitchVolume = 0xff
|
||||
}
|
||||
|
||||
public getPin(id: number) {
|
||||
|
@ -19,51 +19,52 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export class Image extends RefObject {
|
||||
public static height: number = 5;
|
||||
public height: number;
|
||||
public width: number;
|
||||
public data: number[];
|
||||
constructor(width: number, data: number[]) {
|
||||
super();
|
||||
this.width = width;
|
||||
this.data = data;
|
||||
this.height = (this.data.length / this.width) | 0;
|
||||
}
|
||||
public print() {
|
||||
console.debug(`Image id:${this.id} size:${this.width}x${Image.height}`)
|
||||
console.debug(`Image id:${this.id} size:${this.width}x${this.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;
|
||||
x = x | 0;
|
||||
y = y | 0;
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= this.height) 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;
|
||||
x = x | 0;
|
||||
y = y | 0;
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= this.height) 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;
|
||||
xSrcIndex = xSrcIndex | 0;
|
||||
length = length | 0;
|
||||
xTargetIndex = xTargetIndex | 0;
|
||||
for (let x = 0; x < length; x++) {
|
||||
for (let y = 0; y < 5; y++) {
|
||||
for (let y = 0; y < this.height; y++) {
|
||||
let value = this.get(xSrcIndex + x, y);
|
||||
target.set(xTargetIndex + x, y, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public shiftLeft(cols: number) {
|
||||
cols = cols >> 0;
|
||||
cols = cols | 0;
|
||||
for (let x = 0; x < this.width; ++x)
|
||||
for (let y = 0; y < 5; ++y)
|
||||
for (let y = 0; y < this.height; ++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)
|
||||
for (let y = 0; y < this.height; ++y)
|
||||
this.set(x, y, x >= cols ? this.get(x - cols, y) : 0);
|
||||
}
|
||||
|
||||
@ -85,7 +86,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export function createImageFromBuffer(data: number[]): Image {
|
||||
return new Image(data.length / 5, data);
|
||||
return new Image((data.length / 5) | 0, data);
|
||||
}
|
||||
|
||||
export function createImageFromString(text: string): Image {
|
||||
@ -110,15 +111,14 @@ namespace pxsim {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
export const FONT_DATA = [0x0, 0x0, 0x0, 0x0, 0x0, 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0x1c, 0x92, 0x52, 0x52, 0x0, 0xc, 0x92, 0x52, 0x4c, 0x0, 0x1c, 0x92, 0x5c, 0x90, 0x0, 0xe, 0xd2, 0x4e, 0xc2, 0x0, 0xe, 0xd0, 0x10, 0x10, 0x0, 0x6, 0xc8, 0x4, 0x98, 0x8, 0x8, 0xe, 0xc8, 0x7, 0x0, 0x12, 0x52, 0x52, 0x4f, 0x0, 0x11, 0x31, 0x2a, 0x44, 0x0, 0x11, 0x31, 0x35, 0xbb, 0x0, 0x12, 0x4c, 0x8c, 0x92, 0x0, 0x11, 0x2a, 0x44, 0x98, 0x0, 0x1e, 0xc4, 0x88, 0x1e, 0x6, 0xc4, 0x8c, 0x84, 0x86, 0x8, 0x8, 0x8, 0x8, 0x8, 0x18, 0x8, 0xc, 0x88, 0x18, 0x0, 0x0, 0xc, 0x83, 0x60];
|
||||
export function createFont(): Image {
|
||||
const data = [0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x8, 0x8, 0x0, 0x8, 0xa, 0x4a, 0x40, 0x0, 0x0, 0xa, 0x5f, 0xea, 0x5f, 0xea, 0xe, 0xd9, 0x2e, 0xd3, 0x6e, 0x19, 0x32, 0x44, 0x89, 0x33, 0xc, 0x92, 0x4c, 0x92, 0x4d, 0x8, 0x8, 0x0, 0x0, 0x0, 0x4, 0x88, 0x8, 0x8, 0x4, 0x8, 0x4, 0x84, 0x84, 0x88, 0x0, 0xa, 0x44, 0x8a, 0x40, 0x0, 0x4, 0x8e, 0xc4, 0x80, 0x0, 0x0, 0x0, 0x4, 0x88, 0x0, 0x0, 0xe, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x1, 0x22, 0x44, 0x88, 0x10, 0xc, 0x92, 0x52, 0x52, 0x4c, 0x4, 0x8c, 0x84, 0x84, 0x8e, 0x1c, 0x82, 0x4c, 0x90, 0x1e, 0x1e, 0xc2, 0x44, 0x92, 0x4c, 0x6, 0xca, 0x52, 0x5f, 0xe2, 0x1f, 0xf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8, 0x8, 0xe, 0x10, 0x8, 0x4, 0x82, 0x41, 0xe, 0xc2, 0x42, 0x42, 0x4e, 0x4, 0x8a, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x8, 0x4, 0x80, 0x0, 0x0, 0x0, 0xe, 0xd2, 0x52, 0x4f, 0x10, 0x10, 0x1c, 0x92, 0x5c, 0x0, 0xe, 0xd0, 0x10, 0xe, 0x2, 0x42, 0x4e, 0xd2, 0x4e, 0xc, 0x92, 0x5c, 0x90, 0xe, 0x6, 0xc8, 0x1c, 0x88, 0x8, 0xe, 0xd2, 0x4e, 0xc2, 0x4c, 0x10, 0x10, 0x1c, 0x92, 0x52, 0x8, 0x0, 0x8, 0x8, 0x8, 0x2, 0x40, 0x2, 0x42, 0x4c, 0x10, 0x14, 0x98, 0x14, 0x92, 0x8, 0x8, 0x8, 0x8, 0x6, 0x0, 0x1b, 0x75, 0xb1, 0x31, 0x0, 0x1c, 0x92, 0x52, 0x52, 0x0, 0xc, 0x92, 0x52, 0x4c, 0x0, 0x1c, 0x92, 0x5c, 0x90, 0x0, 0xe, 0xd2, 0x4e, 0xc2, 0x0, 0xe, 0xd0, 0x10, 0x10, 0x0, 0x6, 0xc8, 0x4, 0x98, 0x8, 0x8, 0xe, 0xc8, 0x7, 0x0, 0x12, 0x52, 0x52, 0x4f, 0x0, 0x11, 0x31, 0x2a, 0x44, 0x0, 0x11, 0x31, 0x35, 0xbb, 0x0, 0x12, 0x4c, 0x8c, 0x92, 0x0, 0x11, 0x2a, 0x44, 0x98, 0x0, 0x1e, 0xc4, 0x88, 0x1e, 0x6, 0xc4, 0x8c, 0x84, 0x86, 0x8, 0x8, 0x8, 0x8, 0x8, 0x18, 0x8, 0xc, 0x88, 0x18, 0x0, 0x0, 0xc, 0x83, 0x60];
|
||||
|
||||
let nb = data.length;
|
||||
let nb = FONT_DATA.length;
|
||||
let n = nb / 5;
|
||||
let font = createInternalImage(nb);
|
||||
for (let c = 0; c < n; c++) {
|
||||
for (let row = 0; row < 5; row++) {
|
||||
let char = data[c * 5 + row];
|
||||
let char = FONT_DATA[c * 5 + row];
|
||||
for (let col = 0; col < 5; col++) {
|
||||
if ((char & (1 << col)) != 0)
|
||||
font.set((c * 5 + 4) - col, row, 255);
|
||||
@ -129,6 +129,24 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.fonts {
|
||||
export function charCodeBuffer(charCode: number): RefBuffer {
|
||||
if (charCode < DAL.MICROBIT_FONT_ASCII_START || charCode > DAL.MICROBIT_FONT_ASCII_END)
|
||||
return undefined;
|
||||
|
||||
const b = board();
|
||||
const led = b.ledMatrixState;
|
||||
const font = led.font;
|
||||
const h = font.height;
|
||||
const w = font.width;
|
||||
const buf = control.createBuffer(h);
|
||||
const offset = (charCode - DAL.MICROBIT_FONT_ASCII_START) * h;
|
||||
for (let row = 0; row < h; ++row)
|
||||
buf.data[row] = FONT_DATA[offset + row];
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
namespace pxsim.images {
|
||||
export function createImage(img: Image) {
|
||||
return img
|
||||
@ -177,7 +195,7 @@ namespace pxsim.ImageMethods {
|
||||
|
||||
export function height(leds: Image): number {
|
||||
pxtrt.nullCheck(leds)
|
||||
return Image.height;
|
||||
return leds.height;
|
||||
}
|
||||
|
||||
export function width(leds: Image): number {
|
||||
@ -186,11 +204,11 @@ namespace pxsim.ImageMethods {
|
||||
}
|
||||
|
||||
export function plotFrame(leds: Image, frame: number) {
|
||||
ImageMethods.plotImage(leds, frame * Image.height);
|
||||
ImageMethods.plotImage(leds, frame * leds.height);
|
||||
}
|
||||
|
||||
export function showFrame(leds: Image, frame: number, interval: number) {
|
||||
ImageMethods.showImage(leds, frame * Image.height, interval);
|
||||
ImageMethods.showImage(leds, frame * leds.height, interval);
|
||||
}
|
||||
|
||||
export function pixel(leds: Image, x: number, y: number): number {
|
||||
@ -268,7 +286,7 @@ namespace pxsim.ImageMethods {
|
||||
|
||||
namespace pxsim.basic {
|
||||
export function showNumber(x: number, interval: number) {
|
||||
interval = interval >> 0;
|
||||
interval |= 0;
|
||||
if (interval <= 0)
|
||||
interval = 1;
|
||||
let leds = createImageFromString(x.toString());
|
||||
@ -277,7 +295,7 @@ namespace pxsim.basic {
|
||||
}
|
||||
|
||||
export function showString(s: string, interval: number) {
|
||||
interval = interval >> 0;
|
||||
interval |= 0;
|
||||
if (interval <= 0)
|
||||
interval = 1;
|
||||
if (s.length == 0) {
|
||||
@ -291,6 +309,7 @@ namespace pxsim.basic {
|
||||
}
|
||||
|
||||
export function showLeds(leds: Image, interval: number): void {
|
||||
interval |= 0;
|
||||
showAnimation(leds, interval);
|
||||
}
|
||||
|
||||
@ -300,6 +319,7 @@ namespace pxsim.basic {
|
||||
}
|
||||
|
||||
export function showAnimation(leds: Image, interval: number): void {
|
||||
interval |= 0;
|
||||
ImageMethods.scrollImage(leds, 5, interval);
|
||||
}
|
||||
|
||||
@ -310,13 +330,17 @@ namespace pxsim.basic {
|
||||
|
||||
namespace pxsim.led {
|
||||
export function plot(x: number, y: number) {
|
||||
x |= 0;
|
||||
y |= 0;
|
||||
board().ledMatrixState.image.set(x, y, 0xff);
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
export function plotBrightness(x: number, y: number, brightness: number) {
|
||||
x |= 0;
|
||||
y |= 0;
|
||||
const state = board().ledMatrixState;
|
||||
brightness = brightness >> 0;
|
||||
brightness |= 0;
|
||||
brightness = Math.max(0, Math.min(led.brightness(), brightness));
|
||||
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
||||
state.displayMode = DisplayMode.greyscale;
|
||||
@ -325,12 +349,16 @@ namespace pxsim.led {
|
||||
}
|
||||
|
||||
export function unplot(x: number, y: number) {
|
||||
x |= 0;
|
||||
y |= 0;
|
||||
board().ledMatrixState.image.set(x, y, 0);
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
||||
export function point(x: number, y: number): boolean {
|
||||
return !!board().ledMatrixState.image.get(x, y);
|
||||
export function pointBrightness(x: number, y: number): number {
|
||||
x |= 0;
|
||||
y |= 0;
|
||||
return board().ledMatrixState.image.get(x, y);
|
||||
}
|
||||
|
||||
export function brightness(): number {
|
||||
@ -338,7 +366,7 @@ namespace pxsim.led {
|
||||
}
|
||||
|
||||
export function setBrightness(value: number): void {
|
||||
value = value >> 0;
|
||||
value |= 0;
|
||||
board().ledMatrixState.brigthness = Math.max(0, Math.min(255, value));
|
||||
runtime.queueDisplayUpdate()
|
||||
}
|
||||
|
@ -136,6 +136,10 @@ namespace pxsim.pins {
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function spiTransfer(cmd: RefBuffer, resp: RefBuffer): void {
|
||||
// TODO
|
||||
}
|
||||
|
||||
export function spiFrequency(f: number): void {
|
||||
// TODO
|
||||
}
|
||||
@ -219,7 +223,7 @@ namespace pxsim.bluetooth {
|
||||
}
|
||||
|
||||
export function uartReadBuffer(): RefBuffer {
|
||||
return pins.createBuffer(0);
|
||||
return pins.createBuffer(0);
|
||||
}
|
||||
|
||||
export function uartReadUntil(del: string): string {
|
||||
@ -241,3 +245,14 @@ namespace pxsim.bluetooth {
|
||||
export function setTransmitPower(power: number) { }
|
||||
}
|
||||
|
||||
namespace pxsim.light {
|
||||
export function sendWS2812Buffer(buffer: RefBuffer, pin: number) {
|
||||
pxsim.sendBufferAsm(buffer, pin)
|
||||
}
|
||||
|
||||
export function setMode(pin: number, mode: number) {
|
||||
const lp = neopixelState(pin);
|
||||
if (!lp) return;
|
||||
lp.mode = mode & 0xff;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
namespace pxsim {
|
||||
export function sendBufferAsm(buffer: RefBuffer, pin: DigitalPin) {
|
||||
let b = board();
|
||||
if (b) {
|
||||
let np = b.neopixelState;
|
||||
if (np) {
|
||||
let buf = buffer.data;
|
||||
np.updateBuffer(buf as any, pin); // TODO this is wrong
|
||||
runtime.queueDisplayUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -73,8 +73,13 @@ namespace pxsim.serial {
|
||||
}
|
||||
|
||||
export function readBuffer(length: number) {
|
||||
length |= 0;
|
||||
if (length <= 0)
|
||||
length = 64;
|
||||
return pins.createBuffer(length);
|
||||
}
|
||||
|
||||
export function setBaudRate(rate: number) {
|
||||
// TODO
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user