From 7117ba771ea527bca6108aa77fd70c612df38ece Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 7 Nov 2016 22:25:19 -0800 Subject: [PATCH] support for multiple simulated servos --- sim/dalboard.ts | 9 +++++++-- sim/state/edgeconnector.ts | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sim/dalboard.ts b/sim/dalboard.ts index 3bccacf8..b471248c 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -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(); diff --git a/sim/state/edgeconnector.ts b/sim/state/edgeconnector.ts index feae5343..06577223 100644 --- a/sim/state/edgeconnector.ts +++ b/sim/state/edgeconnector.ts @@ -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) {