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