Cumminicate the RC value to the server

Afterwards update the frontend accordingly.
This commit is contained in:
Shannon Sterz 2016-02-18 17:41:33 +01:00
parent fddf4464b8
commit 6bc20016d8

View file

@ -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 = { var o = {
RCs: [] 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 ( ) { o.irTest = function ( ) {
return $http.get('/irTest'); return $http.get('/irTest');
} }
@ -42,14 +49,15 @@ app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){
$scope.RCs = arduino.RCs; $scope.RCs = arduino.RCs;
for (var i = $scope.RCs.length - 1; i >= 0; i--) { for (var i = $scope.RCs.length - 1; i >= 0; i--) {
$scope.RCs[i].state = true; $scope.RCs[i].state = false;
} }
$scope.irTest = function(RC){ $scope.sendRC = function(RC){
arduino.sendRC(RC);
};
$scope.irTest = function(){
arduino.irTest(); arduino.irTest();
RC.state = (RC.state) ? false : true;
}; };
}]); }]);