How do I change the battery level ?

daemondong
Posts: 11
Joined: Fri Dec 24, 2021 7:20 am

How do I change the battery level ?

Postby daemondong » Tue Jan 18, 2022 4:24 am

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.

daemondong
Posts: 11
Joined: Fri Dec 24, 2021 7:20 am

Re: How do I change the battery level ?

Postby daemondong » Fri Jan 21, 2022 7:33 am

I think this is the basic battery function. Could anyone help me about it ? Thank you.

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: How do I change the battery level ?

Postby ESP_Sprite » Sat Jan 22, 2022 4:43 am

You can use esp_hidd_dev_battery_set for that.

daemondong
Posts: 11
Joined: Fri Dec 24, 2021 7:20 am

Re: How do I change the battery level ?

Postby daemondong » Sat Jan 22, 2022 2:26 pm

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.
  1. void hid_demo_task(void *pvParameters)
  2. {
  3.     static bool send_volum_up = false;
  4.     static uint8_t tcn=0;
  5.     static uint8_t lvlBatt=100;
  6.     while (1) {
  7.         tcn++;
  8.         if (tcn>=5) {
  9.             tcn=0;
  10.             if (lvlBatt>30) lvlBatt--;
  11.             esp_hidd_dev_battery_set(hid_dev,lvlBatt);
  12.             ESP_LOGI(TAG, "Batt Level = %d",lvlBatt);
  13.         }
  14.         if (dev_connected) {
  15.             ESP_LOGI(TAG, "Send the volume");
  16.             if (send_volum_up) {
  17.                 esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_UP, true);
  18.                 vTaskDelay(100 / portTICK_PERIOD_MS);
  19.                 esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_UP, false);
  20.             } else {
  21.                 esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_DOWN, true);
  22.                 vTaskDelay(100 / portTICK_PERIOD_MS);
  23.                 esp_hidd_send_consumer_value(HID_CONSUMER_VOLUME_DOWN, false);
  24.             }
  25.             send_volum_up = !send_volum_up;
  26.         }
  27.         vTaskDelay(2000 / portTICK_PERIOD_MS);
  28.     }
  29. }
  1. I (61098) HID_DEV_DEMO: Batt Level = 94
  2. I (61098) HID_DEV_DEMO: Send the volume
  3. W (61098) Test: cmd=233,press=1
  4.  
  5. W (61198) Test: cmd=233,press=0
  6.  
  7. I (63198) HID_DEV_DEMO: Send the volume
  8. W (63198) Test: cmd=234,press=1
  9.  
  10. W (63298) Test: cmd=234,press=0
  11.  
  12. I (65298) HID_DEV_DEMO: Send the volume
  13. W (65298) Test: cmd=233,press=1
  14.  
  15. W (65398) Test: cmd=233,press=0
  16.  
  17. I (67398) HID_DEV_DEMO: Send the volume
  18. W (67398) Test: cmd=234,press=1
  19.  
  20. W (67498) Test: cmd=234,press=0
  21.  
  22. I (69498) HID_DEV_DEMO: Send the volume
  23. W (69498) Test: cmd=233,press=1
  24.  
  25. W (69598) Test: cmd=233,press=0
  26.  
  27. I (71598) HID_DEV_DEMO: Batt Level = 93
  28. I (71598) HID_DEV_DEMO: Send the volume
  29. W (71598) Test: cmd=234,press=1
  30.  
  31. W (71698) Test: cmd=234,press=0

daemondong
Posts: 11
Joined: Fri Dec 24, 2021 7:20 am

Re: How do I change the battery level ?

Postby daemondong » Fri Feb 25, 2022 1:43 pm

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 347 guests