|
34 | 34 |
|
35 | 35 | bool is_connected = false; |
36 | 36 | QueueHandle_t input_queue = NULL; |
37 | | - |
| 37 | +static uint8_t s_battery_level = 0; |
38 | 38 | const char *DEVICE_NAME = "ESP32 Remote"; |
39 | 39 |
|
40 | 40 | /** |
@@ -76,7 +76,6 @@ void joystick_task() |
76 | 76 | uint8_t hat_switch = 0; // unused in this example |
77 | 77 | uint8_t button_in = 0; |
78 | 78 | uint8_t throttle = 0; // unused in this example |
79 | | - |
80 | 79 | while (true) { |
81 | 80 | DELAY(HID_LATENCY); |
82 | 81 |
|
@@ -140,6 +139,18 @@ void joystick_task() |
140 | 139 | } |
141 | 140 | } |
142 | 141 |
|
| 142 | +static void battery_timer_cb(TimerHandle_t xTimer) |
| 143 | +{ |
| 144 | + s_battery_level = (s_battery_level + 1) % 100; |
| 145 | + ESP_LOGI(HID_DEMO_TAG, "Change battery level to %d", s_battery_level); |
| 146 | + if (is_connected) { |
| 147 | + esp_err_t ret = set_hid_battery_level(s_battery_level); |
| 148 | + if (ret != ESP_OK) { |
| 149 | + ESP_LOGE(HID_DEMO_TAG, "Failed to set battery level"); |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | + |
143 | 154 | /** |
144 | 155 | * @brief Initialize bluetooth resources |
145 | 156 | * @return ESP_OK on success; any other value indicates error |
@@ -250,7 +261,11 @@ void app_main(void) |
250 | 261 | #else //CONFIG_JOYSTICK_INPUT_MODE_ADC |
251 | 262 | xTaskCreate(joystick_ext_read, "ext_hardware_joystick", 2048, NULL, tskIDLE_PRIORITY, NULL); |
252 | 263 | #endif |
253 | | - |
| 264 | + // Create a timer to update battery level periodically (add 1 each time as an example) |
| 265 | + TimerHandle_t battery_timer = xTimerCreate(NULL, pdMS_TO_TICKS(5000), true, NULL, battery_timer_cb); |
| 266 | + if (xTimerStart(battery_timer, 0) != pdPASS) { |
| 267 | + ESP_LOGE(HID_DEMO_TAG, "Failed to start battery timer"); |
| 268 | + } |
254 | 269 | // Main joystick task |
255 | 270 | joystick_task(); |
256 | 271 |
|
|
0 commit comments