forked from trstringer/pipin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model-output.js
123 lines (102 loc) · 3.42 KB
/
model-output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var utility = require('./utility.js');
var chalk = require('chalk');
const config = {
leftMarginSpacing: 8,
physicalIdMargin: 5
};
function displayModelName(modelDetails) {
if (modelDetails.name) {
console.log(`Model: ${modelDetails.name}`);
console.log(' ');
}
}
function displaySchematicHeaderFooter() {
var output = '';
var i;
for (i = 0; i < config.leftMarginSpacing + config.physicalIdMargin + 1; i++) {
output += ' ';
}
console.log(`${output}+-------+`);
}
function displayPinRow(pinLeft, pinRight) {
var displayRow;
const pinChar = 'o';
displayRow = formatPinForOutput(pinLeft, true);
displayRow += ' | ';
switch (pinLeft.type) {
case 'constantPower':
displayRow += chalk.red(pinChar);
break;
case 'ground':
displayRow += chalk.blue(pinChar);
break;
case 'gpio':
displayRow += chalk.yellow(pinChar);
break;
case 'eeprom':
displayRow += chalk.white(pinChar);
break;
}
displayRow += ' | ';
switch (pinRight.type) {
case 'constantPower':
displayRow += chalk.red(pinChar);
break;
case 'ground':
displayRow += chalk.blue(pinChar);
break;
case 'gpio':
displayRow += chalk.yellow(pinChar);
break;
case 'eeprom':
displayRow += chalk.white(pinChar);
break;
}
displayRow += ' | ';
displayRow += formatPinForOutput(pinRight, false);
console.log(displayRow);
}
function formatPinForOutput(pin, isLeft) {
var pinSpecDisplay;
switch (pin.type) {
case 'constantPower':
pinSpecDisplay = isLeft ?
utility.leftPad(`[${pin.physicalId}] `, ' ', config.physicalIdMargin) + utility.leftPad(`${pin.voltage}V`, ' ', config.leftMarginSpacing) :
utility.rightPad(`${pin.voltage}V`, ' ', config.leftMarginSpacing) + ` [${pin.physicalId}]`;
pinSpecDisplay = chalk.red(pinSpecDisplay);
break;
case 'ground':
pinSpecDisplay = isLeft ?
utility.leftPad(`[${pin.physicalId}] `, ' ', config.physicalIdMargin) + utility.leftPad(`GND`, ' ', config.leftMarginSpacing) :
utility.rightPad(`GND`, ' ', config.leftMarginSpacing) + ` [${pin.physicalId}]`;
pinSpecDisplay = chalk.blue(pinSpecDisplay);
break;
case 'gpio':
pinSpecDisplay = isLeft ?
utility.leftPad(`[${pin.physicalId}] `, ' ', config.physicalIdMargin) + utility.leftPad(`GPIO(${pin.gpioId})`, ' ', config.leftMarginSpacing) :
utility.rightPad(`GPIO(${pin.gpioId})`, ' ', config.leftMarginSpacing) + ` [${pin.physicalId}]`;
pinSpecDisplay = chalk.yellow(pinSpecDisplay);
break;
case 'eeprom':
pinSpecDisplay = isLeft ?
utility.leftPad(`[${pin.physicalId}] `, ' ', config.physicalIdMargin) + utility.leftPad(`EEPROM`, ' ', config.leftMarginSpacing) :
utility.rightPad(`EEPROM`, ' ', config.leftMarginSpacing) + ` [${pin.physicalId}]`;
pinSpecDisplay = chalk.white(pinSpecDisplay);
break;
}
return pinSpecDisplay;
}
function displayPins(modelDetails) {
if (modelDetails.pins && modelDetails.pins.length > 0) {
displaySchematicHeaderFooter();
var i;
for (i = 0; i < modelDetails.pins.length; i += 2) {
displayPinRow(modelDetails.pins[i], modelDetails.pins[i + 1]);
}
displaySchematicHeaderFooter();
}
}
module.exports = function (modelDetails) {
displayModelName(modelDetails);
displayPins(modelDetails);
};