From 7048156b4630c36a53a59c195d750a5f30deeee3 Mon Sep 17 00:00:00 2001 From: darzu Date: Wed, 31 Aug 2016 22:41:30 -0700 Subject: [PATCH] draws small wires for small micro:bit pins --- sim/microbit.ts | 2 +- sim/visuals/wiring.ts | 51 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/sim/microbit.ts b/sim/microbit.ts index 1d5d2842..792907a5 100644 --- a/sim/microbit.ts +++ b/sim/microbit.ts @@ -147,7 +147,7 @@ namespace pxsim.visuals { const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0; const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0; const pinGND2mid = pinGNDmid + bigPinWidth / 2.0; - const pinMids = [pin0mid, pin1mid, pin2mid, pin3mid].concat(pins4onXs).concat([pinGNDmid, pin3Vmid, pinGND2mid]); + const pinMids = [pin0mid, pin1mid, pin2mid, pin3mid].concat(pins4onMids).concat([pinGNDmid, pin3Vmid, pinGND2mid]); const pinNames = [ "P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20", diff --git a/sim/visuals/wiring.ts b/sim/visuals/wiring.ts index 1f1248e0..d5a0b693 100644 --- a/sim/visuals/wiring.ts +++ b/sim/visuals/wiring.ts @@ -163,6 +163,41 @@ namespace pxsim.visuals { g.appendChild(el); return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; } + function mkSmallMBPinEnd(p: [number, number], top: boolean, clr: string): visuals.SVGElAndSize { + //HACK + //TODO: merge with mkOpenJumperEnd() + let k = visuals.PIN_DIST * 0.24; + let plasticLength = k * 4; + let plasticWidth = k * 1.2; + let metalLength = k * 10; + let metalWidth = k; + const strokeWidth = visuals.PIN_DIST / 4.0; + let [cx, cy] = p; + let yOffset = 10; + let o = top ? -1 : 1; + let g = svg.elt("g") + + let el = svg.elt("rect"); + let h1 = plasticLength; + let w1 = plasticWidth; + let x1 = cx - w1 / 2; + let y1 = cy + yOffset - (h1 / 2); + svg.hydrate(el, {x: x1, y: y1, width: w1, height: h1, rx: 0.5, ry: 0.5, class: "sim-bb-wire-end"}); + (el).style["stroke-width"] = `${strokeWidth}px`; + + let el2 = svg.elt("rect"); + let h2 = metalLength; + let w2 = metalWidth; + let cy2 = cy + yOffset + o * (h1 / 2 + h2 / 2); + let x2 = cx - w2 / 2; + let y2 = cy2 - (h2 / 2); + svg.hydrate(el2, {x: x2, y: y2, width: w2, height: h2, class: "sim-bb-wire-bare-end"}); + (el2).style["fill"] = `#bbb`; + + g.appendChild(el2); + g.appendChild(el); + return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; + } function mkCrocEnd(p: [number, number], top: boolean, clr: string): SVGElAndSize { //TODO: merge with mkOpenJumperEnd() let k = visuals.PIN_DIST * 0.24; @@ -325,7 +360,7 @@ namespace pxsim.visuals { return {endG: endG, end1: end1, end2: end2, wires: wires}; } - private drawWireWithCrocs(pin1: Coord, pin2: Coord, color: string): Wire { + private drawWireWithCrocs(pin1: Coord, pin2: Coord, color: string, smallPin: boolean = false): Wire { //TODO: merge with drawWire() const PIN_Y_OFF = 40; const CROC_Y_OFF = -17; @@ -349,7 +384,11 @@ namespace pxsim.visuals { pin2 = [x2, y2 + PIN_Y_OFF];//HACK [x2, y2] = pin2; let endCoord2: Coord = [x2, y2 + CROC_Y_OFF] - let end2AndSize = mkCrocEnd(endCoord2, true, color); + let end2AndSize: SVGElAndSize; + if (smallPin) + end2AndSize = mkSmallMBPinEnd(endCoord2, true, color); + else + end2AndSize = mkCrocEnd(endCoord2, true, color); let end2 = end2AndSize.el; let endG = svg.child(g, "g", {class: "sim-bb-wire-ends-g"}); endG.appendChild(end1); @@ -415,7 +454,13 @@ namespace pxsim.visuals { let endLoc = this.getLocCoord(end); let wireEls: Wire; if (withCrocs && end.type == "dalboard") { - wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); + let boardPin = (end).pin; + if (boardPin == "P0" || boardPin == "P1" || boardPin == "P0" || boardPin == "GND" || boardPin == "+3v3" ) { + //HACK + wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); + } else { + wireEls = this.drawWireWithCrocs(startLoc, endLoc, color, true); + } } else { wireEls = this.drawWire(startLoc, endLoc, color); }