btHsRingReject (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


This function is used to make the headset stop ringing and let btHsOpen return as if the user had rejected the ring. When btHsOpen is called with ring activated, it will wait for the user to accept or reject the call or for the timeout to occur. Sometimes the application needs to answer or reject the call instead of waiting for the headset - for example if the call was hung up by the caller. Please also see the btHsRingAccept for the accept function.

 

Input:

None

 

Return: INT

0

- Success.

-1

- Bluetooth library is not open.

-5

- Headset not ringing.

-7

- Headset not connected.

-17

- Timeout.

 

Declaration:

FUNCTION btHsRingReject : INT;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  DIP1 : BOOL;
  DIP2 : BOOL;
END_VAR;
 
THREAD_BLOCK GSM_Thread;
  VAR
     incomingCall  : gsmIncomingCall;
     rc            : INT;
  END_VAR;
  // Turn on power to the GSM module, use no pin code
  gsmPower(power := TRUE);
  WHILE TRUE DO
     incomingCall();
     
     // 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");
          btHsClose();
          IF gsmOffHook() THEN gsmHangup(); END_IF;
        ELSIF rc = -15 THEN
           // The user rejected the call. Hangup the phone
           DebugMsg(message:="    Call Rejected");
          gsmHangup();
        ELSE
          // The user didn't answer. Hangup the phone
           DebugMsg(message:="    Call Timeout");
          gsmHangup();
        END_IF;
    END_IF;
  END_WHILE;
END_THREAD_BLOCK;
 
PROGRAM test;
VAR
  ConID_Headset : SINT;
  btCon_Headset : btConnection;
END_VAR;
 
// 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();
 
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;
 
IF DIP1 THEN
  btHsRingAccept();
END_IF;
 
IF DIP2 THEN
  btHsRingReject();
END_IF;
 
  ...
 
END;
END_PROGRAM;