merging microbit
This commit is contained in:
@ -16,12 +16,14 @@ namespace pxsim {
|
||||
neopixelState: NeoPixelState;
|
||||
rgbLedState: number;
|
||||
speakerState: SpeakerState;
|
||||
microServoState: MicroServoState;
|
||||
servosState: MicroServosState;
|
||||
fileSystem: FileSystemState;
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
// components
|
||||
this.fileSystem = new FileSystemState();
|
||||
this.builtinParts["ledmatrix"] = this.ledMatrixState = new LedMatrixState(runtime);
|
||||
this.builtinParts["buttonpair"] = this.buttonPairState = new ButtonPairState({
|
||||
ID_BUTTON_A: DAL.MICROBIT_ID_BUTTON_A,
|
||||
@ -63,7 +65,12 @@ namespace pxsim {
|
||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||
this.builtinParts["speaker"] = this.speakerState = new SpeakerState();
|
||||
this.builtinParts["microservo"] = this.microServoState = new MicroServoState();
|
||||
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
|
||||
"P0": DAL.MICROBIT_ID_IO_P0,
|
||||
"P1": DAL.MICROBIT_ID_IO_P1,
|
||||
"P2": DAL.MICROBIT_ID_IO_P2,
|
||||
"P3": DAL.MICROBIT_ID_IO_P3
|
||||
});
|
||||
|
||||
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||
|
@ -72,12 +72,12 @@ namespace pxsim.pins {
|
||||
}
|
||||
|
||||
export function servoWritePin(pinId: number, value: number) {
|
||||
let pin = getPin(pinId);
|
||||
if (!pin) return;
|
||||
|
||||
analogSetPeriod(pinId, 20000);
|
||||
// TODO: per pin state
|
||||
if (board().microServoState.angle != value) {
|
||||
board().microServoState.angle = value;
|
||||
runtime.queueDisplayUpdate();
|
||||
}
|
||||
const state = board().servosState.servoState(pinId);
|
||||
state.setAngle(value);
|
||||
}
|
||||
|
||||
export function servoSetPulse(pinId: number, micros: number) {
|
||||
|
18
sim/state/filesystem.ts
Normal file
18
sim/state/filesystem.ts
Normal file
@ -0,0 +1,18 @@
|
||||
namespace pxsim.files {
|
||||
export function appendLine(filename: string, text: string) {
|
||||
const b = board();
|
||||
b.fileSystem.append(filename, text + "\r\n");
|
||||
}
|
||||
export function appendString(filename: string, text: string) {
|
||||
const b = board();
|
||||
b.fileSystem.append(filename, text);
|
||||
}
|
||||
export function appendNumber(filename: string, value: number) {
|
||||
const b = board();
|
||||
b.fileSystem.append(filename, value.toString());
|
||||
}
|
||||
export function remove(filename: string) {
|
||||
const b = board();
|
||||
b.fileSystem.remove(filename);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user