This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Audio controls for iOS and Android

Hi.

I'm trying to get audio controls (mostly volume up/down) to work with apple and android phones. I've used as base your HDI keyboard example.

It seems to work OK with apple what comes to controls themselves, but problem is that as it advertises itself as keyboard, the virtual keyboard doesn't work. I assume I have to change the hids_init report map to be only consumer control? Do I also have to change the device appearance to some other type?

As sidenote is there simplier way of handling this? I mean I only need the volume up/down and perhaps next/previous track, not full on keyboard/mouse interface.

EDIT:

Ok, I changed the sd_ble_gap_appearance_set to other than keyboard and now the iOS works.

However I would like to trim the hids_init report_map_data. I tried this:

static uint8_t report_map_data[] =
{
    // Report ID 2: Advanced buttons
    0x05, 0x0C,                     // Usage Page (Consumer)
    0x09, 0x01,                     // Usage (Consumer Control)
    0xA1, 0x01,                     // Collection (Application)

    0x85, 0x01,                     //     Report Id (1)
    0x15, 0x00,                     //     Logical minimum (0)
    0x25, 0x01,                     //     Logical maximum (1)
    0x75, 0x01,                     //     Report Size (1)
    0x95, 0x01,                     //     Report Count (1)

    0x09, 0xCD,                     //     Usage (Play/Pause)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x83, 0x01,               //     Usage (AL Consumer Control Configuration)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xB5,                     //     Usage (Scan Next Track)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xB6,                     //     Usage (Scan Previous Track)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)

    0x09, 0xEA,                     //     Usage (Volume Down)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x09, 0xE9,                     //     Usage (Volume Up)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x25, 0x02,               //     Usage (AC Forward)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0x0A, 0x24, 0x02,               //     Usage (AC Back)
    0x81, 0x02,                     //     Input (Data,Value,Relative,Bit Field)
    0xC0                            // End Collection		
};

I changed the indexes and the system seems to be running ok:

hids_init_obj.evt_handler                    = on_hids_evt;
hids_init_obj.error_handler                  = alert_notification_error_handler;
hids_init_obj.is_kb                          = true;
hids_init_obj.is_mouse                       = false;
hids_init_obj.inp_rep_count                  = 1;
hids_init_obj.p_inp_rep_array                = input_report_array;
hids_init_obj.outp_rep_count                 = 1;
hids_init_obj.p_outp_rep_array               = output_report_array;
hids_init_obj.feature_rep_count              = 0;
hids_init_obj.p_feature_rep_array            = NULL;
hids_init_obj.rep_map.data_len               = sizeof(report_map_data);
hids_init_obj.rep_map.p_data                 = report_map_data;
hids_init_obj.hid_information.bcd_hid        = BASE_USB_HID_SPEC_VERSION;
hids_init_obj.hid_information.b_country_code = 0;
hids_init_obj.hid_information.flags          = hid_info_flags;
hids_init_obj.included_services_count        = 0;
hids_init_obj.p_included_services_array      = NULL;

However iOS doesn't respond to commands. Am I missing something mandatory in the config? I couldn't find any explanation how the report map is configured.

EDIT2: I also noticed, that with android (5.0.2) the same keyboard code that works OK in iOS doesn't work at all in android and hangs up after few seconds if vol up/down is sent. Should the android be able to use the hids_keyboard example right on?

I also connected to this device via gatt and tried to enable notifications for all the HIDS reports (also wrote the descriptors to enable notification mode). Not quite sure what are the connection mode requirements here (bonded/not bonded).

Parents Reply Children
No Data
Related