lgq
3 天以前 081f12a52906abe6c2d139fdc144135978681009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;