Skip to content

Commit

Permalink
Tweak.
Browse files Browse the repository at this point in the history
  • Loading branch information
supercobra committed Oct 30, 2018
1 parent e69c823 commit 374befc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions q-cpu-usage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Library to make track cpuUsage
// if not installed run npm install request
// Library to track cpuUsage
const os = require('os-utils');

// Library to send signal to Q keyboards
const q = require('daskeyboard-applet');

// Color associated to each coordinate
// Color associated to cpu activity from low (green) to high (red).
const colors = ['#00FF00', '#00FF00', '#00FF00', '#00FF00', '#FFFF00', '#FFFF00', '#FF0000',
'#FF0000', '#FF0000', '#FF0000'
];
Expand All @@ -13,9 +13,11 @@ const colors = ['#00FF00', '#00FF00', '#00FF00', '#00FF00', '#FFFF00', '#FFFF00'
class CpuUsage extends q.DesktopApp {
constructor() {
super();
// run every 3000 ms
this.pollingInterval = 3000;
}

// call this function every pollingInterval
async run() {
this.getCpuUsage();
}
Expand All @@ -24,7 +26,8 @@ class CpuUsage extends q.DesktopApp {
getColor(zoneIndex, numberOfKeysToLight) {
if (zoneIndex > numberOfKeysToLight) {
// if the zone is after the number max of keys to light. Turn off the light
return '#000000'; // Black color = no light
// Black color = no light
return '#000000';
} else {
// turn on the zone with the proper color
return colors[zoneIndex];
Expand All @@ -39,18 +42,21 @@ class CpuUsage extends q.DesktopApp {
const numberOfKeysToLight = Math.round(numberOfKeys * v) + 1;
let points = [];

// create a list of points (zones) with a color). Each point
// correspond to an LED
for (let i = 0; i < numberOfKeys; i++) {
points.push(new q.Point(this.getColor(i, numberOfKeysToLight)));
};
}

// send list of RGB zones to Q keyboard
this.sendLocal(new q.Signal({
points: [points],
points: [points],
name: "CPU Usage",
message: Math.round(v * 100) + "%",
isMuted: true,
}))
}));
});
}
}

const cpuUsage = new CpuUsage();
const cpuUsage = new CpuUsage();

0 comments on commit 374befc

Please sign in to comment.