Skip to content

Commit

Permalink
Fixed Enable/Disable GPU functionality
Browse files Browse the repository at this point in the history
Added error/success notifications using Toastr
  • Loading branch information
brandon-barker committed Feb 8, 2014
1 parent be9611e commit f847956
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
23 changes: 20 additions & 3 deletions app/scripts/controllers/DashboardCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down Expand Up @@ -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 () {
});

Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ <h2>Dashboard
<td>
<span class="fa fa-fw handicon"
ng-class="{'fa-check':device.Enabled == 'Y','fa-times':device.Enabled == 'N'}"
ng-click="toggleGpu(device)">
ng-click="toggleGpu(miner, device)">
</span>
</td>
<td>{{device.Model.replace('AMD Radeon', '')}}</td>
Expand Down
12 changes: 6 additions & 6 deletions lib/modules/bfgminer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},

Expand Down
30 changes: 26 additions & 4 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit f847956

Please sign in to comment.