basic servo simulation (#297)

This commit is contained in:
Peli de Halleux
2016-11-01 08:16:03 -07:00
committed by GitHub
parent 237c5c019b
commit 4963bf776a
5 changed files with 49 additions and 7 deletions

View File

@ -12,7 +12,9 @@ namespace pxsim {
lightSensorState: LightSensorState;
buttonPairState: ButtonPairState;
radioState: RadioState;
// TODO: not singletons
neopixelState: NeoPixelState;
microServoState: MicroServoState;
constructor() {
super()
@ -48,7 +50,7 @@ namespace pxsim {
0,
0,
DAL.MICROBIT_ID_IO_P19,
DAL.MICROBIT_ID_IO_P20
DAL.MICROBIT_ID_IO_P20
]
});
this.builtinParts["radio"] = this.radioState = new RadioState(runtime);
@ -58,14 +60,17 @@ 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.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
this.builtinVisuals["neopixel"] = () => new visuals.NeoPixelView();
this.builtinVisuals["neopixel"] = () => new visuals.NeoPixelView();
this.builtinVisuals["microservo"] = () => new visuals.MicroServoView();
this.builtinPartVisuals["buttonpair"] = (xy: visuals.Coord) => visuals.mkBtnSvg(xy);
this.builtinPartVisuals["ledmatrix"] = (xy: visuals.Coord) => visuals.mkLedMatrixSvg(xy, 8, 8);
this.builtinPartVisuals["neopixel"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy);
this.builtinPartVisuals["neopixel"] = (xy: visuals.Coord) => visuals.mkNeoPixelPart(xy);
this.builtinPartVisuals["microservo"] = (xy: visuals.Coord) => visuals.mkMicroServoPart(xy);
}
receiveMessage(msg: SimulatorMessage) {
@ -97,7 +102,7 @@ namespace pxsim {
const cmpDefs = msg.partDefinitions || {};
const fnArgs = msg.fnArgs;
const opts : visuals.BoardHostOpts = {
const opts: visuals.BoardHostOpts = {
state: this,
boardDef: boardDef,
partsList: cmpsList,

View File

@ -11,7 +11,7 @@ namespace pxsim.input {
if (!pin) return;
pin.isTouched();
pxtcore.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_UP, handler);
}
}
export function pinIsPressed(pinId: number): boolean {
let pin = getPin(pinId);
@ -73,7 +73,11 @@ namespace pxsim.pins {
export function servoWritePin(pinId: number, value: number) {
analogSetPeriod(pinId, 20000);
// TODO
// TODO: per pin state
if (board().microServoState.angle != value) {
board().microServoState.angle = value;
runtime.queueDisplayUpdate();
}
}
export function servoSetPulse(pinId: number, micros: number) {