How Do I Programmatically Turn the MC90xx Bluetooth Radio On/Off?

Article ID: 18761073

Question

Can the Bluetooth radio in the MC90xx can be programmatically turned on and off.

Facts

MC90xx running WM 2003

Answer

The following code is used to turn the Bluetooth radio on and off programmatically:
 
BOOL BTPwr(BOOL bOn)
{
      if(bOn)
      {
                  // Set the BT radio mode to on
                  BthSetMode(BTH_CONNECTABLE);
                  if (IsBTPwrSet(BTH_CONNECTABLE, 10000))
                        return true;
      }
      else
      {
                  BthSetMode(BTH_POWER_OFF);
                  if (IsBTPwrSet(BTH_POWER_OFF, 10000))
                                       return true;
      }
                return false;
}
 
// check whether the BT pwr is set right
BOOL IsBTPwrSet (DWORD dwExpectedMode, DWORD dwTimeout)
{
      DWORD dwMode;
      DWORD dwStartTime = GetTickCount();  // start timer
 
      // Polling every 1 second until it's set or timeout
    do
    {
                  if (BthGetMode( &dwMode) == ERROR_SUCCESS )
                  {
                              if (dwMode == dwExpectedMode)
                                          return true;
                  }
 
                  Sleep(1000);
    } while ((GetTickCount() -  dwStartTime) < dwTimeout);
   
    return false;
}