From b4bd1cb7bbb7e7d8b95aa882c604a1ad07da137b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 30 Apr 2018 09:40:44 +0200 Subject: [PATCH] Added web UI for MCP3008 analog sensors values --- .../http/static/css/gpio.sensor.mcp3008.css | 0 .../http/static/js/gpio.sensor.mcp3008.js | 47 +++++++++++++++++++ .../plugins/gpio.sensor.mcp3008.html | 5 ++ 3 files changed, 52 insertions(+) create mode 100644 platypush/backend/http/static/css/gpio.sensor.mcp3008.css create mode 100644 platypush/backend/http/static/js/gpio.sensor.mcp3008.js create mode 100644 platypush/backend/http/templates/plugins/gpio.sensor.mcp3008.html diff --git a/platypush/backend/http/static/css/gpio.sensor.mcp3008.css b/platypush/backend/http/static/css/gpio.sensor.mcp3008.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/platypush/backend/http/static/js/gpio.sensor.mcp3008.js b/platypush/backend/http/static/js/gpio.sensor.mcp3008.js new file mode 100644 index 0000000000..86b897aefd --- /dev/null +++ b/platypush/backend/http/static/js/gpio.sensor.mcp3008.js @@ -0,0 +1,47 @@ +$(document).ready(function() { + var $container = $('#sensors-container'); + + var onEvent = function(event) { + switch (event.args.type) { + case 'platypush.message.event.sensor.SensorDataChangeEvent': + var data = event.args.sensors; + + for (var sensor of Object.keys(data)) { + var $sensor = $container.find('[data-sensor-type=' + sensor + ']'); + var $sensorValue; + + if ($sensor.length === 0) { + $sensor = $('
') + .addClass('row sensor-data') + .attr('data-sensor-type', sensor); + + var $name = $('
') + .addClass('sensor-name six columns') + .text(sensor); + + $sensorValue = $('
') + .addClass('sensor-value six columns'); + + $sensor.appendTo($container); + } else { + $sensorValue = $sensor.find('.sensor-value'); + } + + $sensorValue.text(data[sensor]); + } + + break; + } + }; + + var initEvents = function() { + window.registerEventListener(onEvent); + }; + + var init = function() { + initEvents(); + }; + + init(); +}); + diff --git a/platypush/backend/http/templates/plugins/gpio.sensor.mcp3008.html b/platypush/backend/http/templates/plugins/gpio.sensor.mcp3008.html new file mode 100644 index 0000000000..be1a5151c0 --- /dev/null +++ b/platypush/backend/http/templates/plugins/gpio.sensor.mcp3008.html @@ -0,0 +1,5 @@ + + + +
+