graphics() raspian detection

This commit is contained in:
Sebastian Hildebrandt 2019-01-13 14:36:22 +01:00
parent 5a7d5992b6
commit fa7e7c5d12
4 changed files with 84 additions and 20 deletions

View File

@ -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() | | | hostname | X | X | X | X | X | same as os.hostname() |
| | codepage | X | X | X | X | | OS build version | | | codepage | X | X | X | X | | OS build version |
| | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | | | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| | serial | | X | X | X | | OS/Host serial number | | | serial | X | X | X | X | | OS/Host serial number |
| | build | | | X | X | | OS build version | | | build | X | | X | X | | OS build version |
| si.uuid(cb) | {...} | X | X | X | X | X | object of several UUIDs | | si.uuid(cb) | {...} | X | X | X | X | X | object of several UUIDs |
| | os | X | X | X | X | | os specific UUID | | | os | X | X | X | X | | os specific UUID |
| si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) | | si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) |

View File

@ -161,7 +161,7 @@
<tr> <tr>
<td></td> <td></td>
<td>serial</td> <td>serial</td>
<td></td> <td>X</td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>
@ -171,7 +171,7 @@
<tr> <tr>
<td></td> <td></td>
<td>build</td> <td>build</td>
<td></td> <td>X</td>
<td></td> <td></td>
<td>X</td> <td>X</td>
<td>X</td> <td>X</td>

View File

@ -396,32 +396,65 @@ function graphics(callback) {
}); });
} }
if (_linux) { if (_linux) {
let cmd = 'lspci -vvv 2>/dev/null'; // Raspberry: https://elinux.org/RPI_vcgencmd_usage
exec(cmd, function (error, stdout) { if (util.isRaspberry() && util.isRaspbian()) {
if (!error) { let cmd = 'fbset -s | grep \'mode "\'; vcgencmd get_mem gpu; tvservice -s; tvservice -n;';
let lines = stdout.toString().split('\n'); exec(cmd, function (error, stdout) {
result.controllers = parseLinesLinuxControllers(lines); let lines = stdout.toString().split('\n');
} if (lines.length > 3 && lines[0].indexOf('mode "' >= -1)) {
let cmd = 'xdpyinfo 2>/dev/null | grep \'depth of root window\' | awk \'{ print $5 }\''; 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) { exec(cmd, function (error, stdout) {
let depth = 0;
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); 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) { exec(cmd, function (error, stdout) {
let depth = 0;
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
result.displays = parseLinesLinuxDisplays(lines, depth); depth = parseInt(lines[0]) || 0;
} }
if (callback) { let cmd = 'xrandr --verbose 2>/dev/null';
callback(result); exec(cmd, function (error, stdout) {
} if (!error) {
resolve(result); let lines = stdout.toString().split('\n');
result.displays = parseLinesLinuxDisplays(lines, depth);
}
if (callback) {
callback(result);
}
resolve(result);
});
}); });
}); });
}); }
} }
if (_freebsd || _openbsd) { if (_freebsd || _openbsd) {
if (callback) { callback(result); } if (callback) { callback(result); }

View File

@ -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) { function execWin(cmd, opts, callback) {
if (!callback) { if (!callback) {
callback = opts; callback = opts;
@ -325,3 +354,5 @@ exports.powerShell = powerShell;
exports.nanoSeconds = nanoSeconds; exports.nanoSeconds = nanoSeconds;
exports.countUniqueLines = countUniqueLines; exports.countUniqueLines = countUniqueLines;
exports.noop = noop; exports.noop = noop;
exports.isRaspberry = isRaspberry;
exports.isRaspbian = isRaspbian;