当我按下按钮时,如何对nRF52 DK进行编程以发送BLE MIDI消息?

时间:2019-08-16 08:37:35

标签: c bluetooth-lowenergy midi nrf52

我是使用真实C语言开发的新手。我有使用Arduino的更多经验。 当我按下Nordic nRF52 DK的按钮之一时,我试图通过Bluetooth MIDI发送MIDI消息。但是我没有成功。我该怎么办?

我尝试使用本教程:https://www.novelbits.io/bluetooth-gatt-services-characteristics/ 一切正常,我能够创建可发现的BLE MIDI设备。但是我一直坚持设置一种发送实际MIDI消息的方法。 我仅使用按钮打开/关闭DK LED进行了测试,一切正常

我想我应该在这里(midi_service.c)进行一些配置:

**@brief Function for handling the Write event.
 *
 * @param[in]   p_midi_service   LED Button Service structure.
 * @param[in]   p_ble_evt        Event received from the BLE stack.
 */
static void on_write(ble_midi_service_t * p_midi_service, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = (ble_gatts_evt_write_t *) &p_ble_evt->evt.gatts_evt.params.write;

    if ((p_evt_write->handle == p_midi_service->data_io_char_handles.value_handle) &&
        (p_evt_write->len == 1) &&
        (p_midi_service->evt_handler != NULL))
    {
      // Handle what happens on a write event to the characteristic value
    }

    // Check if the Custom value CCCD is written to and that the value is the appropriate length, i.e 2 bytes.
    if ((p_evt_write->handle == p_midi_service->data_io_char_handles.cccd_handle)
        && (p_evt_write->len == 2)
       )
    {
        // CCCD written, call application event handler
        if (p_midi_service->evt_handler != NULL)
        {
            ble_midi_evt_t evt;

            if (ble_srv_is_notification_enabled(p_evt_write->data))
            {
                evt.evt_type = BLE_DATA_IO_EVT_NOTIFICATION_ENABLED;
            }
            else
            {
                evt.evt_type = BLE_DATA_IO_EVT_NOTIFICATION_DISABLED;
            }

            p_midi_service->evt_handler(p_midi_service, &evt);
        }
    }
}

然后在这里找到在我的主要代码上调用它的方法:

case BSP_EVENT_KEY_3:
             LEDS_ON(1 << LED_4);
             //MIDI message

case BSP_EVENT_KEY_2:
             LEDS_OFF(1 << LED_4);
             //MIDI message

如果我尝试例如:

case BSP_EVENT_KEY_3:
             LEDS_ON(1 << LED_4);
             ble_add_char_params_t (0x80, 0x80, 0x90, 0x3c, 127);

(此处的想法是发送“ Note On”消息) 编译时出现错误“预期标识符或数字常量前的'('”。 可能这是一种非常愚蠢的方法,但是正如我说的那样,我是这种编码的新手,因此不确定如何做到。 使用Arduino我可以做到,但是我想学习如何更“认真”地编写代码。

0 个答案:

没有答案