btHsOpen (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 btHsOpen is used to open the audio connection to a connected headset. It is possible to issue a Ring command by setting Ring to TRUE when the function is called. Then the headset will play a ring tone until the user accepts/rejects the call or the defined number of rings is reached. If the user accepts the incoming call, the audio connection is active until the user hang-ups by pressing the hang-up button on the headset or the audio connection is closed with btHsClose. If the headset hang-up method is used, the audio connection is closed automatically when the user hang-up, from the headset and it is not necessary to use btHsClose. However, the call is not hung up automatically, and the program must do this manually with gsmHangup.

If the Ring parameter is FALSE, the audio connection will be opened without user notification and must be closed with btHsClose.

 

Use btHsConnected to get the connection status and btHsRingAccept or btHsRingReject to stop the ring asynchronously.

 

Input:

Ring : BOOL

When TRUE, the headset will play a ring tone until the user accepts or rejects the call or the number of RingCounts is reached.

 

RingCount : SINT

The number of rings to play before the function returns with a timeout.

 

Return: SINT

0

- Success. Ring accepted if Ring was TRUE.

-1

- Bluetooth library is not open.

-4

- Already connected to device.

-7

- Headset not connected.

-15

- Ring rejected.

-17

- Timeout.

 

Declaration:

FUNCTION btHsOpen : INT;
VAR_INPUT
  Ring     : BOOL;
  RingCount : SINT;
END_VAR;

 

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 btHsConnected() AND gsmOffHook() DO
     END_WHILE;
    // Hangup the call
     DebugMsg(message:="    Call finished");
    IF gsmOffHook() THEN gsmHangup(); END_IF;
  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;