UNPKG

1.6 kBJavaScriptView Raw
1/**
2 * Many pins have common aliases, especially SPI!
3 */
4
5var MISO = "miso";
6var MOSI = "mosi";
7var SCLK = "sclk";
8var SS = "ss";
9
10// jshint unused:false
11var aliases = {
12
13 // SCLK
14 clk: SCLK,
15 clock: SCLK,
16 sclk: SCLK,
17
18 // MISO
19 somi: MISO,
20 sdo: MISO,
21 do: MISO,
22 dout: MISO,
23 so: MISO,
24 mrsr: MISO,
25 miso: MISO,
26
27 // MOSI
28 simo: MOSI,
29 sdi: MOSI,
30 data: MOSI,
31 di: MOSI,
32 din: MOSI,
33 si: MOSI,
34 mtst: MOSI,
35 mosi: MOSI,
36
37 // SS
38 ncs: SS,
39 cs: SS,
40 csb: SS,
41 csn: SS,
42 en: SS,
43 ld: SS,
44 load: SS,
45 nss: SS,
46 ste: SS,
47 sync: SS,
48 ss: SS,
49};
50
51
52/**
53 * Options
54 *
55 * @param {String} arg Pin address.
56 * @param {Number} arg Pin address.
57 * @param {Array} arg List of Pin addresses.
58 *
59 * @return {Options} normalized board options instance.
60 */
61
62function Options(arg) {
63 if (!(this instanceof Options)) {
64 return new Options(arg);
65 }
66
67 var opts = {};
68
69 if (typeof arg === "number" ||
70 typeof arg === "string") {
71 opts.pin = arg;
72 } else if (Array.isArray(arg)) {
73 opts.pins = arg;
74 } else {
75 opts = arg;
76
77
78 // @Nick, this is where you want to focus.
79 // Anytime this path is taken, the constructor
80 // received an object. If the object contains
81 // a "pins" property that is ALSO an object, we need
82 // to normalize the keys of that object, using the
83 // "aliases" map defined above.
84 //
85 // This change will require renaming pin properties in
86 // a few classes, but I'm ok with that, because if we do this
87 // right, no existing code will break.
88 //
89 }
90
91 Object.assign(this, opts);
92}
93
94module.exports = Options;