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

📄 main.c

📁 蓝牙鼠标的例程
💻 C
📖 第 1 页 / 共 3 页
字号:
        break;
        
        case CL_SM_AUTHENTICATE_CFM:
        {
            appHandleClSmAuthenticateConfirm(theApp, (CL_SM_AUTHENTICATE_CFM_T *)message);
        }
        break;
        
        case CL_SM_AUTHORISE_IND:
        {
            switch (state)
            {
                case appDiscoverable:
                case appDiscoverableConnecting:
                    appHandleClSmAuthoriseInd(theApp, (CL_SM_AUTHORISE_IND_T *)message);
                    break;
                default:
                    appRejectClSmAuthoriseInd(theApp, (CL_SM_AUTHORISE_IND_T *)message);
                    break;
            }
        }
        break;

        case CL_DM_CLOCK_OFFSET_CFM:
        {   
            switch (state)
            {
                case appCabledConnected:
                    appHandleClDmClockOffsetCfm(theApp, (CL_DM_CLOCK_OFFSET_CFM_T *)message);
                    break;
                default:
                    break;
            }
        }
        break;

        case CL_DM_MODE_CHANGE_EVENT:
        {   
            switch (state)
            {
                case appCabledConnected:
                    appHandleClDmModeChangeEvent(theApp, (CL_DM_MODE_CHANGE_EVENT_T *)message);
                    break;
                default:
                    break;
            }
        }
        break;

        case CL_SM_SECURITY_LEVEL_CFM:
        case CL_DM_WRITE_INQUIRY_ACCESS_CODE_CFM:
        break;        
        
        case MESSAGE_MORE_DATA:
        {
            switch (state)
            {
                case appDiscoverable:
                case appIdle:
                    appHandleDataDispose(theApp, (MessageMoreData *)message);
                    break;
                case appCabledDisconnected:
                    appSetState(theApp, appCabledConnecting);
                    break;
                default:
                    break;
            }            
        }
        break;
        
		/* HID library messages */            
    	case HID_INIT_CFM:
        {
        	switch (state)
            {
            	case appInitialising:
                	appHandleHidInitConfirm(theApp, (HID_INIT_CFM_T *)message);
                    break;
                default:
                	appHandleUnexpected(theApp, id);
                	break;
            }
        }
        break;
                    
        case HID_CONNECT_IND:
        {
			switch (state)
			{
				case appDiscoverable:
					appHandleHidConnectIndDiscoverable(theApp, (HID_CONNECT_IND_T *)message);
					break;
                default:
					appHandleHidConnectIndReject(theApp, (HID_CONNECT_IND_T *)message);
					break;
			}
        }
        break;
			       
        case HID_CONNECT_CFM:
        {
            switch (state)
            {
                case appDiscoverableConnecting:
                    appHandleHidConnectCfmDiscoverable(theApp, (HID_CONNECT_CFM_T *)message);
                    break;
                case appCabledConnecting:
    				appHandleHidConnectCfmCabled(theApp, (HID_CONNECT_CFM_T *)message);
                    break;
                default:
					appHandleUnexpected(theApp, id);
					break;
            }
        }
        break;
        
	    case HID_DISCONNECT_IND:
        {
            switch (state)
            {
	            case appCabledConnected:
                case appCabledDisconnecting:
    				appHandleHidDisconnectInd(theApp, (HID_DISCONNECT_IND_T *)message);
                    break;
                default:
					appHandleUnexpected(theApp, id);
					break;
            }
        }
        break;
        
        case HID_SET_PROTOCOL_IND:
        {
           	switch (state)
            {
                case appCabledConnected:
                    appHandleHidSetProtocolInd(theApp, (HID_SET_PROTOCOL_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;
        
        case HID_GET_PROTOCOL_IND:
        {
           	switch (state)
            {
                case appCabledConnected:
                    appHandleHidGetProtocolInd(theApp, (HID_GET_PROTOCOL_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;
        
        case HID_SET_IDLE_IND:
        {
        	switch (state)
            {
                case appCabledConnected:
                    appHandleHidSetIdleInd(theApp, (HID_SET_IDLE_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;
        
        case HID_GET_IDLE_IND:
        {
        	switch (state)
            {
                case appCabledConnected:
                    appHandleHidGetIdleInd(theApp, (HID_GET_IDLE_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;
        
        case HID_SET_REPORT_IND:
        case HID_DATA_IND:
        {
            switch (state)
            {
                case appCabledConnected:
                    appHandleHidSetReportInd(theApp, (HID_SET_REPORT_IND_T *)message, (id == HID_SET_REPORT_IND));
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break; 
            }
        }
        break;

        case HID_GET_REPORT_IND:
        {
            switch (state)
            {
                case appCabledConnected:
                    appHandleHidGetReportInd(theApp, (HID_GET_REPORT_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break; 
            }
        }
        break;

        case HID_CONTROL_IND:
        {
            switch (state)
            {
                case appCabledConnected:
                    appHandleHidControlInd(theApp, (HID_CONTROL_IND_T *)message);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break; 
            }
        }
        break;

        case APP_INTERNAL_IDLE_TIMEOUT_IND:
        {
            switch (state)
            {
                case appCabledConnected:
                    appHandleInternalIdleTimeoutInd(theApp);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;

        case APP_INTERNAL_DISCOVERABLE_TIMEOUT_IND:
        {
           switch (state)
            {
                case appDiscoverable:
                    appHandleInternalDiscoverableTimeoutInd(theApp);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }        }
        break;

        case APP_INTERNAL_UNPLUG_IND:
        {
			theApp->power_off_enter = FALSE;
            switch (state)
            {
                case appDiscoverableConnecting:
                case appCabledConnecting:
                case appCabledDisconnecting:
                    appHandleInternalUnplugIndDefer(theApp);
                    break;
                case appCabledConnected:
                    appHandleInternalUnplugIndConnected(theApp);
                    break;
                case appCabledDisconnected:
                    appHandleInternalUnplugIndDisconnected(theApp);                    
                    break;
                case appDiscoverable:
                case appIdle:
                    appHandleInternalUnplugIndDiscoverable(theApp);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;
            }
        }
        break;

        case APP_INTERNAL_UNPLUG_TIMEOUT_IND:
        {
            switch (state)
            {
                case appCabledConnected:
                    appHandleInternalUnplugTimeoutInd(theApp);
                    break;
                default:
                    appHandleUnexpected(theApp, id);
                    break;  
            }
        }
        break;

        case APP_INTERNAL_SHUTDOWN_IND:
        {
            switch (state)
            {
                case appDiscoverableConnecting:
                case appCabledConnecting:
                case appCabledDisconnecting:
                    appHandleInternalShutdownIndDefer(theApp);
                    break;
                case appCabledConnected:
                    appHandleInternalShutdownIndConnected(theApp);
                    break;
				case appIdle:
					appHandleInternalShutdownIndIdle(theApp);
					break;
                default:
                    appHandleInternalShutdownInd(theApp);
                    break;
            }                
        }
        break;

		case APP_INTERNAL_BUTTON_PRESSED_IND:
		{
            switch (state)
            {
				case appIdle:
			        MessageSend(&theApp->task, APP_INTERNAL_SHUTDOWN_IND, 0);
					break;
				
				default:
					theApp->power_off_enter = TRUE;
					break;
			}
		}
		break;

		case APP_INTERNAL_BUTTON_RELEASED_IND:
		{
			if (theApp->power_off_enter)
			{
				theApp->power_off_enter = FALSE;
		        MessageSend(&theApp->task, APP_INTERNAL_SHUTDOWN_IND, 0);
			}
		}
		break;
		default:
		{
			/* An unexpected message has arrived - must handle it */
            appHandleUnexpected(theApp, id);
		}
		break;
    }
}
        

int main(void)
{
    static appTaskData theApp;
        
    /* Set up task 1 handler */
    theApp.task.handler = app_handler;
        
    /* Set initial state */
    theApp.state = appInitialising;
	
	/* Initialise power button flag */
	theApp.power_off_enter = FALSE;

    /* Initialise PIO directions */
    PioSetDir(HID_MASK_OUTPUT_MASK | HID_MASK_INPUT_MASK, HID_MASK_OUTPUT_MASK);
        
    /* Initialise buttons */
    pioInit(&theApp.pioState, &theApp.task);
        
    /* Initialise Led */    
    appLedInit(&theApp.led);
    appLedUpdate(&theApp.led, 0, -1, 0);
    appLedSetPriority(&theApp.led, 0);   
        
    /* Init the Connection Manager */
   	ConnectionInitEx(&theApp.task, &app_msg_filter);

    /* Start the message scheduler loop */
   	MessageLoop();

    return 0;
}

⌨️ 快捷键说明

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