From e681cc8c9725ca7968998e4e33a881cc6b415a67 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 1 Sep 2016 15:37:39 -0700 Subject: [PATCH] added parts to microbit --- libs/microbit/pxt.json | 1 + libs/microbit/pxtparts.json | 78 ++++++++++++++ sim/dalboard.ts | 6 +- sim/definitions.ts | 177 +------------------------------ sim/instructions/instructions.ts | 5 +- 5 files changed, 89 insertions(+), 178 deletions(-) create mode 100644 libs/microbit/pxtparts.json diff --git a/libs/microbit/pxt.json b/libs/microbit/pxt.json index 248288c6..ccfbc202 100644 --- a/libs/microbit/pxt.json +++ b/libs/microbit/pxt.json @@ -27,6 +27,7 @@ "serial.cpp", "serial.ts", "buffer.cpp", + "pxtparts.json", "_locales/fr/microbit-jsdoc-strings.json" ], "public": true, diff --git a/libs/microbit/pxtparts.json b/libs/microbit/pxtparts.json new file mode 100644 index 00000000..cf0f73f1 --- /dev/null +++ b/libs/microbit/pxtparts.json @@ -0,0 +1,78 @@ +{ + "ledmatrix": { + "visual": "ledmatrix", + "breadboardColumnsNeeded": 8, + "breadboardStartRow": "h", + "pinAllocation": { + "type": "auto", + "gpioPinsNeeded": [5, 5] + }, + "assemblyStep": 0, + "wires": [ + {"start": ["breadboard", "j", 0], "end": ["GPIO", 5], "color": "purple", "assemblyStep": 1}, + {"start": ["breadboard", "j", 1], "end": ["GPIO", 6], "color": "purple", "assemblyStep": 1}, + {"start": ["breadboard", "j", 2], "end": ["GPIO", 7], "color": "purple", "assemblyStep": 1}, + {"start": ["breadboard", "j", 3], "end": ["GPIO", 8], "color": "purple", "assemblyStep": 1}, + {"start": ["breadboard", "a", 7], "end": ["GPIO", 9], "color": "purple", "assemblyStep": 1}, + {"start": ["breadboard", "a", 0], "end": ["GPIO", 0], "color": "green", "assemblyStep": 2}, + {"start": ["breadboard", "a", 1], "end": ["GPIO", 1], "color": "green", "assemblyStep": 2}, + {"start": ["breadboard", "a", 2], "end": ["GPIO", 2], "color": "green", "assemblyStep": 2}, + {"start": ["breadboard", "a", 3], "end": ["GPIO", 3], "color": "green", "assemblyStep": 2}, + {"start": ["breadboard", "j", 4], "end": ["GPIO", 4], "color": "green", "assemblyStep": 2} + ] + }, + "buttonpair": { + "visual": "buttonpair", + "breadboardColumnsNeeded": 6, + "breadboardStartRow": "f", + "pinAllocation": { + "type": "predefined", + "pins": ["P13", "P12"] + }, + "assemblyStep": 0, + "wires": [ + {"start": ["breadboard", "j", 0], "end": ["GPIO", 0], "color": "yellow", "assemblyStep": 1}, + {"start": ["breadboard", "a", 2], "end": "ground", "color": "blue", "assemblyStep": 1}, + {"start": ["breadboard", "j", 3], "end": ["GPIO", 1], "color": "orange", "assemblyStep": 2}, + {"start": ["breadboard", "a", 5], "end": "ground", "color": "blue", "assemblyStep": 2} + ] + }, + "neopixel": { + "visual": "neopixel", + "breadboardColumnsNeeded": 5, + "breadboardStartRow": "h", + "pinAllocation": { + "type": "factoryfunction", + "functionName": "neopixel.create", + "pinArgPositions": [0], + "otherArgPositions": [1] + }, + "assemblyStep": 0, + "wires": [ + {"start": ["breadboard", "j", 1], "end": "ground", "color": "blue", "assemblyStep": 1}, + {"start": ["breadboard", "j", 2], "end": "threeVolt", "color": "red", "assemblyStep": 2}, + {"start": ["breadboard", "j", 3], "end": ["GPIO", 0], "color": "green", "assemblyStep": 2} + ] + }, + "speaker": { + "visual": { + "image": "/parts/speaker.svg", + "width": 500, + "height": 500, + "firstPin": [180, 135], + "pinDist": 70, + "extraColumnOffset": 1 + }, + "breadboardColumnsNeeded": 5, + "breadboardStartRow": "f", + "pinAllocation": { + "type": "auto", + "gpioPinsNeeded": 1 + }, + "assemblyStep": 0, + "wires": [ + {"start": ["breadboard", "j", 1], "end": ["GPIO", 0], "color": "#ff80fa", "assemblyStep": 1}, + {"start": ["breadboard", "j", 3], "end": "ground", "color": "blue", "assemblyStep": 1} + ] + } +} \ No newline at end of file diff --git a/sim/dalboard.ts b/sim/dalboard.ts index 78fdf4dd..b95f354b 100644 --- a/sim/dalboard.ts +++ b/sim/dalboard.ts @@ -1,3 +1,5 @@ +/// + namespace pxsim { export class DalBoard extends BaseBoard { id: string; @@ -69,12 +71,14 @@ namespace pxsim { } initAsync(msg: SimulatorRunMessage): Promise { + super.initAsync(msg); + let options = (msg.options || {}) as RuntimeOptions; let boardDef = CURRENT_BOARD; //TODO: read from pxt.json/pxttarget.json let cmpsList = msg.parts; - let cmpDefs = PART_DEFINITIONS; //TODO: read from pxt.json/pxttarget.json + let cmpDefs = msg.partDefinitions || {}; //TODO: read from pxt.json/pxttarget.json let fnArgs = msg.fnArgs; let viewHost = new visuals.BoardHost({ diff --git a/sim/definitions.ts b/sim/definitions.ts index a8374580..a4ede8ba 100644 --- a/sim/definitions.ts +++ b/sim/definitions.ts @@ -1,73 +1,10 @@ /// +/// /// /// /// namespace pxsim { - export interface PinBlockDefinition { - x: number, - y: number, - labelPosition: "above" | "below"; - labels: string[] - } - export interface BoardImageDefinition { - image: string, - outlineImage?: string, - width: number, - height: number, - pinDist: number, - pinBlocks: PinBlockDefinition[], - }; - export interface BoardDefinition { - visual: BoardImageDefinition | string, - gpioPinBlocks?: string[][], - gpioPinMap: {[pin: string]: string}, - groundPins: string[], - threeVoltPins: string[], - attachPowerOnRight?: boolean, - onboardComponents?: string[] - useCrocClips?: boolean, - marginWhenBreadboarding?: [number, number, number, number], - } - export interface FactoryFunctionPinAlloc { - type: "factoryfunction", - functionName: string, - pinArgPositions: number[], - otherArgPositions?: number[], - } - export interface PredefinedPinAlloc { - type: "predefined", - pins: string[], - } - export interface AutoPinAlloc { - type: "auto", - gpioPinsNeeded: number | number[], - } - export interface PartVisualDefinition { - image: string, - width: number, - height: number, - pinDist: number, - extraColumnOffset?: number, - firstPin: [number, number], - } - export interface PartDefinition { - visual: string | PartVisualDefinition, - breadboardColumnsNeeded: number, - breadboardStartRow: string, - wires: WireDefinition[], - assemblyStep: number, - pinAllocation: FactoryFunctionPinAlloc | PredefinedPinAlloc | AutoPinAlloc, - } - export interface WireDefinition { - start: WireLocationDefinition, - end: WireLocationDefinition, - color: string, - assemblyStep: number - }; - export type WireLocationDefinition = - ["breadboard", string, number] | ["GPIO", number] | "ground" | "threeVolt"; - export const MICROBIT_DEF: BoardDefinition = { visual: "microbit", gpioPinBlocks: [ @@ -107,118 +44,6 @@ namespace pxsim { marginWhenBreadboarding: [0, 0, 80, 0], } - export const PART_DEFINITIONS: Map = { - "ledmatrix": { - visual: "ledmatrix", - breadboardColumnsNeeded: 8, - breadboardStartRow: "h", - pinAllocation: { - type: "auto", - gpioPinsNeeded: [5, 5], - }, - assemblyStep: 0, - wires: [ - {start: ["breadboard", `j`, 0], end: ["GPIO", 5], color: "purple", assemblyStep: 1}, - {start: ["breadboard", `j`, 1], end: ["GPIO", 6], color: "purple", assemblyStep: 1}, - {start: ["breadboard", `j`, 2], end: ["GPIO", 7], color: "purple", assemblyStep: 1}, - {start: ["breadboard", `j`, 3], end: ["GPIO", 8], color: "purple", assemblyStep: 1}, - {start: ["breadboard", `a`, 7], end: ["GPIO", 9], color: "purple", assemblyStep: 1}, - {start: ["breadboard", `a`, 0], end: ["GPIO", 0], color: "green", assemblyStep: 2}, - {start: ["breadboard", `a`, 1], end: ["GPIO", 1], color: "green", assemblyStep: 2}, - {start: ["breadboard", `a`, 2], end: ["GPIO", 2], color: "green", assemblyStep: 2}, - {start: ["breadboard", `a`, 3], end: ["GPIO", 3], color: "green", assemblyStep: 2}, - {start: ["breadboard", `j`, 4], end: ["GPIO", 4], color: "green", assemblyStep: 2}, - ] - }, - "buttonpair": { - visual: "buttonpair", - breadboardColumnsNeeded: 6, - breadboardStartRow: "f", - pinAllocation: { - type: "predefined", - pins: ["P13", "P12"], - }, - assemblyStep: 0, - wires: [ - {start: ["breadboard", "j", 0], end: ["GPIO", 0], color: "yellow", assemblyStep: 1}, - {start: ["breadboard", "a", 2], end: "ground", color: "blue", assemblyStep: 1}, - {start: ["breadboard", "j", 3], end: ["GPIO", 1], color: "orange", assemblyStep: 2}, - {start: ["breadboard", "a", 5], end: "ground", color: "blue", assemblyStep: 2}, - ], - }, - "neopixel": { - visual: "neopixel", - breadboardColumnsNeeded: 5, - breadboardStartRow: "h", - pinAllocation: { - type: "factoryfunction", - functionName: "neopixel.create", - pinArgPositions: [0], - otherArgPositions: [1], - }, - assemblyStep: 0, - wires: [ - {start: ["breadboard", "j", 1], end: "ground", color: "blue", assemblyStep: 1}, - {start: ["breadboard", "j", 2], end: "threeVolt", color: "red", assemblyStep: 2}, - {start: ["breadboard", "j", 3], end: ["GPIO", 0], color: "green", assemblyStep: 2}, - ], - }, - "speaker": { - visual: { - image: svg.toDataUri(` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -`), - width: 500, - height: 500, - firstPin: [180, 135], - pinDist: 70, - extraColumnOffset: 1, - }, - breadboardColumnsNeeded: 5, - breadboardStartRow: "f", - pinAllocation: { - type: "auto", - gpioPinsNeeded: 1, - }, - assemblyStep: 0, - wires: [ - {start: ["breadboard", "j", 1], end: ["GPIO", 0], color: "#ff80fa", assemblyStep: 1}, - {start: ["breadboard", "j", 3], end: "ground", color: "blue", assemblyStep: 1}, - ], - }, - } - export const builtinComponentSimVisual: Map<() => visuals.IBoardComponent> = { "buttonpair": () => new visuals.ButtonPairView(), "ledmatrix": () => new visuals.LedMatrixView(), diff --git a/sim/instructions/instructions.ts b/sim/instructions/instructions.ts index 25cb44ec..04bfe01e 100644 --- a/sim/instructions/instructions.ts +++ b/sim/instructions/instructions.ts @@ -620,6 +620,9 @@ ${tsPackage} let parts = (getQsVal("parts") || "").split(" "); parts.sort(); + // parts definitions + let partDefinitions = JSON.parse(getQsVal("partdefs") || "{}") as pxsim.Map + //fn args let fnArgs = JSON.parse((getQsVal("fnArgs") || "{}")); @@ -637,7 +640,7 @@ ${tsPackage} style.textContent += STYLE; const boardDef = CURRENT_BOARD; - const cmpDefs = PART_DEFINITIONS; + const cmpDefs = partDefinitions; //props let dummyBreadboard = new visuals.Breadboard({});