From f847956335c1a2bd25b9a073fc9129b9b46ad3d9 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Sat, 8 Feb 2014 13:47:51 +0200 Subject: [PATCH] Fixed Enable/Disable GPU functionality Added error/success notifications using Toastr --- app/scripts/controllers/DashboardCtrl.js | 23 +++++++++++++++--- app/views/partials/main.html | 2 +- lib/modules/bfgminer.js | 12 +++++----- lib/socket.js | 30 ++++++++++++++++++++---- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/app/scripts/controllers/DashboardCtrl.js b/app/scripts/controllers/DashboardCtrl.js index 91d8a5b..0fdd5ca 100644 --- a/app/scripts/controllers/DashboardCtrl.js +++ b/app/scripts/controllers/DashboardCtrl.js @@ -13,13 +13,13 @@ angular.module('nodeminerApp') $scope.showSummary = true; $scope.miners = []; - $scope.toggleGpu = function (device) { + $scope.toggleGpu = function (miner, device) { if (device.Enabled == 'Y') { console.log('Disabling ' + device.Model + ' (' + device.ID + ')'); - socket.emit('gpu:disable', device); + socket.emit('gpu:disable', { miner:miner, device:device }); } else { console.log('Enabling ' + device.Model + ' (' + device.ID + ')'); - socket.emit('gpu:enable', device); + socket.emit('gpu:enable', { miner:miner, device:device }); } } @@ -149,6 +149,23 @@ angular.module('nodeminerApp') } }); + socket.on('error:gpuenable', function (status) { + toastr.error('Error enabling GPU: ' + status.Msg); + }); + + socket.on('error:gpudisable', function (status) { + toastr.error('Error disabling GPU: ' + status.Msg); + }); + + socket.on('success:gpuenable', function (status) { + toastr.success('Successfully enabled GPU.'); + }); + + + socket.on('success:gpudisable', function (status) { + toastr.success('Successfully disabled GPU.'); + }); + socket.emit('init:pools', function () { }); diff --git a/app/views/partials/main.html b/app/views/partials/main.html index aeebf7c..4335d2d 100644 --- a/app/views/partials/main.html +++ b/app/views/partials/main.html @@ -150,7 +150,7 @@

Dashboard + ng-click="toggleGpu(miner, device)"> {{device.Model.replace('AMD Radeon', '')}} diff --git a/lib/modules/bfgminer.js b/lib/modules/bfgminer.js index fe5a8f6..0ea51a6 100644 --- a/lib/modules/bfgminer.js +++ b/lib/modules/bfgminer.js @@ -74,31 +74,31 @@ module.exports = { }); }, - enableGpu: function (miner, device) { + enableGpu: function (miner, device, callback) { var self = this; self.config = _.extend({}, self.defaults, miner) || self.defaults; self.send('gpuenable', device.ID, function (err, data) { if (err) { - console.log('Error enabling device! ' + err); + callback(err); } - console.log('Enabled GPU.'); + callback(null, data); }); }, - disableGpu: function (miner, device) { + disableGpu: function (miner, device, callback) { var self = this; self.config = _.extend({}, self.defaults, miner) || self.defaults; self.send('gpudisable', device.ID, function (err, data) { if (err) { - console.log('Error disabling device!!! ' + err); + callback(err); } - console.log('Disabled GPU.'); + callback(null, data); }); }, diff --git a/lib/socket.js b/lib/socket.js index f9a86d1..3714789 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -111,12 +111,34 @@ module.exports = function (socket) { }); }); - socket.on('gpu:enable', function (miner, device) { - bfgminer.enableGpu(miner, device); + socket.on('gpu:enable', function (data) { + var miner = data.miner; + var device = data.device; + + bfgminer.enableGpu(miner, device, function(err, data) { + if (err || data.STATUS[0].STATUS == 'E') { + socket.emit('error:gpuenable', data.STATUS[0]); + } + + if (data.STATUS[0].STATUS == 'I') { + socket.emit('success:gpuenable', data.STATUS[0]); + } + }); }); - socket.on('gpu:disable', function (miner, device) { - bfgminer.disableGpu(miner, device); + socket.on('gpu:disable', function (data) { + var miner = data.miner; + var device = data.device; + + bfgminer.disableGpu(miner, device, function(err, data){ + if (err || data.STATUS[0].STATUS == 'E') { + socket.emit('error:gpudisable', data.STATUS[0]); + } + + if (data.STATUS[0].STATUS == 'I') { + socket.emit('success:gpudisable', data.STATUS[0]); + } + }); }); socket.on('disconnect', function () {