support for multiple simulated servos

This commit is contained in:
Peli de Halleux 2016-11-07 22:25:19 -08:00
parent 633522c800
commit 7117ba771e
2 changed files with 12 additions and 7 deletions

View File

@ -14,7 +14,7 @@ namespace pxsim {
radioState: RadioState;
// TODO: not singletons
neopixelState: NeoPixelState;
microServoState: MicroServoState;
servosState: MicroServosState;
fileSystem: FileSystemState;
constructor() {
@ -62,7 +62,12 @@ namespace pxsim {
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
this.builtinParts["compass"] = this.compassState = new CompassState();
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
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();

View File

@ -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) {