Galzai / MK32

Keyboard firmware for ESP32 microcontrollers
667 stars 117 forks source link

Battery monitor value #23

Closed gijsn closed 3 years ago

gijsn commented 3 years ago

Hi, Great project! Really comes in very useful for my single keyboard on the ESP32 (the sick68, no oled screen), I'll write up the wiki of how I built the thing once its done. Love the BLE functionality.

Though I have one minor issue, I cannot get the battery level to change on Windows. By default its set to 50% in the code, but all my attempts at modifying the attribute value have failed thus far. I saw the HID code is very similar to the esp-idf example, but unfortunately they also did not implement it. Could you give me some pointers to how I can adapt the value?

Let me know! Gijs

Edit: I was able to add the following lines to hid_device_le_prf.c (around line 582, after the ESP_GATTS_CONNECT_EVT code) after some more extensive researchign:

battary_level = 60;
esp_ble_gatts_set_attr_value(battary_table[BAS_IDX_BAT_LVL_VAL], sizeof(uint8_t), &battary_lev);
esp_ble_gatts_sed_indicate(gatts_if, param->connect.conn_id, battery_Table[BAS_IDX_BATT_LVL_VAL], sizeof(uint8_t), &battary_lev, false);

while defining the battery_table as such around line 620 (with static uint16_t battery_table[BAS_IDX_NB])

memcpy(battery_table, param->add_attr_tab.handles, sizeof(battery_table)

Though I have not found a proper way to make this periodic yet..

gijsn commented 3 years ago

I was finally able to achieve this: https://github.com/Galzai/MK32/compare/master...gijsn:master#diff-d0d45ac689cb047a071964d07f04cad0b774b3ccb7aeae83a0af1231368893f0R177

Not really sure if this is the proper way, but it works for me

Galzai commented 3 years ago

If everything works for you feel free to make a pull request for this feature! As you can see I'm not really active with this project, so I apologize for the lack of prior response.

gijsn commented 3 years ago

No worries, Ill cherry pick the code as I made some other changes as well and submit a PR