draws small wires for small micro:bit pins

This commit is contained in:
darzu 2016-08-31 22:41:30 -07:00
parent 232758805b
commit 7048156b46
2 changed files with 49 additions and 4 deletions

View File

@ -147,7 +147,7 @@ namespace pxsim.visuals {
const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0; const pin3Vmid = pins4onMids[13] + bigPinWidth / 2.0;
const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0; const pinGNDmid = pins4onMids[pins4onMids.length - 1] + bigPinWidth / 2.0;
const pinGND2mid = pinGNDmid + 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 = [ const pinNames = [
"P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10",
"P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20", "P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20",

View File

@ -163,6 +163,41 @@ namespace pxsim.visuals {
g.appendChild(el); g.appendChild(el);
return {el: g, x: x1 - strokeWidth, y: Math.min(y1, y2), w: w1 + strokeWidth * 2, h: h1 + h2}; 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"});
(<any>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"});
(<any>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 { function mkCrocEnd(p: [number, number], top: boolean, clr: string): SVGElAndSize {
//TODO: merge with mkOpenJumperEnd() //TODO: merge with mkOpenJumperEnd()
let k = visuals.PIN_DIST * 0.24; let k = visuals.PIN_DIST * 0.24;
@ -325,7 +360,7 @@ namespace pxsim.visuals {
return {endG: endG, end1: end1, end2: end2, wires: wires}; 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() //TODO: merge with drawWire()
const PIN_Y_OFF = 40; const PIN_Y_OFF = 40;
const CROC_Y_OFF = -17; const CROC_Y_OFF = -17;
@ -349,7 +384,11 @@ namespace pxsim.visuals {
pin2 = [x2, y2 + PIN_Y_OFF];//HACK pin2 = [x2, y2 + PIN_Y_OFF];//HACK
[x2, y2] = pin2; [x2, y2] = pin2;
let endCoord2: Coord = [x2, y2 + CROC_Y_OFF] 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 end2 = end2AndSize.el;
let endG = <SVGGElement>svg.child(g, "g", {class: "sim-bb-wire-ends-g"}); let endG = <SVGGElement>svg.child(g, "g", {class: "sim-bb-wire-ends-g"});
endG.appendChild(end1); endG.appendChild(end1);
@ -415,7 +454,13 @@ namespace pxsim.visuals {
let endLoc = this.getLocCoord(end); let endLoc = this.getLocCoord(end);
let wireEls: Wire; let wireEls: Wire;
if (withCrocs && end.type == "dalboard") { if (withCrocs && end.type == "dalboard") {
wireEls = this.drawWireWithCrocs(startLoc, endLoc, color); let boardPin = (<BoardLoc>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 { } else {
wireEls = this.drawWire(startLoc, endLoc, color); wireEls = this.drawWire(startLoc, endLoc, color);
} }