fix(display): use execSync shell pipe instead of fs.writeFileSync to avoid EINVAL
Made-with: Cursor
This commit is contained in:
10
lib/led.js
10
lib/led.js
@@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const log = require('./logger');
|
const { execSync } = require('child_process');
|
||||||
|
const log = require('./logger');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前面板指示灯控制
|
* 前面板指示灯控制
|
||||||
@@ -110,9 +111,10 @@ class Display {
|
|||||||
|
|
||||||
_write(val) {
|
_write(val) {
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(DISPLAY_PATH, val);
|
// 用 shell 管道写入,与 echo "..." | tee ... 行为完全一致
|
||||||
|
execSync(`echo "${val}" | tee ${DISPLAY_PATH} > /dev/null`, { timeout: 3000 });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.warn('display', `写入失败 (${DISPLAY_PATH}): ${e.message}`);
|
log.warn('display', `写入失败: ${e.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user