Merge pull request #1 from wdmtech/add-app-smartswitch

Add app smartswitch
pull/370/head
Will Murray 2020-04-30 21:33:53 +01:00 committed by GitHub
commit 2daf775474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 0 deletions

View File

@ -1158,5 +1158,22 @@
{"name":"batchart.app.js","url":"app.js"}, {"name":"batchart.app.js","url":"app.js"},
{"name":"batchart.img","url":"app-icon.js","evaluate":true} {"name":"batchart.img","url":"app-icon.js","evaluate":true}
] ]
},
{ "id": "smartswitch",
"name": "BTLE Smartswitch",
"shortName":"Smartswitch",
"icon": "app.png",
"version":"0.01",
"description": "Using EspruinoHub, control your smart devices on and off via Bluetooth Low Energy!",
"tags": "bluetooth,btle,smart,switch",
"readme": "README.md",
"storage": [
{"name":"smartswitch.app.js","url":"app.js"},
{"name":"smartswitch-on.img","url":"app-icon.js","evaluate":true},
{"name":"smartswitch-on.img","url":"smartswitch-icon.js","evaluate":true},
{"name":"smartswitch-off.img","url":"switch-off.js","evaluate":true},
{"name":"light-on.img","url":"light-on.js","evaluate":true},
{"name":"light-off.img","url":"light-off.js","evaluate":true}
]
} }
] ]

View File

@ -0,0 +1 @@
0.01: New App! See the README.MD for details on how to use it.

View File

