r1729 - oipf/emulator/js/contollers
Author: ygrego Date: 2015-06-16 15:28:55 +0000 (Tue, 16 Jun 2015) New Revision: 1729 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1729 Log: The power state of emulator must be managed by a distinct controller. Modified: oipf/emulator/js/contollers/RemoteControlControllers.js Modified: oipf/emulator/js/contollers/RemoteControlControllers.js =================================================================== --- oipf/emulator/js/contollers/RemoteControlControllers.js 2015-06-16 10:38:11 UTC (rev 1728) +++ oipf/emulator/js/contollers/RemoteControlControllers.js 2015-06-16 15:28:55 UTC (rev 1729) @@ -6,25 +6,16 @@ var RemoteControlControllers = angular.module('RemoteControlControllers', []); RemoteControlControllers.controller('RemoteControlController', - ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { + ['$rootScope', '$scope', '$http', '$timeout', function ($rootScope, $scope, $http, $timeout) { + $http.get('./emulator/remoteControl/remoteControl.json').success(function(data) { $scope.remoteControl = data; }); - $scope.clickMapping = { - "POWER": "setEmulatorON", - "0": "setChannelByNumber", - "1": "setChannelByNumber", - "2": "setChannelByNumber", - "3": "setChannelByNumber", - "4": "setChannelByNumber", - "5": "setChannelByNumber", - "6": "setChannelByNumber", - "7": "setChannelByNumber", - "8": "setChannelByNumber", - "9": "setChannelByNumber", - "V+": "setVolume", - "V-": "setVolume", + $scope.remoteControlClick = function(buttonId) { + var methodName = $scope.clickMapping[buttonId]; + console.log("methodName:", methodName, $scope[methodName]); + methodName && $scope[methodName].call($scope, buttonId); }; $scope.state = 'OFF'; @@ -32,16 +23,33 @@ $scope.channelNumber = ""; $scope.channelNumberActive = false; $scope.volumeViewActive = false; - $scope.emulatorON = false; + $rootScope.powerChange = false; $scope.currentVolume = 50; $scope.setSate = function() { }; - $scope.setEmulatorON = function() { - $scope.emulatorON = !$scope.emulatorON; + $scope.setPowerChange = function() { + $rootScope.powerChange = !$rootScope.powerChange; + console.log($rootScope.powerChange); }; + $scope.clickMapping = { + "POWER": "setPowerChange", + "0": "setChannelByNumber", + "1": "setChannelByNumber", + "2": "setChannelByNumber", + "3": "setChannelByNumber", + "4": "setChannelByNumber", + "5": "setChannelByNumber", + "6": "setChannelByNumber", + "7": "setChannelByNumber", + "8": "setChannelByNumber", + "9": "setChannelByNumber", + "V+": "setVolume", + "V-": "setVolume" + }; + $scope.setChannelByNumber = function(buttonId) { $scope.channelNumberActive = true; @@ -67,13 +75,61 @@ $scope.volumeViewActive = false; }, 3000); }; +}]); - $scope.remoteControlClick = function(buttonId) { - var methodName = $scope.clickMapping[buttonId]; - console.log("methodName:", methodName, $scope[methodName]); - methodName && $scope[methodName].call($scope, buttonId); - }; - }]); +RemoteControlControllers.controller("PowerStateController", + ["$rootScope", "$scope", "ConfigurationService", function($rootScope, $scope, ConfigurationService) { + $scope.onStarting = true; + $scope.videoStyle = "off"; + $scope.configurationService = ConfigurationService(); + + $scope.configurationService.localSystem.onPowerStateChange = function(state) { + if ($scope.waitingState == state && $scope.result) { + if (state == 0) { + + console.log("POWER STATE CHANGE: OFF."); + $scope.videoStyle = "off"; + + } else { + + console.log("POWER STATE CHANGE: ON."); + $scope.videoStyle = "on"; + + } + } else { + + console.log("POWER STATE CHANGE: ERROR."); + + } + $scope.$apply(); + + console.groupEnd("PowerStateController"); + }; + + $rootScope.$watch("powerChange", function() { + + if (!$scope.onStarting) { + console.group("PowerStateController"); + console.log("The power state will change."); + + if ($scope.configurationService.localSystem.powerState == 0) { + + $scope.waitingState = 1; + $scope.result = $scope.configurationService.localSystem.setPowerState(1); + + } else if ($scope.configurationService.localSystem.powerState == 1) { + + $scope.waitingState = 0; + $scope.result = $scope.configurationService.localSystem.setPowerState(0); + } + } else { + $scope.onStarting = false; + } + + + }); + +}]);
participants (1)
-
ygregoï¼ users.nuiton.org