Skip to content

Commit b92eb58

Browse files
committed
feature: Added brightness control feature.
1 parent c8539fe commit b92eb58

16 files changed

Lines changed: 44624 additions & 44424 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ WebScreen uses a JSON configuration file stored on the SD card as `/webscreen.js
156156
"background": "#2980b9",
157157
"foreground": "#00fff1"
158158
},
159+
"display": {
160+
"brightness": 200
161+
},
159162
"script": "app.js"
160163
}
161164
```
@@ -169,6 +172,7 @@ WebScreen uses a JSON configuration file stored on the SD card as `/webscreen.js
169172
| **settings.mqtt** | `enabled` | Enable MQTT functionality | `false` |
170173
| **screen** | `background` | Background color (hex format) | `"#000000"` |
171174
| | `foreground` | Text/foreground color (hex) | `"#FFFFFF"` |
175+
| **display** | `brightness` | Display brightness (0-255) | `200` |
172176
| **Root** | `script` | JavaScript file to execute | `"app.js"` |
173177

174178
### Example Configurations
@@ -374,6 +378,7 @@ WebScreen includes a comprehensive serial command system for interactive develop
374378
/info - Show device information and version
375379
/write <filename> - Interactive JavaScript editor
376380
/load <script.js> - Switch to different JS application
381+
/brightness <0-255> - Set display brightness (no args to query current)
377382
/reboot - Restart the device
378383
```
379384
@@ -448,6 +453,7 @@ The firmware exposes numerous functions to your JavaScript applications. Some hi
448453
- **HTTP:** `http_get()`, `http_post()`, `http_delete()` (all support custom ports like `http://host:port/path`), `http_set_ca_cert_from_sd()`, `parse_json_value()`
449454
- **SD Card:** `sd_read_file()`, `sd_write_file()`, `sd_list_dir()`, `sd_delete_file()`
450455
- **BLE:** `ble_init()`, `ble_is_connected()`, `ble_write()`
456+
- **Display:** `set_brightness()`, `get_brightness()`
451457
- **UI Drawing:** `draw_label()`, `draw_rect()`, `show_image()`, `create_label()`, `label_set_text()`
452458
- **Image Handling:** `create_image()`, `create_image_from_ram()`, `rotate_obj()`, `move_obj()`, `animate_obj()`
453459
- **Styles & Layout:** `create_style()`, `obj_add_style()`, `style_set_*()`, `obj_align()`

docs/API.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ WebScreen exposes a comprehensive set of functions to JavaScript applications ru
66

77
```json
88
{
9-
"wifi": {
10-
"ssid": "MyNetwork",
11-
"password": "MyPassword",
12-
"enabled": true
9+
"settings": {
10+
"wifi": {
11+
"ssid": "MyNetwork",
12+
"pass": "MyPassword"
13+
},
14+
"mqtt": {
15+
"enabled": false
16+
}
1317
},
14-
"mqtt": {
15-
"enabled": false
18+
"screen": {
19+
"background": "#2980b9",
20+
"foreground": "#00fff1"
1621
},
1722
"display": {
18-
"background_color": "#2980b9",
19-
"foreground_color": "#00fff1"
23+
"brightness": 200
2024
},
21-
"script_file": "my_app.js"
25+
"script": "my_app.js"
2226
}
2327
```
2428

@@ -40,6 +44,23 @@ The following functions are available in your JavaScript applications:
4044
- **create_timer()**
4145
Create a timer object for periodic execution.
4246

47+
### Display Control
48+
49+
- **set_brightness(value)**
50+
Set the display brightness. Value ranges from 0 (off) to 255 (maximum). Returns the applied brightness value, or -1 on error.
51+
```javascript
52+
set_brightness(200); // Set brightness to ~78%
53+
set_brightness(0); // Turn off display backlight
54+
set_brightness(255); // Maximum brightness
55+
```
56+
57+
- **get_brightness()**
58+
Returns the current display brightness value (0-255).
59+
```javascript
60+
let current = get_brightness();
61+
print("Current brightness: " + numberToString(current));
62+
```
63+
4364
### String Utilities
4465

4566
- **str_index_of(haystack, needle)**

docs/SerialCommands.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ WebScreen> /help
6060
/wget <url> [file] - Download file from URL to SD card
6161
/ping <host> - Test network connectivity
6262
/backup [save|restore] - Backup/restore configuration
63+
/brightness <0-255> - Set display brightness
6364
/monitor [cpu|mem|net] - Live system monitoring
6465
/reboot - Restart the device
6566
@@ -127,6 +128,32 @@ WebScreen Version: 2.0.0
127128
Build Date: Dec 15 2024 14:30:25
128129
```
129130

131+
#### `/brightness <0-255>`
132+
Sets or queries the display brightness level.
133+
134+
**Usage:**
135+
```
136+
WebScreen> /brightness
137+
Current brightness: 200
138+
139+
WebScreen> /brightness 150
140+
[OK] Brightness set to 150
141+
142+
WebScreen> /brightness 255
143+
[OK] Brightness set to 255
144+
```
145+
146+
**Parameters:**
147+
- **No argument**: Displays the current brightness level
148+
- **0-255**: Sets the brightness to the specified value (0 = off, 255 = maximum)
149+
150+
**Notes:**
151+
- Changes take effect immediately on the AMOLED display
152+
- To persist brightness across reboots, also set `display.brightness` in the configuration:
153+
```
154+
/config set display.brightness 150
155+
```
156+
130157
#### `/reboot` or `/restart`
131158
Restarts the WebScreen device. Useful for applying configuration changes or recovering from errors.
132159

2.63 KB
Binary file not shown.
8.65 KB
Binary file not shown.

0 commit comments

Comments
 (0)