Skip to content

Commit

Permalink
Show temp, leds-sim shows text
Browse files Browse the repository at this point in the history
  • Loading branch information
C-D-Lewis committed Nov 20, 2023
1 parent 06f75f7 commit 54c7089
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 13 deletions.
19 changes: 11 additions & 8 deletions apps/monitor/src/plugins/rack-oled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const {
} = require('os');
const visuals = require('../modules/visuals');
const {
ip, log, conduit, wait,
} = require('../node-common')(['ip', 'log', 'conduit', 'wait']);
ip, log, temperature,
} = require('../node-common')(['ip', 'log', 'temperature']);

/**
* Monitor stats for display on rack-mounted OLED display.
Expand All @@ -23,20 +23,23 @@ module.exports = async () => {
const [, time] = new Date().toISOString().split('T');
const timeNow = time.split(':').slice(0, 2).join(':');

const { message: apps } = await conduit.send({ to: 'conduit', topic: 'getApps' });
const appsUp = apps.filter((p) => p.status === 'OK').length;
// Running conduit apps
// const { message: apps } = await conduit.send({ to: 'conduit', topic: 'getApps' });
// const appsUp = apps.filter((p) => p.status === 'OK').length;

const temp = temperature.get();

const lines = [
`${hostname} (.${ipLastTwoOctets})`,
'',
`${timeNow} (Up ${uptimeStr} hrs)`,
`C:${cpuMinute} / M:${memoryPerc} / A:${appsUp}/${apps.length}`,
`C:${cpuMinute} | M:${memoryPerc} | T:${temp}`,
];
log.debug(lines);

await visuals.setText(lines);

// Preserve oled burn-in
await wait(10000);
await visuals.setText([]);
// Prevent oled burn-in
// await wait(10000);
// await visuals.setText([]);
};
3 changes: 2 additions & 1 deletion apps/visuals/src/api/state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const handles = require('../modules/handles');

const { leds, conduit } = require('../node-common')(['leds', 'conduit']);
const { leds, conduit, textDisplay } = require('../node-common')(['leds', 'conduit', 'textDisplay']);

/**
* Handle a 'state' topic packet.
Expand All @@ -11,6 +11,7 @@ const { leds, conduit } = require('../node-common')(['leds', 'conduit']);
const handleStatePacket = async (packet, res) => {
const message = {
leds: leds.getState(),
text: textDisplay.getLinesState(),
handles: Object.entries(handles.getAll()).map(([k, v]) => ({ [k]: !!v })),
};
await conduit.respond(res, { status: 200, message });
Expand Down
76 changes: 75 additions & 1 deletion tools/leds-simulator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions tools/leds-simulator/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ const chalk = require('chalk');

const INTERVAL_MS = 1000;

const updateDisplay = (ledArr) => {
process.stdout.clearLine();
const updateDisplay = (ledArr, textArr) => {
console.clear();

// LEDs
process.stdout.cursorTo(0);
ledArr.forEach(led => process.stdout.write(chalk.rgb(...led)('\u25C9 ')));

// Text lines
textArr.forEach((p) => {
process.stdout.write('\n');
process.stdout.write(p);
});
};

const main = async () => {
Expand All @@ -15,7 +23,7 @@ const main = async () => {
setInterval(async () => {
try {
const state = await conduit.send({ to: 'visuals', topic: 'state' }, { silent: true });
updateDisplay(state.message.leds);
updateDisplay(state.message.leds, state.message.text);
} catch (e) {
console.log('Disconnected');
}
Expand Down

0 comments on commit 54c7089

Please sign in to comment.