From 4cf0f0cc4da5ca7023544eb9917d9d38e512d4f7 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 30 Sep 2018 14:30:21 +0200 Subject: [PATCH] fix completion, add moar events --- .vscode/settings.json | 2 +- data/www/index.html | 25 ++++++++++------ data/www/script.js | 54 ++++++++++++++++++++++++++++++++--- lib/NeoPattern/NeoPattern.cpp | 10 ++++--- src/PixelPlugin.h | 6 ++++ test/.gitignore | 1 + test/package-lock.json | 24 ++++++++++++++++ test/palette.js | 28 ++++++++++++++++++ 8 files changed, 132 insertions(+), 18 deletions(-) create mode 100644 test/.gitignore create mode 100644 test/package-lock.json create mode 100644 test/palette.js diff --git a/.vscode/settings.json b/.vscode/settings.json index c61cd55..8d30d4d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "terminal.integrated.env.linux": { - "PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/home/master/.nvm/versions/node/v9.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/master/go/bin", + "PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl", "PLATFORMIO_CALLER": "vscode" }, "files.associations": { diff --git a/data/www/index.html b/data/www/index.html index b119527..c5981b4 100644 --- a/data/www/index.html +++ b/data/www/index.html @@ -2,7 +2,7 @@ - Illu-Cat + ESP Kit @@ -16,6 +16,13 @@ Pixels
diff --git a/data/www/script.js b/data/www/script.js index 2da6246..3b82ae7 100644 --- a/data/www/script.js +++ b/data/www/script.js @@ -10784,13 +10784,33 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +const hues = [ ["#FDEB71", "#F8D800"], ["#ABDCFF", "#0396FF"], ["#FEB692", "#EA5455"], ["#CE9FFC", "#7367F0"], ["#90F7EC", "#32CCBC"], ["#FFF6B7", "#F6416C"], ["#81FBB8", "#28C76F"], ["#E2B0FF", "#9F44D3"], ["#F97794", "#623AA2"], ["#FCCF31", "#F55555"], ["#F761A1", "#8C1BAB"], ["#43CBFF", "#9708CC"], ["#5EFCE8", "#736EFE"], ["#FAD7A1", "#E96D71"], ["#FFD26F", "#3677FF"], ["#A0FE65", "#FA016D"], ["#FFDB01", "#0E197D"], ["#FEC163", "#DE4313"], ["#92FFC0", "#002661"], ["#EEAD92", "#6018DC"], ["#F6CEEC", "#D939CD"], ["#52E5E7", "#130CB7"], ["#F1CA74", "#A64DB6"], ["#E8D07A", "#5312D6"], ["#EECE13", "#B210FF"], ["#79F1A4", "#0E5CAD"], ["#FDD819", "#E80505"], ["#FFF3B0", "#CA26FF"], ["#FFF5C3", "#9452A5"], ["#F05F57", "#360940"], ["#2AFADF", "#4C83FF"], ["#FFF886", "#F072B6"], ["#97ABFF", "#123597"], ["#F5CBFF", "#C346C2"], ["#FFF720", "#3CD500"], ["#FF6FD8", "#3813C2"], ["#EE9AE5", "#5961F9"], ["#FFD3A5", "#FD6585"], ["#C2FFD8", "#465EFB"], ["#FD6585", "#0D25B9"], ["#FD6E6A", "#FFC600"], ["#65FDF0", "#1D6FA3"], ["#6B73FF", "#000DFF"], ["#FF7AF5", "#513162"], ["#F0FF00", "#58CFFB"], ["#FFE985", "#FA742B"], ["#FFA6B7", "#1E2AD2"], ["#FFAA85", "#B3315F"], ["#72EDF2", "#5151E5"], ["#FF9D6C", "#BB4E75"], ["#F6D242", "#FF52E5"], ["#69FF97", "#00E4FF"], ["#3B2667", "#BC78EC"], ["#70F570", "#49C628"], ["#3C8CE7", "#00EAFF"], ["#FAB2FF", "#1904E5"], ["#81FFEF", "#F067B4"], ["#FFA8A8", "#FCFF00"], ["#FFCF71", "#2376DD"], ["#FF96F9", "#C32BAC"] ]; let endpoint = '/pixel'; __WEBPACK_IMPORTED_MODULE_0_jquery___default()(() => { - new __WEBPACK_IMPORTED_MODULE_1__core_App__["a" /* default */](__WEBPACK_IMPORTED_MODULE_0_jquery___default()('body')) + let app = new __WEBPACK_IMPORTED_MODULE_1__core_App__["a" /* default */](__WEBPACK_IMPORTED_MODULE_0_jquery___default()('body')) .components(__WEBPACK_IMPORTED_MODULE_2__components_exports__) .websocket(new WebSocket(endpoint.indexOf('/') === 0 ? "ws://" + window.location.host + endpoint : endpoint)); + app.mediator.on('pixels/hue', (payload) => { + let msg = JSON.stringify({ + topic: 'pixels/state', + payload: JSON.stringify({ + brightness: 32, + color: parseInt(hues[payload][0].replace('#', '0x'), 16), + color2: parseInt(hues[payload][1].replace('#', '0x'), 16), + totalSteps: 32, + pattern: 5 + }) + }); + app.mediator.trigger('pixels/totalSteps', 32); + app.mediator.trigger('pixels/pattern', 5); + app.mediator.trigger('pixels/color', hues[payload][0]); + app.mediator.trigger('pixels/color2', hues[payload][1]); + console.log('pixels/hue: ' + msg); + app.ws.send(msg); + }); + // TODO make components __WEBPACK_IMPORTED_MODULE_0_jquery___default()('.collapsible').each((i, container) => { container.querySelector('.heading').addEventListener('click', (item) => { @@ -10936,6 +10956,7 @@ class App { websocket(websocket) { this.ws = websocket; + return this; } getStore(dataStore) { @@ -11110,6 +11131,9 @@ class Form extends __WEBPACK_IMPORTED_MODULE_1__core_Component__["a" /* default __WEBPACK_IMPORTED_MODULE_0_jquery___default.a.post(this.config.endpoint, { fileName: this.config.filename, config: JSON.stringify(data) }) .done((data) => { alert("data saved"); + }) + .fail((data) => { + alert("save failed"); }); }; @@ -11968,7 +11992,13 @@ class ParamSlider extends __WEBPACK_IMPORTED_MODULE_1__base_Slider_Slider__["a" payload: evt.target.value })); } - + subscribe(){ + this.ctx.mediator.on(this.config.topic, (payload) => { + //console.log(this.config.topic + ":" + payload); + this.node.find('input').val(payload); + //this.notify(payload); + }); + } } /* harmony export (immutable) */ __webpack_exports__["a"] = ParamSlider; @@ -12019,12 +12049,19 @@ class ParamColor extends __WEBPACK_IMPORTED_MODULE_1__base_ColorPicker_ColorPick constructor(ctx, node) { super(ctx, node); + this.ctx.mediator.on(this.config.topic, (payload) => { + this.node.find('input').val(payload); + }); } onChange(evt) { + this.notify(evt.target.value); + } + + notify(val){ let obj = { topic: this.config.topic, - payload: parseInt(this.value.replace('#', '0x')) + payload: parseInt(val.replace('#', '0x')) }; this.ctx.ws.send(JSON.stringify(obj)); console.log(obj); @@ -12107,7 +12144,14 @@ class ParamSelect extends __WEBPACK_IMPORTED_MODULE_1__base_Select_Select__["a" name: this.config.name, entries: this.config.entries }); - this.node.find('option[value="'+this.config.default+'"]').attr('selected', 'selected'); + this.selectEntry(this.config.default); + this.ctx.mediator.on(this.config.topic, (payload) => { + this.selectEntry(payload); + }); + } + + selectEntry(payload){ + this.node.find('option[value="'+payload+'"]').attr('selected', 'selected'); } onChange(evt) { @@ -12115,7 +12159,9 @@ class ParamSelect extends __WEBPACK_IMPORTED_MODULE_1__base_Select_Select__["a" topic: this.config.topic, payload: evt.target.value }; + this.ctx.mediator.trigger(obj.topic, obj.payload); this.ctx.ws.send(JSON.stringify(obj)); + } } diff --git a/lib/NeoPattern/NeoPattern.cpp b/lib/NeoPattern/NeoPattern.cpp index 8a507a7..5905b33 100644 --- a/lib/NeoPattern/NeoPattern.cpp +++ b/lib/NeoPattern/NeoPattern.cpp @@ -5,7 +5,6 @@ using namespace std; using namespace std::placeholders; - /** * Original NeoPattern code by Bill Earl @@ -28,7 +27,7 @@ class NeoPattern : public Adafruit_NeoPixel // Member Variables: pattern ActivePattern; // which pattern is running - direction Direction; // direction to run the pattern + direction Direction = FORWARD; // direction to run the pattern unsigned long Interval = 150; // milliseconds between updates unsigned long lastUpdate = 0; // last update of position @@ -52,12 +51,15 @@ class NeoPattern : public Adafruit_NeoPixel NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type) :Adafruit_NeoPixel(pixels, pin, type) { + //OnComplete = bind(&NeoPattern::onCompleteDefault, this, _1); TotalSteps = numPixels(); } void onCompleteDefault(int pixels) { - if(ActivePattern != RAINBOW_CYCLE){ - //Serial.println("reversing"); + //Serial.println("onCompleteDefault"); + // FIXME no specific code + if(ActivePattern == THEATER_CHASE){ + return; } Reverse(); //Serial.println("pattern completed"); diff --git a/src/PixelPlugin.h b/src/PixelPlugin.h index 7c7cc16..30f769b 100644 --- a/src/PixelPlugin.h +++ b/src/PixelPlugin.h @@ -34,13 +34,18 @@ class PixelPlugin : public Plugin { subscribe("pixels/totalSteps", bind(&PixelPlugin::setTotalSteps, this, _1)); subscribe("pixels/brightness", bind(&PixelPlugin::setBrightness, this, _1)); subscribe("pixels/state", bind(&PixelPlugin::setState, this, _1)); + subscribe("pixels/stream", bind(&PixelPlugin::stream, this, _1)); animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this)); userScheduler->addTask(animation); animation.enable(); PRINT_MSG(Serial, SPROCKET_TYPE, "NeoPixels activated"); } + void stream(String msg){ + // TODO handle LED byte array stream + } void setState(String msg) { + PRINT_MSG(Serial, SPROCKET_TYPE, msg.c_str()); state.fromJsonString(msg); pixels->setBrightness(state.brightness); pixels->ColorSet(state.color); @@ -49,6 +54,7 @@ class PixelPlugin : public Plugin { pixels->Color2 = state.color2; pixels->TotalSteps = state.totalSteps; pixels->ActivePattern = (pattern) state.pattern; + pixels->Direction = FORWARD; } void colorWheel(String msg){ int color = atoi(msg.c_str()); diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/test/package-lock.json b/test/package-lock.json new file mode 100644 index 0000000..8d15fc7 --- /dev/null +++ b/test/package-lock.json @@ -0,0 +1,24 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + }, + "coolhue": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/coolhue/-/coolhue-1.0.9.tgz", + "integrity": "sha512-4+ctEja6XNJ8GrV+OLbioHWssC8tT/IUSZlS6i/RXc0R+ef7g6jNGmLC4VwhEKCJXTKPQ0FqbwojYLDtpPXs1w==" + }, + "ws": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.0.0.tgz", + "integrity": "sha512-c2UlYcAZp1VS8AORtpq6y4RJIkJ9dQz18W32SpR/qXGfLDZ2jU4y4wKvvZwqbi7U6gxFQTeE+urMbXU/tsDy4w==", + "requires": { + "async-limiter": "1.0.0" + } + } + } +} diff --git a/test/palette.js b/test/palette.js new file mode 100644 index 0000000..577f2bf --- /dev/null +++ b/test/palette.js @@ -0,0 +1,28 @@ +const WebSocket = require('ws'); +const coolhue = require("coolhue"); + +var coolhueData = [ ["#FDEB71", "#F8D800"], ["#ABDCFF", "#0396FF"], ["#FEB692", "#EA5455"], ["#CE9FFC", "#7367F0"], ["#90F7EC", "#32CCBC"], ["#FFF6B7", "#F6416C"], ["#81FBB8", "#28C76F"], ["#E2B0FF", "#9F44D3"], ["#F97794", "#623AA2"], ["#FCCF31", "#F55555"], ["#F761A1", "#8C1BAB"], ["#43CBFF", "#9708CC"], ["#5EFCE8", "#736EFE"], ["#FAD7A1", "#E96D71"], ["#FFD26F", "#3677FF"], ["#A0FE65", "#FA016D"], ["#FFDB01", "#0E197D"], ["#FEC163", "#DE4313"], ["#92FFC0", "#002661"], ["#EEAD92", "#6018DC"], ["#F6CEEC", "#D939CD"], ["#52E5E7", "#130CB7"], ["#F1CA74", "#A64DB6"], ["#E8D07A", "#5312D6"], ["#EECE13", "#B210FF"], ["#79F1A4", "#0E5CAD"], ["#FDD819", "#E80505"], ["#FFF3B0", "#CA26FF"], ["#FFF5C3", "#9452A5"], ["#F05F57", "#360940"], ["#2AFADF", "#4C83FF"], ["#FFF886", "#F072B6"], ["#97ABFF", "#123597"], ["#F5CBFF", "#C346C2"], ["#FFF720", "#3CD500"], ["#FF6FD8", "#3813C2"], ["#EE9AE5", "#5961F9"], ["#FFD3A5", "#FD6585"], ["#C2FFD8", "#465EFB"], ["#FD6585", "#0D25B9"], ["#FD6E6A", "#FFC600"], ["#65FDF0", "#1D6FA3"], ["#6B73FF", "#000DFF"], ["#FF7AF5", "#513162"], ["#F0FF00", "#58CFFB"], ["#FFE985", "#FA742B"], ["#FFA6B7", "#1E2AD2"], ["#FFAA85", "#B3315F"], ["#72EDF2", "#5151E5"], ["#FF9D6C", "#BB4E75"], ["#F6D242", "#FF52E5"], ["#69FF97", "#00E4FF"], ["#3B2667", "#BC78EC"], ["#70F570", "#49C628"], ["#3C8CE7", "#00EAFF"], ["#FAB2FF", "#1904E5"], ["#81FFEF", "#F067B4"], ["#FFA8A8", "#FCFF00"], ["#FFCF71", "#2376DD"], ["#FF96F9", "#C32BAC"] ]; + +let gradient = coolhue.getGradientArray(19); +const host = '192.168.1.150';//'tardis.lan'; +const ws = new WebSocket('ws://'+host+'/pixel'); + +ws.on('open', function open() { + console.log(gradient); + let msg = JSON.stringify({ + topic: 'pixels/state', + payload: JSON.stringify({ + brightness: 32, + color: parseInt(gradient[0].replace('#', '0x'), 16), + color2: parseInt(gradient[1].replace('#', '0x'), 16), + totalSteps: 100, + pattern: 5 + }) + }); + console.log(msg); + ws.send(msg); +}); + +ws.on('message', function incoming(data) { + console.log(data); +}); \ No newline at end of file