Page 1 of 1

How do I change the battery level ?

Posted: Tue Jan 18, 2022 4:24 am
by daemondong
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.

Re: How do I change the battery level ?

Posted: Fri Jan 21, 2022 7:33 am
by daemondong
I think this is the basic battery function. Could anyone help me about it ? Thank you.

Re: How do I change the battery level ?

Posted: Sat Jan 22, 2022 4:43 am
by Sprite
You can use esp_hidd_dev_battery_set for that.

Re: How do I change the battery level ?

Posted: Sat Jan 22, 2022 2:26 pm
by daemondong
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.

Code: Untitled.c Select all


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);
}
}

Code: Untitled.tex Select all


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

Re: How do I change the battery level ?

Posted: Fri Feb 25, 2022 1:43 pm
by daemondong
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();
    }