Skip to content

Commit

Permalink
Minor: Made companion more resilent from USB problems on Raspbey pi 3…
Browse files Browse the repository at this point in the history
…, as discussed in #313
  • Loading branch information
haakonnessjoen committed Aug 31, 2019
1 parent 0eddb4c commit cd41bd5
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/usb/elgato.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,29 @@ elgato.prototype.quit = function () {
}
};

elgato.prototype.draw = function(key, buffer) {
elgato.prototype.draw = function(key, buffer, attempts) {
var self = this;

try {
key = self.mapButton(key);
// null/undefined => 0
attempts = ~~attempts;

if (key >= 0 && !isNaN(key)) {
buffer = self.handleBuffer(buffer);
self.streamDeck.fillImage(key, buffer);
}
} catch (e) {
self.system.emit('elgatodm_remove_device', self.devicepath);
if(!attempts){
buffer = self.handleBuffer(buffer);
}
attempts++;

return true;
try {
self.streamDeck.fillImage(self.reverseButton(key), buffer);
return true;
} catch (e) {
if(attempts > 2) {
self.log('Error drawing:', e);
self.system.emit('elgatodm_remove_device', self.devicepath);
return false;
}
setTimeout(self.draw.bind(self), 20, key, buffer, attempts)
// alternatively a setImmediate() or nextTick()
}
}

elgato.prototype.isPressed = function(key) {
Expand Down

0 comments on commit cd41bd5

Please sign in to comment.