ref: verify hardware
This commit is contained in:
+36
-12
@@ -18,12 +18,24 @@ global.HARDWARE = global.HARDWARE || {
|
|||||||
* @param {Object} args - The command-line arguments to customize the initialization process.
|
* @param {Object} args - The command-line arguments to customize the initialization process.
|
||||||
* @returns {boolean} Returns true if the initialization was successful.
|
* @returns {boolean} Returns true if the initialization was successful.
|
||||||
*/
|
*/
|
||||||
const init = (args) => {
|
const init = async (args) => {
|
||||||
const model = getModel();
|
if (!args.mqtt_url) {
|
||||||
const valid = model && model.includes("Raspberry Pi 5");
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check supported hardware
|
// Check supported hardware
|
||||||
if (valid) {
|
if (!hardwareExists()) {
|
||||||
|
console.warn("Hardware not supported");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check supported model
|
||||||
|
const model = getModel();
|
||||||
|
if (!model || !model.includes("Raspberry Pi 5")) {
|
||||||
|
console.warn(`Device ${model} not supported`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
console.log("\nModel:", getModel());
|
console.log("\nModel:", getModel());
|
||||||
console.log("Serial Number:", getSerialNumber());
|
console.log("Serial Number:", getSerialNumber());
|
||||||
console.log("Host Name:", getHostName());
|
console.log("Host Name:", getHostName());
|
||||||
@@ -41,11 +53,8 @@ const init = (args) => {
|
|||||||
|
|
||||||
// Check for display changes
|
// Check for display changes
|
||||||
setInterval(update, 500);
|
setInterval(update, 500);
|
||||||
} else {
|
|
||||||
console.warn(`Device ${model} not supported`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return valid;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +87,21 @@ const update = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies hardware compatibility by checking the presence of necessary sys files.
|
||||||
|
*
|
||||||
|
* @returns {bool} Returns true if all files exists.
|
||||||
|
*/
|
||||||
|
const hardwareExists = () => {
|
||||||
|
const files = [
|
||||||
|
"/sys/firmware/devicetree/base/model",
|
||||||
|
"/sys/firmware/devicetree/base/serial-number",
|
||||||
|
"/sys/class/backlight/10-0045/brightness",
|
||||||
|
"/sys/class/backlight/10-0045/bl_power",
|
||||||
|
];
|
||||||
|
return files.every((file) => fs.existsSync(file));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Raspberry Pi model name using `/sys/firmware/devicetree/base/model`.
|
* Gets the Raspberry Pi model name using `/sys/firmware/devicetree/base/model`.
|
||||||
*
|
*
|
||||||
@@ -192,8 +216,8 @@ const getDisplayStatus = () => {
|
|||||||
*/
|
*/
|
||||||
const setDisplayStatus = (status, callback = null) => {
|
const setDisplayStatus = (status, callback = null) => {
|
||||||
if (status !== "ON" && status !== "OFF") {
|
if (status !== "ON" && status !== "OFF") {
|
||||||
console.error("Status must be 'ON' or 'OFF'.");
|
console.error("Status must be 'ON' or 'OFF'");
|
||||||
if (typeof callback === "function") callback(null, "Invalid status.");
|
if (typeof callback === "function") callback(null, "Invalid status");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const args = status === "ON" ? ["--on", "*"] : ["--off", "*"];
|
const args = status === "ON" ? ["--on", "*"] : ["--off", "*"];
|
||||||
@@ -240,8 +264,8 @@ const getDisplayBrightness = () => {
|
|||||||
*/
|
*/
|
||||||
const setDisplayBrightness = (brightness, callback = null) => {
|
const setDisplayBrightness = (brightness, callback = null) => {
|
||||||
if (typeof brightness !== "number" || brightness < 1 || brightness > 100) {
|
if (typeof brightness !== "number" || brightness < 1 || brightness > 100) {
|
||||||
console.error("Brightness must be a number between 1 and 100.");
|
console.error("Brightness must be a number between 1 and 100");
|
||||||
if (typeof callback === "function") callback(null, "Invalid brightness.");
|
if (typeof callback === "function") callback(null, "Invalid brightness");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const value = Math.max(1, Math.min(Math.round((brightness / 100) * 31), 31));
|
const value = Math.max(1, Math.min(Math.round((brightness / 100) * 31), 31));
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@ global.INTEGRATION = global.INTEGRATION || {
|
|||||||
* @param {Object} args - The command-line arguments to customize the initialization process.
|
* @param {Object} args - The command-line arguments to customize the initialization process.
|
||||||
* @returns {boolean} Returns true if the initialization was successful.
|
* @returns {boolean} Returns true if the initialization was successful.
|
||||||
*/
|
*/
|
||||||
const init = (args) => {
|
const init = async (args) => {
|
||||||
if (!args.mqtt_url) {
|
if (!args.mqtt_url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ const initRefresh = (client) => {
|
|||||||
)
|
)
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/execute`) {
|
if (topic === `${root}/execute`) {
|
||||||
console.log("Refresh webview...");
|
console.log("Refreshing webview...");
|
||||||
hardware.setDisplayStatus("ON");
|
hardware.setDisplayStatus("ON");
|
||||||
WEBVIEW.view.webContents.reloadIgnoringCache();
|
WEBVIEW.view.webContents.reloadIgnoringCache();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -15,9 +15,9 @@ global.WEBVIEW = global.WEBVIEW || {
|
|||||||
* @param {Object} args - The command-line arguments to customize the initialization process.
|
* @param {Object} args - The command-line arguments to customize the initialization process.
|
||||||
* @returns {boolean} Returns true if the initialization was successful.
|
* @returns {boolean} Returns true if the initialization was successful.
|
||||||
*/
|
*/
|
||||||
const init = (args) => {
|
const init = async (args) => {
|
||||||
if (!args.web_url) {
|
if (!args.web_url) {
|
||||||
console.error("Please provide the '--web-url' parameter.");
|
console.error("Please provide the '--web-url' parameter");
|
||||||
return app.quit();
|
return app.quit();
|
||||||
}
|
}
|
||||||
const url = new URL(args.web_url);
|
const url = new URL(args.web_url);
|
||||||
|
|||||||
Reference in New Issue
Block a user