From 6bc20016d840571352c9aac07e961376e7b42ef9 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Thu, 18 Feb 2016 17:41:33 +0100 Subject: [PATCH] Cumminicate the RC value to the server Afterwards update the frontend accordingly. --- nodejs/public/javascripts/angularApp.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/nodejs/public/javascripts/angularApp.js b/nodejs/public/javascripts/angularApp.js index 5ff2163..8122fa7 100644 --- a/nodejs/public/javascripts/angularApp.js +++ b/nodejs/public/javascripts/angularApp.js @@ -19,7 +19,7 @@ app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $url }]); -app.factory('arduino', ['$http', function($http, auth){ +app.factory('arduino', ['$http', function($http){ var o = { RCs: [] }; @@ -30,6 +30,13 @@ app.factory('arduino', ['$http', function($http, auth){ }); } + o.sendRC = function (RC) { + var code = (RC.state) ? RC.off_value : RC.on_value; + return $http.post('/register', {code}).success(function (data) { + RC.state = (RC.state) ? false : true; + }); + } + o.irTest = function ( ) { return $http.get('/irTest'); } @@ -42,14 +49,15 @@ app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){ $scope.RCs = arduino.RCs; for (var i = $scope.RCs.length - 1; i >= 0; i--) { - $scope.RCs[i].state = true; + $scope.RCs[i].state = false; } - $scope.irTest = function(RC){ - - arduino.irTest(); - RC.state = (RC.state) ? false : true; + $scope.sendRC = function(RC){ + arduino.sendRC(RC); + }; + $scope.irTest = function(){ + arduino.irTest(); }; }]); \ No newline at end of file