From e2fe660012e9b23fb344419cc061e690df7c98b2 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Fri, 14 Oct 2016 06:46:56 -0700 Subject: [PATCH] towards pin placement --- libs/core/pxtparts.json | 4 ++-- pxtarget.json | 8 +++++++- sim/visuals/microbit.ts | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libs/core/pxtparts.json b/libs/core/pxtparts.json index c1bbde2f..403d379f 100644 --- a/libs/core/pxtparts.json +++ b/libs/core/pxtparts.json @@ -157,8 +157,8 @@ {"x": 395, "y": 48} ] }, "pinDefinitions": [ - { "target": "P1", "style": "croc", "orientation": "-Z"}, - { "target": "ground", "style": "croc", "orientation": "-Z"} + { "target": "M_OUT1", "style": "croc", "orientation": "-Z"}, + { "target": "M_OUT2", "style": "croc", "orientation": "-Z"} ], "instantiation": {"kind": "singleton"}, "assembly": [ diff --git a/pxtarget.json b/pxtarget.json index 59d6e031..3e668d77 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -146,7 +146,13 @@ "P15": "P15", "P16": "P16", "P19": "P19", - "P20": "P20" + "P20": "P20", + "EXT_PWR":"EXT_PWR", + "SPKR":"EXT_PWR", + "BTN_A": "BTN_A", + "BTN_B": "BTN_B", + "M_OUT1": "M_OUT1", + "M_OUT2": "M_OUT2" }, "spiPins": { "MOSI": "P15", diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index dac1091e..ecd8d8ef 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -1060,11 +1060,10 @@ namespace pxsim.visuals { private thermometerText: SVGTextElement; private shakeButton: SVGElement; public board: pxsim.DalBoard; - private pinNmToCoord: Map = {}; + private pinNmToCoord: Map; private rgbLed: SVGElement; constructor(public props: IBoardProps) { - this.recordPinCoords(); this.buildDom(); if (props && props.wireframe) svg.addClass(this.element, "sim-wireframe"); @@ -1091,6 +1090,7 @@ namespace pxsim.visuals { } public getCoord(pinNm: string): Coord { + if (!this.pinNmToCoord) this.recordPinCoords(); return this.pinNmToCoord[pinNm]; } @@ -1103,9 +1103,12 @@ namespace pxsim.visuals { } public recordPinCoords() { + this.pinNmToCoord = {}; pinNames.forEach((nm,i) => { // TODO: position pins from SVG - this.pinNmToCoord[nm] = [0,0]; + const p = this.pins[i]; + const r = p.getBoundingClientRect(); + this.pinNmToCoord[nm] = [r.left + r.width / 2, r.top + r.height / 2]; }); }