-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransformers.js
104 lines (92 loc) · 2.68 KB
/
transformers.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
'use strict';
const dedent = require('dedent');
module.exports = {
'as-is'(str) {
return str;
},
toDefine(sensors) {
const output = [];
for (const [i, { _id, title, sensorType }] of sensors.entries()) {
output.push(dedent`// ${title} - ${sensorType}
#define SENSOR${i + 1}_ID "${_id}"`);
}
return output.join('\r\n');
},
toDefineWithSuffixPrefixAndKey(sensors, prefix, suffix, key) {
const output = [];
for (const [, sensor] of sensors.entries()) {
const value = sensor[key].replace(/\s+/g, '');
output.push(dedent`// ${sensor.title} - ${sensor.sensorType}
#define ${prefix}${value.toUpperCase()}${suffix}`);
}
return output.join('\r\n');
},
toProgmem(sensors) {
const output = [];
for (const { _id, title, sensorType } of sensors) {
output.push(dedent`// ${title} - ${sensorType}
const char ${sensorType
.toUpperCase()
.replace(/[^A-Z0-9]+/g, '')}_${title
.toUpperCase()
.replace(/[^A-Z0-9]+/g, '')
.slice(0, 6)}SENSOR_ID[] PROGMEM = "${_id}";`);
}
return output.join('\r\n');
},
toProgmemWithoutPrefix(sensors) {
const output = [];
for (const { _id, title } of sensors) {
output.push(dedent`// ${title}
const char ${title
.toUpperCase()
.replace(/[^A-Z0-9]+/g, '')
.slice(0, 6)}SENSOR_ID[] PROGMEM = "${_id}";`);
}
return output.join('\r\n');
},
digitalPortToPortNumber(port, offset = 0) {
let portNumber = 0;
switch (port) {
case 'A':
portNumber = 1;
break;
case 'B':
portNumber = 3;
break;
case 'C':
portNumber = 5;
break;
}
return Number(portNumber) + Number(offset);
},
transformTTNID(eui, lsb = false) {
if (eui === undefined || (eui.length !== 16 && eui.length !== 32)) {
return '{ }';
}
// split eui into chunks of two
let chunks = eui.match(/.{1,2}/g);
if (lsb) {
chunks = chunks.reverse();
}
return `{${chunks.map((c) => ` 0x${c}`)} }`;
},
toDefineDisplay(display) {
const output = [];
if (display === 'true') {
output.push(`#define DISPLAY128x64_CONNECTED`);
} else {
output.push(`//#define DISPLAY128x64_CONNECTED`);
}
return output.join('\r\n');
},
toDefineEnableDebug(debug){
const output = [];
if (debug === 'true') {
output.push(`#define ENABLE_DEBUG`);
} else {
output.push(`//#define ENABLE_DEBUG`);
}
return output.join('\r\n');
}
};