@ -0,0 +1,12 @@
# Smartswitch app for BangleJS
# EspruinoHub
Install EspruinoHub following the directions at [https://github.com/espruino/EspruinoHub](https://github.com/espruino/EspruinoHub)
# Example Node-RED flow
```
[{"id":"6d5e0685.62fed8","type":"switch","z":"37813ca5.3e4a04","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0,0","vt":"str"},{"t":"eq","v":"0,1","vt":"str"},{"t":"eq","v":"1,0","vt":"str"},{"t":"eq","v":"1,1","vt":"str"},{"t":"eq","v":"2,0","vt":"str"},{"t":"eq","v":"2,1","vt":"str"},{"t":"eq","v":"3,0","vt":"str"},{"t":"eq","v":"3,1","vt":"str"},{"t":"eq","v":"4,0","vt":"str"},{"t":"eq","v":"4,1","vt":"str"}],"checkall":"true","repair":false,"outputs":10,"x":130,"y":520,"wires":[["2dd25bad.402644"],["e39ef382.eea6c"],["bb5aca6b.24e888"],["ed2bb6.25745448"],["869f116a.18c0a"],["d7661912.3d1f78"],[],[],[],[]]},{"id":"e39ef382.eea6c","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":500,"wires":[["fc85fc8f.9622f8"]]},{"id":"2dd25bad.402644","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":460,"wires":[["fc85fc8f.9622f8"]]},{"id":"ed2bb6.25745448","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":600,"wires":[["dbcd73c6.cc0bf"]]},{"id":"bb5aca6b.24e888","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":560,"wires":[["dbcd73c6.cc0bf"]]},{"id":"d7661912.3d1f78","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":700,"wires":[["c8cb0b9b.1b7528"]]},{"id":"869f116a.18c0a","type":"change","z":"37813ca5.3e4a04","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":660,"wires":[["c8cb0b9b.1b7528"]]}]
```

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AGeJAAwttGMotLGMQiD1uzAAWtGEgtE64ACF5IwbFwYtESUouGFpowaFywvXDIS7CFyIwXLwouSF6peF1ovrRqowWF4heEstlApIveDolfAAIEGF76OGFYQuMF6+zdo4uOF6+tF49lFwK9KF7AAJLxovUGBiOhF+IwLF5guWF+AwKF5YuYGBQvKFzQwJF5IucGBAvIFzwwHF44ugF+AwFF4wui/2CABQvrr1YAAIvjrwoDAAwvjFhFeR8onDX/4vcXxIvkYA73BR0gACYA4umMI4uoGAouqAH4AK"))

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4AT5gAGFtoxlFpYxhFp4xeFyYwaFyowZF9wuXGC4vuFzIwVF9wdK53OApIwYDRHN6gAC5oFFF8QoC5wyIMRAvZ5wkERgJbCBQqPfEoKGGL4S/j5i3GFwS/jK5BnIF6owMW4S8KFygvKSIQDFF85bBF8QwKF54uUF+AwJF5wuWF+AwIF5ouYGBAvMFzQwHF5YucGAwvKFzwwFF5IugAAOCAA1erAABF0X+rwoDAAwvjFhFeMYIvkE4QAHF8a/vwS+JF8jAHe4KOkGAaQFroumAAUrAAQtpGAgusAH4A/AFI="))

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AH4A/AH4A/AH4Ag1gAECyGFAB1bAAmAFooyQFp4uGEoWIwQAEGBgtQFwtcFpAACxAwJFyIvFEAItIMAowFF1IwFF6zqBRhIvIxBetMAYvWdgJeSAAOHFyQvEw5eRBAeIF6+IF5wIHF66+LTJIvlNBaPfRRAved4g0BAASNJd4f+F61cFQYAEFxQ/Bw4vXYAQAFLxms/wABGC2ALyaOBF7BgGLyAweFyIwTF4jyDLxKMBFw4xTGAhhEFpAuKGKQwFeg4ADFxgAZFlgA/AH4A/AH4A/AH4A/AH4AhA"))

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4A/AH4A/AH4A/AH4AI1gAEFlgAEz2WAAm6ABwuPxGCAAgJC0wwVGJQtIAAWIGIWXF6gxIEAItIMAgABMCowGFyKSGGCulRhQvHegovVLySRGF6QwBLyjyaF4IuQBAaQX3WmF5wIG0ovXXxaZJYDLuMF8SPHRRCPed4mIcwaNJd7YvBAA4uKH4OXF63+/wuHLxi+YF4JgHLxiOXFwJgHLxmmFwYvXGAqNQFzAwELxKMBdjQwJMAwtCRgovRFpDDIAAjqEFyItLGRQWQAH4A/AH4A/AH4A/AH4A/AH4AP"))

View File

@ -0,0 +1,79 @@
// Learn more!
// https://www.espruino.com/Reference#l_NRF_setAdvertising
// https://www.espruino.com/Bangle.js#buttons
// Initial graphics setup
g.clear();
g.setFontAlign(0, 0); // center font
// g.setFont("6x8", 8); // bitmap font, 8x magnified
g.setFont("Vector", 40); // vector font, 80px
// Let the app begin!
const storage = require("Storage");
let currentPage = 0;
let pages = [
{
name: "Downstairs",
icon: "light",
state: false
},
{
name: "Upstairs",
icon: "smartswitch",
state: false
}];
function loadPage(page) {
const icon = page.state ? page.icon + "-on" : page.icon + "-off";
Bangle.beep();
g.clear();
g.setFont("Vector", 10);
g.drawString("prev", g.getWidth() - 25, 20);
g.drawString("next", g.getWidth() - 25, 220);
g.setFont("Vector", 15);
g.drawString(page.name, g.getWidth() / 2, 200);
g.setFont("Vector", 40);
g.drawString(page.state ? "On" : "Off", g.getWidth() / 2, g.getHeight() / 2);
g.drawImage(storage.read(`${icon}.png`), g.getWidth() / 2 - 24, g.getHeight() / 2 - 24 - 50);
}
function prevPage() {
if (currentPage > 0) {
currentPage--;
loadPage(pages[currentPage]);
}
}
function nextPage() {
if (currentPage < pages.length - 1) {
currentPage++;
loadPage(pages[currentPage]);
}
}
function swipe(dir) {
const page = pages[currentPage];
page.state = dir == 1;
NRF.setAdvertising({
0xFFFF: [currentPage, page.state]
});
loadPage(page);
// optional - this keeps the watch LCD lit up
g.flip();
Bangle.buzz();
}
Bangle.on('swipe', swipe);
setWatch(prevPage, BTN, {edge: "rising", debounce: 50, repeat: true});
setWatch(nextPage, BTN3, {edge: "rising", debounce: 50, repeat: true});
loadPage(pages[currentPage]);