Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve codes for undefined buttons #26

Open
K4in-5037 opened this issue Jun 23, 2024 · 2 comments
Open

Retrieve codes for undefined buttons #26

K4in-5037 opened this issue Jun 23, 2024 · 2 comments

Comments

@K4in-5037
Copy link

how can I get the codes needed to add in HidUsageTables.json as indicated in #21?, I have a FireTV Remote Pro, is not an original but it works (with some mislabeled buttons), the issue is that the 4 bottom buttons (the branded streaming services buttons) doesn't send anything through the sensors, and the logger doesn't show anything useful, here is the message I get when I press any of those buttons

[00:28:52][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 3] - 10
[00:28:52][V][esp32_ble_client:121]: [0] [47:54:41:A2:FE:52] gattc_event_handler: event=10 gattc_if=3
[00:28:52][D][esp32_ble_client:110]: [0] [47:54:41:A2:FE:52] ESP_GATTC_NOTIFY_EVT
[00:28:52][D][ble_client_hid:184]: Received HID input report from handle 61
[00:28:52][D][hid_parser:350]: Parsing HID report with report ID (239)
[00:28:52][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 3] - 10
[00:28:52][V][esp32_ble_client:121]: [0] [47:54:41:A2:FE:52] gattc_event_handler: event=10 gattc_if=3
[00:28:52][D][esp32_ble_client:110]: [0] [47:54:41:A2:FE:52] ESP_GATTC_NOTIFY_EVT
[00:28:52][D][ble_client_hid:184]: Received HID input report from handle 46
[00:28:52][D][hid_parser:350]: Parsing HID report with report ID (1)
[00:28:52][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 3] - 10
[00:28:52][V][esp32_ble_client:121]: [0] [47:54:41:A2:FE:52] gattc_event_handler: event=10 gattc_if=3
[00:28:52][D][esp32_ble_client:110]: [0] [47:54:41:A2:FE:52] ESP_GATTC_NOTIFY_EVT
[00:28:52][D][ble_client_hid:184]: Received HID input report from handle 57
[00:28:52][D][hid_parser:350]: Parsing HID report with report ID (2)

is there a way to get the relevant codes for those buttons so I can define them in the json file?

@koying
Copy link

koying commented Jan 19, 2025

This does it:

koying@57db77e

It generates code like

  # Prime Video
  - "161_0":
  # Netflix
  - "162_0":
  # Disney+
  - "163_0":
  # Hulu
  - "164_0":

for that "Alexa remote" that I got from Ali

@K4in-5037
Copy link
Author

K4in-5037 commented Jan 25, 2025

Thank you, I tried your fork and it works. Then for fun I tried to assign proper names and fix the mislabeled buttons, I'm putting here my process in case it helps someone else.

First you need to edit an add to the HidUsageTables.json the new entries with the matching ids.

"UsagePages": [
	{
      "Kind": "Defined",
      "Id": 161,
      "Name": "FireTV Custom 1",
      "UsageIds": [
        {
          "Id": 0,
          "Name": "App 1",
          "Kinds": [
            "Sel"
          ]
        }
      ],
      "UsageIdGenerator": null
    },
	{
      "Kind": "Defined",
      "Id": 162,
      "Name": "FireTV Custom 2",
      "UsageIds": [
        {
          "Id": 0,
          "Name": "App 2",
          "Kinds": [
            "Sel"
          ]
        }
      ],
      "UsageIdGenerator": null
    },
	{
      "Kind": "Defined",
      "Id": 163,
      "Name": "FireTV Custom 3",
      "UsageIds": [
        {
          "Id": 0,
          "Name": "App 3",
          "Kinds": [
            "Sel"
          ]
        }
      ],
      "UsageIdGenerator": null
    },
	{
      "Kind": "Defined",
      "Id": 164,
      "Name": "FireTV Custom 4",
      "UsageIds": [
        {
          "Id": 0,
          "Name": "App 4",
          "Kinds": [
            "Sel"
          ]
        }
      ],
      "UsageIdGenerator": null
    },
...

Run the generate_cpp_usage_tables.py script and it will create the new header files, copy it to the ble_client_hid main folder, then edit the usages.cpp file to include the new button definitions.

#include "usages.h"
#include "generic_desktop.h"
#include "keyboard_keypad.h"
#include "consumer.h"
#include "firetv_custom_1.h"
#include "firetv_custom_2.h"
#include "firetv_custom_3.h"
#include "firetv_custom_4.h"

const std::map<uint8_t, const UsagePage> USAGE_PAGES {
  {0x01, USAGE_PAGE_GENERIC_DESKTOP},
  {0x07, USAGE_PAGE_KEYBOARD_KEYPAD},
  {0x0C, USAGE_PAGE_CONSUMER},
  {0xA1, USAGE_PAGE_FIRETV_CUSTOM_1},
  {0xA2, USAGE_PAGE_FIRETV_CUSTOM_2},
  {0xA3, USAGE_PAGE_FIRETV_CUSTOM_3},
  {0xA4, USAGE_PAGE_FIRETV_CUSTOM_4}
};

The first number is the id in HEX (161 = 0xA1 ).
Finally run your esphome project with the new modified code (heads up on the refresh option of the External component by default it will use cache of 1 day thus any recent changes will not apply).

After getting this to work I checked that commit again koying@57db77e and thought, why the return index return on the page value instead of the usage value? wouldn't it be better to have a single page with id 0 and a usage value? that way I would only need to define a single file instead of four, so I swaped the return values to return HIDUsage(index,0); and now I get reported "0_161" instead, and could indeed define the button names in a single file with id 0 (0x00).

Granted I don't actually understand this code or where index comes from, so I don't know if there was a reason of it being like that in the first place, but is working for me.

Anyway thank you again @koying for the solution, actually your post in the HA forum is what led me to this esphome component while searching for a non IR universal remote alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants