2016-08-30 20:55:00 +02:00
|
|
|
namespace pxsim {
|
|
|
|
export class DalBoard extends BaseBoard {
|
|
|
|
id: string;
|
|
|
|
|
|
|
|
// the bus
|
|
|
|
bus: EventBus;
|
|
|
|
|
|
|
|
// state & update logic for component services
|
|
|
|
ledMatrixState: LedMatrixState;
|
|
|
|
edgeConnectorState: EdgeConnectorState;
|
|
|
|
serialState: SerialState;
|
|
|
|
accelerometerState: AccelerometerState;
|
|
|
|
compassState: CompassState;
|
|
|
|
thermometerState: ThermometerState;
|
|
|
|
lightSensorState: LightSensorState;
|
|
|
|
buttonPairState: ButtonPairState;
|
|
|
|
radioState: RadioState;
|
|
|
|
neopixelState: NeoPixelState;
|
|
|
|
|
2016-08-30 23:13:44 +02:00
|
|
|
// updates
|
|
|
|
updateSubscribers: (() => void)[];
|
|
|
|
|
2016-08-30 20:55:00 +02:00
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
this.id = "b" + Math_.random(2147483647);
|
|
|
|
this.bus = new EventBus(runtime);
|
|
|
|
|
|
|
|
// components
|
|
|
|
this.ledMatrixState = new LedMatrixState(runtime);
|
|
|
|
this.buttonPairState = new ButtonPairState();
|
|
|
|
this.edgeConnectorState = new EdgeConnectorState();
|
|
|
|
this.radioState = new RadioState(runtime);
|
|
|
|
this.accelerometerState = new AccelerometerState(runtime);
|
|
|
|
this.serialState = new SerialState();
|
|
|
|
this.thermometerState = new ThermometerState();
|
|
|
|
this.lightSensorState = new LightSensorState();
|
|
|
|
this.compassState = new CompassState();
|
|
|
|
this.neopixelState = new NeoPixelState();
|
2016-08-30 23:13:44 +02:00
|
|
|
|
|
|
|
// updates
|
|
|
|
this.updateSubscribers = []
|
|
|
|
this.updateView = () => {
|
|
|
|
this.updateSubscribers.forEach(sub => sub());
|
|
|
|
}
|
2016-08-30 20:55:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
receiveMessage(msg: SimulatorMessage) {
|
|
|
|
if (!runtime || runtime.dead) return;
|
|
|
|
|
|
|
|
switch (msg.type || "") {
|
|
|
|
case "eventbus":
|
|
|
|
let ev = <SimulatorEventBusMessage>msg;
|
|
|
|
this.bus.queue(ev.id, ev.eventid, ev.value);
|
|
|
|
break;
|
|
|
|
case "serial":
|
|
|
|
let data = (<SimulatorSerialMessage>msg).data || "";
|
|
|
|
this.serialState.recieveData(data);
|
|
|
|
break;
|
|
|
|
case "radiopacket":
|
|
|
|
let packet = <SimulatorRadioPacketMessage>msg;
|
|
|
|
this.radioState.recievePacket(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kill() {
|
|
|
|
super.kill();
|
|
|
|
AudioContextManager.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
initAsync(msg: SimulatorRunMessage): Promise<void> {
|
|
|
|
let options = (msg.options || {}) as RuntimeOptions;
|
|
|
|
|
2016-09-01 03:03:34 +02:00
|
|
|
let boardDef = CURRENT_BOARD; //TODO: read from pxt.json/pxttarget.json
|
2016-08-30 23:13:44 +02:00
|
|
|
|
2016-08-30 20:55:00 +02:00
|
|
|
let cmpsList = msg.parts;
|
2016-08-31 06:15:27 +02:00
|
|
|
let cmpDefs = PART_DEFINITIONS; //TODO: read from pxt.json/pxttarget.json
|
2016-08-30 20:55:00 +02:00
|
|
|
let fnArgs = msg.fnArgs;
|
|
|
|
|
2016-08-31 20:14:16 +02:00
|
|
|
let viewHost = new visuals.BoardHost({
|
|
|
|
state: this,
|
|
|
|
boardDef: boardDef,
|
|
|
|
cmpsList: cmpsList,
|
|
|
|
cmpDefs: cmpDefs,
|
2016-08-31 20:34:49 +02:00
|
|
|
fnArgs: fnArgs,
|
|
|
|
maxWidth: "100%",
|
|
|
|
maxHeight: "100%",
|
2016-08-31 20:14:16 +02:00
|
|
|
});
|
2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
document.body.innerHTML = ""; // clear children
|
2016-08-30 23:13:44 +02:00
|
|
|
document.body.appendChild(viewHost.getView());
|
2016-08-30 20:55:00 +02:00
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|