Drivers Libraries Help > BM64 Bluetooth Driver Library > Using the Library > How the Library Works > Settings Functions
MPLAB Harmony Bluetooth Help
Settings Functions

The function DRV_BM64_VolumeGet returns the volume for the current mode (A2DP or HFP) in percent (0-100), and the corresponding function DRV_BM64_VolumeSet sets the volume in percent. 

The functions DRV_BM64_VolumeUp and DRV_BM64_VolumeDown turn the volume up and down on the host device (e.g. smartphone) by one increment (about 3% of full-scale). Either of these will result in a callback with the event DRV_BM64_EVENT_VOLUME_CHANGED specifying the new volume setting. 

Example:  

case BUTTON_STATE_PRESSED:      // (debouncing not shown)
{
    // bump the volume up one notch based on a button press
    if (BSP_SwitchStateGet(BSP_SWITCH_2)==BSP_SWITCH_STATE_PRESSED))
    {
        // note generic version of call (DRV_BT instead of DRV_BM64) is used
        DRV_BT_volumeUp(appData.bt.handle);
        appData.buttonState=BUTTON_STATE_WAIT_FOR_RELEASE;
    }
}

. . .

// later, a call will come back to the event handler callback function
// (previously set up via a call to DRV_BM64_EventHandlerSet)
static void _BLEEventHandler(DRV_BT_EVENT event, uint32_t param, uintptr_t context)
{
    switch(event)
    {
        case DRV_BM64_EVENT_VOLUME_CHANGED:
        {
            uint16_t volume7bits = (127*param)/100;     // convert to 7 bits
            DRV_AK4384_VolumeSet(audioData.codec.handle,         // update codec’s volume
                    DRV_AK4384_CHANNEL_LEFT_RIGHT,volume7bits);
            laString tempStr;
            char buf[5];
            sprintf(buf,"%3d%%",param);
            laWidget_SetVisible((laWidget*)GFX_VOLUME_VALUE, LA_TRUE);
            tempStr = laString_CreateFromCharBuffer(buf, &LiberationSans12);
            laLabelWidget_SetText(GFX_VOLUME_VALUE, tempStr);    // update screen
            laString_Destroy(&tempStr);
        }
   }
}