⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demobluecap.c

📁 在VC6.0上编译通过的蓝牙通信演示程序, COM1口控制.
💻 C
字号:
/*******************************************************************************
Copyright (C) Excelpoint System (Pte) Ltd. 2006

FILE: demoBlueCAP.c

DESCRIPTION: This file contains key handler and main menu
*******************************************************************************/

#include <stdio.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <crtdbg.h> 
#include "HBCP.h"
#include "demoBlueCAP.h"


enum
{
	SEND_DTMF,
	GET_LIST,
	SET_STORAGE,
	CONNECT_HSHF_BY_ADDR,
	DIAL_NUMBER,
	ENTER_PIN,

	SELECT_BC_FILE,

	ENTER_DFU,

	CONNECT_SPP_BY_ADDR,
	SEND_SPP_DATA,

	NONE
} STATUS;

static unsigned char demoStatus = NONE;
static unsigned char sParameter[20];
static unsigned char ucLength = 0;

/********************************************************************************
 * Function: init_demo
 * Description: init menu state and HBCP
 *
 ********************************************************************************/
void init_demo(void)
{
	demoStatus = NONE;

	Init_HBCP();
}

/********************************************************************************
 * Function: HandKey
 * Description: hanle user command
 *
 ********************************************************************************/
void HandKey(unsigned char ucKey)
{
	unsigned char usKey[2]={0, 0};

	usKey[0] = ucKey;
	usKey[1] = 0;

	if(demoStatus == NONE)
	{
		switch (ucKey)
		{
			case 'o': // O
				// Power On/Off
				HBCP_POWER_ON_OFF();
				PRINT("Power On/Off\n\n");			
				break;
				
			case 'p': // p			
				// Enter pairing mode
				HBCP_Enter_Pair(120);
				PRINT("Enter pairing mode\n\n");			
				break;
			
			case 'x': // x
				// Exit pairing mode
				HBCP_Exit_Pair();
				PRINT("Exit pairing mode\n\n");			
				break;
				
			case 'c': // c
				// Connect to AG
				HBCP_HSHF_Connect();
				PRINT("Connect to AG\n\n");			
				break;
			
			case 'd': // d
				// disconnect from AG
				HBCP_HSHF_Disconnect();
				PRINT("Disconnect from AG\n\n");			
				break;
				
			case 'a': // a
				// Answer the call
				HBCP_Call_Accept();
				PRINT("Accept call\n\n");			
				break;
			
			case 'r': // r
				// Reject the call
				HBCP_Call_Reject();
				PRINT("Reject call\n\n");			
				break;
				
			case 'e': // e
				// End the call
				HBCP_End_Call();
				PRINT("End call\n\n");			
				break;
				
			case 'v': // v
				HBCP_Dial_Voice();
				PRINT("Initiate voice dial\n\n");			
				break;

			case 'l': // l
				// Dial last
				HBCP_Dial_Last();
				PRINT("Dial last number\n\n");				
				break;
					
			case 'n': // n
				// Dial a number
				PRINT("\n\n---------Input number and press enter---------\n\n");			
				demoStatus = DIAL_NUMBER;
				ucLength = 0;			
				break;

			case 'j': // j
				// Transfer audio to AG
				HBCP_Trans_Call_to_AG();
				PRINT("Transfer call to AG\n\n");			
				break;
			
			case 'k': // k
				// Transfer audio to HF
				HBCP_Trans_Call_to_HF();
				PRINT("Transfer call to HF\n\n");			
				break;

			case 'h': // h
				// Sawp 2 call
				HBCP_Call_Swap();
				PRINT("Sawp 2 call\n\n");			
				break;
			
			case 'q': // q
				// Release act and accept other
				HBCP_Rel_Act_Acc_Wait();
				PRINT("Release act and accept other\n\n");			
				break;
			
			case 'w': // w
				// Release hold and reject waiting
				HBCP_Rel_Hold_Rej_Wait();
				PRINT("Release hold and reject waiting\n\n");			
				break;
				
			case 'y': // y
				// Add hold to conversation
				HBCP_Add_Hold();
				PRINT("Add hold to conversation\n\n");
				break;
				
			case 'N':/*sxg 20070105*/
				HBCP_Get_Connected_DEV_Name();
				PRINT("Get Connected Dev Name\n\n");
				break;	
			
			case '9': // 9	
				PRINT("\n\n---------Please Enter the PIN Code and press enter---------\n\n");
				demoStatus = ENTER_PIN;
				ucLength = 0;			
				break;
				
			case '1'://  1
				// Mute mic
				HBCP_Mute_Mic();
				PRINT("Mute mic\n\n");			
				break;
				
			case 'b':
				// Send DTMF
				PRINT("\n\n---------Select a DTMF code---------\n");
				PRINT("---------0-9 # * A-D---------\n\n");
				demoStatus = SEND_DTMF;
				ucLength = 0;
				break;
				
			case 's': // s
				// Volume up
				HBCP_Volume_Up();
				PRINT("Volume up\n\n");			
				break;
			
			case 't': // t
				// Volume down
				HBCP_Volume_Down();
				PRINT("Volume down\n\n");			
				break;
				
			case 'm':
				// set storage
				PRINT("\n\n-----------Select a storage mode---------------\n");
				PRINT("-----1: Miss call 2:Receive call 3: Dial last call--------\n\n");			
				demoStatus = SET_STORAGE;
				ucLength = 0;			
				break;

			case 'g':
				// Get call list
				PRINT("\n\n--------------Input an entry (0: all records)------\n");			
				demoStatus = GET_LIST;
				ucLength = 0;			
				break;
				
			case 'u': // u
				// Get Pair dev Name
				HBCP_Get_Paired_Dev_Name();
				PRINT("Get Pair dev Name\n\n");
				break;
				
			case 'z':
				PRINT("\n\n---------Select connect AG from paired list---------\n\n");
				demoStatus = CONNECT_HSHF_BY_ADDR;
				ucLength = 0;
				break;			

			case 'i': // i
				// Delete all paired devices
				HBCP_Delete_Pair();
				PRINT("Delete all paired devices\n\n"); 		
				break;

			case 'f': // f
				// Restore factory
				HBCP_Restore_Factory();
				PRINT("Restore factory\n\n");
				break;	
				
				/*sxg 20070103*/
			case 'S':
				HBCP_HSHF_Get_Status();
				PRINT("Get HSHF Status\n\n");
				break;

			case 'I':
				HBCP_Set_Inquiry(60);
				PRINT(" HSHF Search Device\n\n");
				ucLength = 0;
				break;				

			case '3': // 3
				// connect last av source
				HBCP_Connect_AV();
				PRINT("connect last av source\n\n");
				break;

			case '4': // 4
				// disconnect av
				HBCP_Disconnect_AV();
				PRINT("disconnect av\n\n");
				break;

			case '5': // 5
				// Play the previous track
				HBCP_Previous_Audio();
				PRINT("Play the previous track\n\n");
				break;

			case '6': // 6
				// Play the next track
				HBCP_Next_Audio();
				PRINT("Play the next track\n\n");
				break;

			case '7': // 7
				// Av Play/Pause
				HBCP_Play_Pause_Audio();
				PRINT("Av play/Pause\n\n");
				break;
				
			case '8': // 8
				// Av Stop
				HBCP_Stop_Audio();
				PRINT("Av Stop\n\n");
				break;
				
			case 'B': // B
				// Select vCard for exchange
				PRINT("\n\n------Input vCard file name and press Enter------\n");
				demoStatus = SELECT_BC_FILE;
				ucLength = 0;
				break;
				
			case 'U':
				// enter DFU mode
				PRINT("\n\n------press Enter to run into DFU mode, others give up------\n");
				demoStatus = ENTER_DFU;
				ucLength = 0;
				break;
				
			case 'C': // C
				// Connect Last used SPP
				HBCP_SPP_Connect();
				PRINT("Connect to SPP\n\n");			
				break;
			
			case 'D': // D
				// disconnect from SPP
				HBCP_SPP_Disconnect();
				PRINT("Disconnect from SPP\n\n");			
				break;
				
			case 'L':
				PRINT("\n\n---------Select connect spp from paired list---------\n\n");
				demoStatus = CONNECT_SPP_BY_ADDR;
				ucLength = 0;
				break;			

			case 'A': 	
				PRINT("\n\n---------Please Enter data to send and press enter---------\n\n");
				demoStatus = SEND_SPP_DATA;
				ucLength = 0;			
				break;

			case 27://'ESC'
				UartDrv_Stop();
				Close_Sync_Thread();
				exit(1);

			default:
				Menu();
				break;
		}
	}
	else
	{
		if(demoStatus == ENTER_DFU)
		{
			ucLength = 0;
			demoStatus = NONE;
			if(ucKey == 13) HBCP_Enter_DFU();
			else Menu();
		}
		else if(ucKey == 13)//'ENTER'
		{
			if(demoStatus == SEND_DTMF)
			{
				HBCP_Send_DTMF(sParameter[0]);
				PRINT("\n\n");
				PRINT("Send DTMF\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == GET_LIST)
			{
				HBCP_Get_CallList(ucLength, sParameter);
				PRINT("\n\n");
				PRINT("Get call list\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == SET_STORAGE)
			{
				HBCP_Set_storage(sParameter[0]);
				PRINT("\n\n");
				PRINT("Set Storage\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == CONNECT_HSHF_BY_ADDR)
			{
				HBCP_Connect_AG_By_Addr(sParameter[0]);
				PRINT("\n\n");
				PRINT("Connect to the selected AG\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == DIAL_NUMBER)
			{
				HBCP_Dial_Number(ucLength, sParameter);
				PRINT("\n\n");
				PRINT("Dial a number\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == ENTER_PIN)
			{
				HBCP_Set_Pin(ucLength, sParameter);
				PRINT("\n\n");
				PRINT("Set PIN\n\n");
				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == SELECT_BC_FILE)
			{
				PRINT("\n\n");
				HBCP_Select_vCard(sParameter);
				PRINT("\n\n");
				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == CONNECT_SPP_BY_ADDR)
			{
				HBCP_Connect_SPP_By_Addr(sParameter[0]);
				PRINT("\n\n");
				PRINT("Connect to the selected SPP\n\n");

				ucLength = 0;
				demoStatus = NONE;
			}
			else if(demoStatus == SEND_SPP_DATA)
			{
				PRINT("\n\n");
				HBCP_Spp_send_Data(ucLength, sParameter);
				PRINT("\n\n");
				ucLength = 0;
				demoStatus = NONE;
			}
		}
		else if((ucKey >= 32) && (ucKey < 127))
		{
			PRINT(usKey);
			sParameter[ucLength ++] = ucKey;
		}
		else if((ucKey == 8) && (ucLength != 0))
		{
			ucLength --;
		}
		else
		{
			Menu();
		}
	}
}

/********************************************************************************
 * Function: Menu
 * Description: Main menu
 *
 ********************************************************************************/
void Menu(void)
{
	system("cls");
	printf("\n\n  ------ BlueCap AV HSHF CVC OPP Ver 0.88 ------\n\n");

	printf("  Power On/Off              - o |\n");
	printf("  Enter pairing mode        - p | Exit pairing mode         - x\n");
	printf("  Delete paired info        - i | Set PIN Code              - 9\n");
	printf("  Restore factory           - f | Search Devices            - I\n");
	printf("  Get Pair dev name         - u | Connect by spec pair dev  - z\n");	
	printf("  Get Connected dev name    - N | Get HSHF Status           - S\n\n");
	
	printf("  Connect HSHF              - c | Disconnect HSHF           - d\n");
	printf("  Accept call               - a | Reject call               - r\n");
	printf("  End call                  - e | Voice dial                - v\n");
	printf("  Dial last                 - l | Dial a number             - n\n");
	printf("  Transfer Audio to AG      - j | Transfer Audio to HF      - k\n");
	printf("  Hold/Swap call            - h | Rel Act and Accept Other  - q\n");
	printf("  Rel Held or Rej waiting   - w | Add Hold Call             - y\n");
	printf("  Mute or unMute            - 1 | Send DTMF                 - b\n");
	printf("  Set storage               - m | Get call list             - g\n\n");
	
	printf("  Vol Up                    - s | Vol Down                  - t\n\n");

	printf("  connect last av source    - 3 | disconnect from av source - 4\n");
	printf("  AV Play previous track    - 5 | AV Play next track        - 6\n");
	printf("  AV play/Pause             - 7 | AV Stop                   - 8\n\n"); 

	printf("  Select vCard for exchange - B | Enter DFU mode            - U\n\n");

	printf("  Connect Last used SPP     - C | Disconnect SPP            - D\n");
	printf("  Connect SPP by pair index - L | Send data through SPP     - A\n\n");

	printf("  Exit                      - Esc\n\n");	
	
	ucLength = 0;
	demoStatus = NONE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -