Skip to content

Commit

Permalink
[v1.0.3]
Browse files Browse the repository at this point in the history
Bump sketch versions
Unify sketch headers
Implement sprintf_P PROGMEM based building of HTTP strings and payload
Should send less TCP packets
Use same structure in all templates except `custom`
  • Loading branch information
ubergesundheit committed Jul 29, 2017
1 parent 6747d9c commit cb93780
Show file tree
Hide file tree
Showing 11 changed files with 725 additions and 869 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# node-sketch-templater Changelog

## v1.0.3
- Bump sketch versions
- Unify sketch headers
- Implement sprintf_P PROGMEM based building of HTTP strings and payload
- Should send less TCP packets
- Use same structure in all templates except `custom`

## v1.0.2
Add `encoding` field to `generateSketch` which allows to specify base64 encoding

## v1.0.1
Fix npm package name in README.md

## v1.0.0
Initial release to npm after extracting from sensebox/openSenseMap-API
Initial release to npm after extracting from sensebox/openSenseMap-API
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ Additionally, the following transformers are implemented:
| Transformer name | Description |
|------------------|-------------|
| `as-is` | Do nothing. |
| `toHex` | Transforms a single string to hex tuples. Example: `"DEADBEEF" => "0xDE, 0xAD, 0xBE, 0xEF"` |
| `toDefine` | Transform an array of sensors to multiple `#define` statements. |
| `toHexArray` | Transform an array of sensors to a list of hex encoded arrays. Uses `toHex` internally. |
| `toProgmem` | Transform an array of sensors to multiple `const char xxSENSOR_ID[] PROGMEM = "<id>";` statements. |

## Adding Transformers

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sensebox/sketch-templater",
"version": "1.0.2",
"version": "1.0.3",
"description": "nodejs library to create senseBox Arduino Sketches",
"main": "src/index.js",
"repository": "https://github.com/sensebox/node-sketch-templater.git",
Expand Down Expand Up @@ -28,4 +28,4 @@
"publishConfig": {
"access": "public"
}
}
}
45 changes: 8 additions & 37 deletions src/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,10 @@

const dedent = require('dedent');

/* Used in toHexArray
* sensors should follow this order strictlyI
* when using the standard senseBox:home wifi setup
* 0 Temperature
* 1 Humidity
* 2 Pressure
* 3 Lux
* 4 UV
* 5 PM10
* 6 PM2.5
* the rest
*/
const homeSensorTitles = [
'Temperatur',
'rel. Luftfeuchte',
'Luftdruck',
'Beleuchtungsstärke',
'UV-Intensität',
'PM10',
'PM2.5'
];

module.exports = {
'as-is'(str) {
return str;
},
toHex(idStr) {
return idStr.toString().replace(/(..)/g, ', 0x$1').substr(2);
},
toDefine(sensors) {
const output = [];
for (const [i, { _id, title }] of sensors.entries()) {
Expand All @@ -40,20 +15,16 @@ module.exports = {

return output.join('\r\n');
},
toHexArray(sensors) {
const homeSensors = [];
const otherSensors = [];
toProgmem(sensors) {
const output = [];
for (const { _id, title } of sensors) {
const index = homeSensorTitles.findIndex(t => t === title);
if (index !== -1) {
homeSensors[index] = dedent`// ${title}
{ ${this.toHex(_id)} }`;
continue;
}
otherSensors.push(dedent`// ${title}
{ ${this.toHex(_id)} }`);
output.push(dedent`// ${title}
const char ${title
.toUpperCase()
.replace(/[^A-Z0-9]+/g, '')
.slice(0, 6)}SENSOR_ID[] PROGMEM = "${_id}";`);
}

return homeSensors.filter(s => s).concat(otherSensors).join(',\r\n');
return output.join('\r\n');
}
};
Loading

0 comments on commit cb93780

Please sign in to comment.