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. (Fixed bug)
  • Loading branch information
haakonnessjoen committed Aug 31, 2019
1 parent cd41bd5 commit bfadbb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ device.prototype.updateBank = function(page, bank) {

if (page == self.page) {
setImmediate(function () {
self.panel.draw(bank - 1, img.buffer, img.updated);
self.panel.draw(bank - 1, img.buffer);
});
}
} else {
Expand Down
19 changes: 15 additions & 4 deletions lib/usb/elgato.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,31 @@ elgato.prototype.draw = function(key, buffer, attempts) {
// null/undefined => 0
attempts = ~~attempts;

if(!attempts){
if (attempts === 0) {
buffer = self.handleBuffer(buffer);
}

attempts++;

var drawKey = self.mapButton(key);

try {
self.streamDeck.fillImage(self.reverseButton(key), buffer);

if (drawKey !== undefined && drawKey >= 0 && drawKey < self.info.keysTotal) {
self.streamDeck.fillImage(drawKey, buffer);
}

return true;
} catch (e) {
if(attempts > 2) {
self.log('Error drawing:', e);
self.log('StreamDeck USB Exception: ' + e.message);

if (attempts > 2) {
self.log('Giving up USB device ' + self.devicepath);
self.system.emit('elgatodm_remove_device', self.devicepath);

return false;
}

setTimeout(self.draw.bind(self), 20, key, buffer, attempts)
// alternatively a setImmediate() or nextTick()
}
Expand Down

0 comments on commit bfadbb1

Please sign in to comment.