From fa7e7c5d1202cdb82f6b9c0c45402bff953efb24 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 13 Jan 2019 14:36:22 +0100 Subject: [PATCH] graphics() raspian detection --- README.md | 4 +-- docs/os.html | 4 +-- lib/graphics.js | 65 +++++++++++++++++++++++++++++++++++++------------ lib/util.js | 31 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9dc12b7..e2bd25a 100644 --- a/README.md +++ b/README.md @@ -265,8 +265,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | hostname | X | X | X | X | X | same as os.hostname() | | | codepage | X | X | X | X | | OS build version | | | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | -| | serial | | X | X | X | | OS/Host serial number | -| | build | | | X | X | | OS build version | +| | serial | X | X | X | X | | OS/Host serial number | +| | build | X | | X | X | | OS build version | | si.uuid(cb) | {...} | X | X | X | X | X | object of several UUIDs | | | os | X | X | X | X | | os specific UUID | | si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) | diff --git a/docs/os.html b/docs/os.html index f64bdb2..dba7b22 100644 --- a/docs/os.html +++ b/docs/os.html @@ -161,7 +161,7 @@ serial - + X X X X @@ -171,7 +171,7 @@ build - + X X X diff --git a/lib/graphics.js b/lib/graphics.js index 5122497..a956ae3 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -396,32 +396,65 @@ function graphics(callback) { }); } if (_linux) { - let cmd = 'lspci -vvv 2>/dev/null'; - exec(cmd, function (error, stdout) { - if (!error) { - let lines = stdout.toString().split('\n'); - result.controllers = parseLinesLinuxControllers(lines); - } - let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; + // Raspberry: https://elinux.org/RPI_vcgencmd_usage + if (util.isRaspberry() && util.isRaspbian()) { + let cmd = 'fbset -s | grep \'mode "\'; vcgencmd get_mem gpu; tvservice -s; tvservice -n;'; + exec(cmd, function (error, stdout) { + let lines = stdout.toString().split('\n'); + if (lines.length > 3 && lines[0].indexOf('mode "' >= -1)) { + const parts = lines[0].replace('mode', '').replace(/"/g, '').trim().split('x'); + if (parts.length === 2) { + push({ + model: getValue(lines, 'device_name', '='), + main: true, + builtin: false, + connection: 'HDMI', + sizex: -1, + sizey: -1, + pixeldepth: -1, + resolutionx: parseInt(parts[0], 10), + resolutiony: parseInt(parts[1], 10) + }) + } + } + if (lines.length > 1 && lines[1].indexOf('gpu=' >= -1) { + push({ + vendor: 'Broadcom', + model: 'VideoCore IV', + bus: '', + vram: lines[1].replace('gpu=', ''), + vramDynamic: true + }) + } + }); + } else { + let cmd = 'lspci -vvv 2>/dev/null'; exec(cmd, function (error, stdout) { - let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - depth = parseInt(lines[0]) || 0; + result.controllers = parseLinesLinuxControllers(lines); } - let cmd = 'xrandr --verbose 2>/dev/null'; + let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; exec(cmd, function (error, stdout) { + let depth = 0; if (!error) { let lines = stdout.toString().split('\n'); - result.displays = parseLinesLinuxDisplays(lines, depth); + depth = parseInt(lines[0]) || 0; } - if (callback) { - callback(result); - } - resolve(result); + let cmd = 'xrandr --verbose 2>/dev/null'; + exec(cmd, function (error, stdout) { + if (!error) { + let lines = stdout.toString().split('\n'); + result.displays = parseLinesLinuxDisplays(lines, depth); + } + if (callback) { + callback(result); + } + resolve(result); + }); }); }); - }); + } } if (_freebsd || _openbsd) { if (callback) { callback(result); } diff --git a/lib/util.js b/lib/util.js index 5cc5c1e..bdf4394 100644 --- a/lib/util.js +++ b/lib/util.js @@ -275,6 +275,35 @@ function getCodepage() { } } +function isRaspberry() { + const PI_MODEL_NO = [ + 'BCM2708', + 'BCM2709', + 'BCM2710', + 'BCM2835', + 'BCM2837B0' + ]; + let cpuinfo = []; + try { + cpuinfo = fs.readFileSync('/proc/cpuinfo', { encoding: 'utf8' }).split('\n'); + } catch (e) { + return false; + }; + const hardware = getValue(cpuinfo, 'hardware'); + return (PI_MODEL_NO.indexOf(hardware) >= -1) +} + +function isRaspbian() { + let osrelease = []; + try { + osrelease = fs.readFileSync('/etc/os-release', { encoding: 'utf8' }).split('\n'); + } catch (e) { + return false; + }; + const id = getValue(cpuinfo, 'id'); + return (id.indexOf('raspbian') >= -1) +} + function execWin(cmd, opts, callback) { if (!callback) { callback = opts; @@ -325,3 +354,5 @@ exports.powerShell = powerShell; exports.nanoSeconds = nanoSeconds; exports.countUniqueLines = countUniqueLines; exports.noop = noop; +exports.isRaspberry = isRaspberry; +exports.isRaspbian = isRaspbian;