How do I change the battery level ?
-
- Posts: 11
- Joined: Fri Dec 24, 2021 7:20 am
How do I change the battery level ?
I'm using the example of ..\bluetooth\esp_hid_device to do some tests. I can use Lightblue APP on Android phone to read the battery level. It's 0x64 always. I can't find the code to change it. Could anyone can tell me after I get the voltage of battery how do I change the battery level? Thank you.
-
- Posts: 11
- Joined: Fri Dec 24, 2021 7:20 am
Re: How do I change the battery level ?
I think this is the basic battery function. Could anyone help me about it ? Thank you.
-
- Posts: 9709
- Joined: Thu Nov 26, 2015 4:08 am
Re: How do I change the battery level ?
You can use esp_hidd_dev_battery_set for that.
-
- Posts: 11
- Joined: Fri Dec 24, 2021 7:20 am
Re: How do I change the battery level ?
I updated the hid_demo_task as below. I could find the battery level was changed and set. But when I use Bluelight to read the battery level it still keeps 0x64.
- void hid_demo_task(void *pvParameters)
- {
- static bool send_volum_up = false;
- static uint8_t tcn=0;
- static uint8_t lvlBatt=100;
- while (1) {
- tcn++;
- if (tcn>=5) {
- tcn=0;
- if (lvlBatt>30) lvlBatt--;
- esp_hidd_dev_battery_set(hid_dev,lvlBatt);
- ESP_LOGI(TAG, "Batt Level = %d",lvlBatt);
- }
- if (dev_connected) {
- ESP_LOGI(TAG, "Send the volume");
- if (send_volum_up) {
- esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_UP, true);
- vTaskDelay(100 / portTICK_PERIOD_MS);
- esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_UP, false);
- } else {
- esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_DOWN, true);
- vTaskDelay(100 / portTICK_PERIOD_MS);
- esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_DOWN, false);
- }
- send_volum_up = !send_volum_up;
- }
- vTaskDelay(2000 / portTICK_PERIOD_MS);
- }
- }
- I (61098) HID_DEV_DEMO: Batt Level = 94
- I (61098) HID_DEV_DEMO: Send the volume
- W (61098) Test: cmd=233,press=1
- W (61198) Test: cmd=233,press=0
- I (63198) HID_DEV_DEMO: Send the volume
- W (63198) Test: cmd=234,press=1
- W (63298) Test: cmd=234,press=0
- I (65298) HID_DEV_DEMO: Send the volume
- W (65298) Test: cmd=233,press=1
- W (65398) Test: cmd=233,press=0
- I (67398) HID_DEV_DEMO: Send the volume
- W (67398) Test: cmd=234,press=1
- W (67498) Test: cmd=234,press=0
- I (69498) HID_DEV_DEMO: Send the volume
- W (69498) Test: cmd=233,press=1
- W (69598) Test: cmd=233,press=0
- I (71598) HID_DEV_DEMO: Batt Level = 93
- I (71598) HID_DEV_DEMO: Send the volume
- W (71598) Test: cmd=234,press=1
- W (71698) Test: cmd=234,press=0
-
- Posts: 11
- Joined: Fri Dec 24, 2021 7:20 am
Re: How do I change the battery level ?
I got it. The battery level should be set as below.
Code: Select all
if (deviceConnected) {
pCharacteristicBatt->setValue((uint8_t*)&batterylevel, 1);
pCharacteristicBatt->notify();
Serial.printf("*** NOTIFY: %s ***\n", logRunning);
//the function excepts string
pCharacteristicRun->setValue((uint8_t *)logRunning,512);
pCharacteristicRun->notify();
}
Who is online
Users browsing this forum: No registered users and 270 guests