btHsClose (Function)

Top  Previous  Next

Architecture:

X32 / NX32

Device support:

MX2 pro, DX4 pro, AX9 pro, MX2 turbo/encore/warp, AX9 turbo

Firmware version:

1.05


The btHsClose function is used to close the headset audio connection previously opened with btHsOpen.

 

Input:

None

 

Return: INT

0

- Success. Call accepted if Ring was TRUE.

-1

- Bluetooth library is not open.

-3

- Bluetooth module is not present.

-7

- Headset not connected.

 

Declaration:

FUNCTION btHsClose : INT;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc            : INT;
  ConID_Headset : SINT;
  btCon_Headset : btConnection;
  incomingCall  : gsmIncomingCall;
END_VAR;
 
// Turn on power to the GSM module, use no pin code
gsmPower(power := TRUE);
 
// Open the Bluetooth library
btOpen(name := "RTCU MX2");
 
// Set the Pin for incoming connections
btSetPin(pin := "1234");
 
// Initiate the headset connection
ConID_Headset:=btConnect(address:="00:e0:98:ae:17:23",pin:="0000", Headset:=TRUE);
DebugFmt(message:="Headset Connection ID =\1", v1:=ConID_Headset);
 
// setup the connection function block
btCon_Headset.id:=ConID_Headset;
 
BEGIN
btCon_Headset();
incomingCall();
 
IF btCon_Headset.changed THEN
  DebugMsg(message:="Connection info changed:");
  DebugFmt(message:="    Connected=\1",v1:=INT(btCon_Headset.connected));
  DebugMsg(message:="    Address="+btCon_Headset.Address);
  DebugFmt(message:="    Error=\1", v1:=btCon_Headset.Errorcode);
END_IF;
 
// Check for incoming calls
IF incomingCall.status > 0 THEN
  // Somebody is calling - notify the user
  DebugMsg(message:="Incoming call");
  rc:=btHsOpen(Ring:=TRUE, RingCount:=5);
  IF rc = 0 THEN
     DebugMsg(message:="    Call accepted");
    // Enable the gsmHeadset and answer the incoming call
    gsmHeadset(enable:=TRUE);
    gsmAnswer();
  // Wait for the call to end
     WHILE gsmOffHook() DO
     END_WHILE;
  // Hangup the call
     DebugMsg(message:="    Call finished");
    btHsClose();
  ELSE
  // The user didn't answer or rejected the call. Hangup the phone
     DebugMsg(message:="    Call Rejected");
    gsmHangup();
  END_IF;
END_IF;
  ...
 
END;
END_PROGRAM;