import { displayClass } from './libvbar-m-dxdisplay.so' const dxDisplay = {}; // Create a singleton instance of the native displayClass. // This is executed only once when the module is first imported due to the nature of ES modules. const displayObj = new displayClass(); /** * Get the current display backlight brightness. * @returns {number} Backlight brightness value (0-100). * @throws {Error} If failed to get backlight. */ dxDisplay.getBacklight = function () { return displayObj.getBacklight(); } /** * Set the display backlight brightness. * @param {number} brightness - The brightness value to set (0-100). * @throws {Error} If failed to set backlight. */ dxDisplay.setBacklight = function (brightness) { if (brightness === undefined || brightness === null) { throw new Error("dxDisplay.setBacklight: 'brightness' parameter is required"); } if (typeof brightness !== 'number' || brightness < 0 || brightness > 100) { throw new Error("dxDisplay.setBacklight: 'brightness' must be a number between 0 and 100"); } displayObj.setBacklight(brightness); } /** * Get the screen enable status. * @returns {boolean} 1 if enabled, 0 if disabled. * @throws {Error} If failed to get enable status. */ dxDisplay.getEnableStatus = function () { return displayObj.getEnableStatus(); } /** * Set the screen enable status. * @param {boolean|number} enable - true/1 to enable screen, false/0 to disable. * @throws {Error} If failed to set enable status. */ dxDisplay.setEnableStatus = function (enable) { if (enable === undefined || enable === null) { throw new Error("dxDisplay.setEnableStatus: 'enable' parameter is required"); } displayObj.setEnableStatus(enable); } /** * Get the current display power mode. * @returns {number} Power mode value: * - 0: VBAR_DRV_DISPLAY_POWER_MODE_NORMAL (Normal mode) * - 1: VBAR_DRV_DISPLAY_POWER_MODE_STANDBY (Standby mode) * @throws {Error} If failed to get power mode. */ dxDisplay.getPowerMode = function () { return displayObj.getPowerMode(); } /** * Set the display power mode. * @param {number} mode - The power mode to set: * - 0: VBAR_DRV_DISPLAY_POWER_MODE_NORMAL (Normal mode) * - 1: VBAR_DRV_DISPLAY_POWER_MODE_STANDBY (Standby mode) * @throws {Error} If failed to set power mode. */ dxDisplay.setPowerMode = function (mode) { if (mode === undefined || mode === null) { throw new Error("dxDisplay.setPowerMode: 'mode' parameter is required"); } if (mode !== 0 && mode !== 1) { throw new Error("dxDisplay.setPowerMode: 'mode' must be 0 (NORMAL) or 1 (STANDBY)"); } displayObj.setPowerMode(mode); } export default dxDisplay;