//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UpdateStatus(int32_t i32Port) { tRectangle sRect; uint8_t ui8DevClass, ui8DevProtocol; // // Calculate the box size based on the lPort value to update one of the // status boxes. The first and last boxes will draw slightly off screen // to make the status area have no borders on the sides and bottom. // sRect.i16XMin = DISPLAY_TEXT_BORDER_H + (BUTTON_WIDTH * i32Port); sRect.i16XMax = sRect.i16XMin + BUTTON_WIDTH; sRect.i16YMin = 240 - 10 - BUTTON_HEIGHT; sRect.i16YMax = sRect.i16YMin + BUTTON_HEIGHT; // // Slightly adjust the first box to draw it off screen properly. // if(i32Port == (NUM_HUB_STATUS - 1)) { sRect.i16XMax -= 2; } // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); if(g_psHubStatus[i32Port].bConnected) { ui8DevClass = USBHCDDevClass(g_psHubStatus[i32Port].ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol( g_psHubStatus[i32Port].ui32Instance, 0); if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&sRect, "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&sRect, "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&sRect, "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&sRect, "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "Unknown", true); } } else { // // Unknown device is currently connected. // UpdateStatusBox(&sRect, "No Device", false); } }
//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UIUpdateStatus(void) { uint8_t ui8DevClass, ui8DevProtocol; static const tRectangle psRect[4] = { { DISPLAY_TEXT_BORDER_H, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 124, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 124, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 184, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 184, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 244, 240 - 10 }, { DISPLAY_TEXT_BORDER_H + 244, 240 - 10 - BUTTON_HEIGHT, DISPLAY_TEXT_BORDER_H + 303, 240 - 10 }, }; // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Default the protocol to none so that non-HID devices do not update // the keyboard modifiers. // ui8DevProtocol = USB_HID_PROTOCOL_NONE; if(g_sStatus.bConnected) { ui8DevClass = USBHCDDevClass(g_sStatus.ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol(g_sStatus.ui32Instance, 0); if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&psRect[0], "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&psRect[0], "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "No Device", false); } if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { if(g_sStatus.ui32Modifiers & HID_KEYB_CAPS_LOCK) { UpdateStatusBox(&psRect[1], "CAPS", true); } else { UpdateStatusBox(&psRect[1], "caps", false); } if(g_sStatus.ui32Modifiers & HID_KEYB_SCROLL_LOCK) { UpdateStatusBox(&psRect[2], "SCROLL", true); } else { UpdateStatusBox(&psRect[2], "scroll", false); } if(g_sStatus.ui32Modifiers & HID_KEYB_NUM_LOCK) { UpdateStatusBox(&psRect[3], "NUM", true); } else { UpdateStatusBox(&psRect[3], "num", false); } } else { UpdateStatusBox(&psRect[1], "caps", false); UpdateStatusBox(&psRect[2], "scroll", false); UpdateStatusBox(&psRect[3], "num", false); } }
//***************************************************************************** // // This function updates the status area of the screen. It uses the current // state of the application to print the status bar. // //***************************************************************************** void UIUpdateStatus(void) { uint8_t ui8DevClass, ui8DevProtocol; static const char pcNoPos[] = "---,---"; static const tRectangle psRect[2] = { { DISPLAY_TEXT_BORDER_H, STATUS_MIN_Y, DISPLAY_TEXT_BORDER_H + STATUS_MIDDLE_X, STATUS_MIN_Y + BUTTON_HEIGHT }, { DISPLAY_TEXT_BORDER_H + STATUS_MIDDLE_X, STATUS_MIN_Y, BUTTON_MIN_X, STATUS_MIN_Y + BUTTON_HEIGHT }, }; char pcPos[8]; // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_psFontFixed6x8); // // Default the protocol to none. // ui8DevProtocol = USB_HID_PROTOCOL_NONE; if(g_sStatus.bConnected) { ui8DevClass = USBHCDDevClass(g_sStatus.ui32Instance, 0); ui8DevProtocol = USBHCDDevProtocol(g_sStatus.ui32Instance, 0); // // If the class has not yet been recognized then print out the new // class of device that has been connected. // if(g_bTypeUpdated == false) { // // Now the class has been updated so do not update it again. // g_bTypeUpdated = true; if(ui8DevClass == USB_CLASS_HID) { if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Mouse is currently connected. // UpdateStatusBox(&psRect[0], "Mouse", true); } else if(ui8DevProtocol == USB_HID_PROTOCOL_KEYB) { // // Keyboard is currently connected. // UpdateStatusBox(&psRect[0], "Keyboard", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } else if(ui8DevClass == USB_CLASS_MASS_STORAGE) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Mass Storage", true); } else if(ui8DevClass == USB_CLASS_HUB) { // // MSC device is currently connected. // UpdateStatusBox(&psRect[0], "Hub", true); } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "Unknown", true); } } } else { // // Unknown device is currently connected. // UpdateStatusBox(&psRect[0], "No Device", false); // // No device is present so allow the class to update when a new device // is connected. // g_bTypeUpdated = false; } if(ui8DevProtocol == USB_HID_PROTOCOL_MOUSE) { // // Update the current cursor position. // UpdateCursor(); usprintf(pcPos, "%3d,%3d", g_sCursor.i16XMin, g_sCursor.i16YMin); UpdateStatusBox(&psRect[1], pcPos, false); } else { UpdateStatusBox(&psRect[1], pcNoPos, false); } UpdateButtons(); }
//***************************************************************************** // // The following is the Main Application Thread. It will Initialize the // Bluetooth Stack and all used profiles. // //***************************************************************************** static void MainApp(void *pThreadParameter) { int iPressCount; int iTick; int iVolume; int iRetVal; tDeviceInfo sDeviceInfo; BTPS_Initialization_t sBTPSInitialization; // // Set the callback function the stack can use for printing to the // console. // #ifdef DEBUG_ENABLED sBTPSInitialization.MessageOutputCallback = MessageOutputCallback; #else sBTPSInitialization.MessageOutputCallback = NULL; #endif // // Initialize the Bluetooth stack, using no callback parameters (NULL). // iRetVal = InitializeBluetooth(BluetoothCallbackFunction, NULL, &sBTPSInitialization); // // Initialize the Graphics Module. // InitializeGraphics(ButtonPressCallback); // // Proceed with application if there was no Bluetooth init error. // if(!iRetVal) { // // Make the device Connectable and Discoverable and enabled Secured // Simple Pairing. // SetLocalDeviceMode(CONNECTABLE_MODE | DISCOVERABLE_MODE | PAIRABLE_SSP_MODE); // // Get information about our local device. // iRetVal = GetLocalDeviceInformation(&sDeviceInfo); if(!iRetVal) { // // Format the board address into a string, and display it on // the console. // BD_ADDRToStr(sDeviceInfo.ucBDAddr, g_cBoardAddress); Display(("Local BD_ADDR: %s\r\n", g_cBoardAddress)); // // Display additional info about the device to the console // Display(("HCI Version : %s\r\n", g_pcHCIVersionStrings[sDeviceInfo.ucHCIVersion])); Display(("Connectable : %s\r\n", ((sDeviceInfo.sMode & CONNECTABLE_MODE) ? "Yes" : "No"))); Display(("Discoverable : %s\r\n", ((sDeviceInfo.sMode & DISCOVERABLE_MODE) ? "Yes" : "No"))); if(sDeviceInfo.sMode & (PAIRABLE_NON_SSP_MODE | PAIRABLE_SSP_MODE)) { Display(("Pairable : Yes\r\n")); Display(("SSP Enabled : %s\r\n", ((sDeviceInfo.sMode & PAIRABLE_SSP_MODE) ? "Yes" : "No"))); } else { Display(("Pairable : No\r\n")); } // // Show message to user on the screen // UpdateStatusBox("Waiting for Connection..."); // // Bluetooth should be running now. Enter a forever loop to run // the user interface on the board screen display and process // button presses. // iTick = ONE_SEC_COUNT; iVolume = DEFAULT_POWERUP_VOLUME; iPressCount = 0; while(1) { // // Update the screen. // ProcessGraphics(); // // Wait 1/10 second. // BTPS_Delay(TENTH_SEC_COUNT); // // If one second has elapsed, toggle the LED // if(!(--iTick)) { iTick = ONE_SEC_COUNT; ToggleLED(LED_PIN); } // // Check to see if the User Switch was pressed. // if(UserSwitchPressed()) { // // Count the amount of time that the button has been // pressed. // iPressCount++; } // // Else the user switch is not pressed // else { // // If the button was just released, then adjust the volume. // Decrease the volume by 10% for each button press. At // zero, then reset it to 100%. // if(iPressCount) { iVolume = (iVolume == 0) ? 100 : iVolume - 10; // // Set the new volume, and display a message on the // console // SoundVolumeSet(iVolume); Display(("Press Count %d Volume %d\r\n", iPressCount, iVolume)); iPressCount = 0; } } } } } // // There was an error initializing Bluetooth // else { // // Print an error message to the console and show a message on // the screen // Display(("Bluetooth Failed to initialize: Error %d\r\n", iRetVal)); UpdateStatusBox("Failed to Initialize Bluetooth."); // // Enter a forever loop. Continue to update the screen, and rapidly // blink the LED as an indication of the error state. // while(1) { ProcessGraphics(); BTPS_Delay(500); ToggleLED(LED_PIN); } } }
//***************************************************************************** // // The following is the callback function that is registered with the // graphics module (during the InitializeGraphics() call). This function // is called by the Graphics module when a button press occurs. // //***************************************************************************** static void ButtonPressCallback(unsigned int ButtonPress) { // // Only process if the Audio Endpoint AND the Remote is // connected. // if(g_bAudioConnected && g_bRemoteConnected) { // // Both connected, process the Button press. // switch(ButtonPress) { case BUTTON_PRESS_PLAY: { Display(("Play Pressed\r\n")); // // Determine if we are currently playing or are // paused. // if(!g_bStreamStarted) { if(!SendRemoteControlCommand(rcPlay)) { UpdateStatusBox("Connected... Playing"); g_bStreamStarted = true; } } break; } case BUTTON_PRESS_PAUSE: { Display(("Pause Pressed\r\n")); // // Determine if we are currently playing or are // paused. // if(g_bStreamStarted) { if(!SendRemoteControlCommand(rcPause)) { UpdateStatusBox("Connected... Playing"); g_bStreamStarted = false; } } break; } case BUTTON_PRESS_NEXT: { Display(("Next Pressed\r\n")); SendRemoteControlCommand(rcNext); break; } case BUTTON_PRESS_BACK: { Display(("Back Pressed\r\n")); SendRemoteControlCommand(rcBack); break; } default: { // // Unknown/Unhandled button press. // break; } } } }
//***************************************************************************** // // The following function is called when various Bluetooth Events occur. The // function passes a Callback Event Data Structure and a Callback Parameter. // The Callback parameter is a user definable value that was passed to the // InitializeBluetooth function. For this application, this value is not used. // //***************************************************************************** static void BluetoothCallbackFunction(tCallbackEventData *pCallbackData, void *pCallbackParameter) { // // Verify that the parameters pass in appear valid. // if(pCallbackData) { // // Process each Callback Event. // switch(pCallbackData->sEvent) { // // Handle PIN code request // case cePinCodeRequest: { Display(("cePinCodeRequest\r\n")); PinCodeResponse(pCallbackData->ucRemoteDevice, 4, DEFAULT_PIN_CODE); break; } // // Handle completion of authentication // case ceAuthenticationComplete: { Display(("ceAuthenticationComplete\r\n")); break; } // // Handle failure of authentication // case ceAuthenticationFailure: { Display(("ceAuthenticationFailure\r\n")); break; } // // Handle opening of endpoint. Notify user of connection. // case ceAudioEndpointOpen: { Display(("ceAudioEndpointOpen\r\n")); // // Flag that we are now connected. // g_bAudioConnected = true; // // Flag that the Audio is not currently playing. // g_bStreamStarted = false; // // Set the Audio State to indicate that we need to prepare to // receive audio data. // UpdateStatusBox("Connected... Paused"); break; } // // Handle closing of endpoint. Notify user there is no more // connection. // case ceAudioEndpointClose: { Display(("ceAudioEndpointClose\r\n")); // // Flag that we are no longer connected. // g_bAudioConnected = false; // // Flag that the Audio is NOT currently playing. // g_bStreamStarted = false; // // Set the audio State back to Stopping. This will allow any // queued audio data to be consumed. // UpdateStatusBox("Waiting for Connection..."); break; } // // Handle start of audio stream. Notify user that a stream is // playing. // case ceAudioStreamStart: { Display(("ceAudioStreamStart\r\n")); // // Flag that the Audio is currently playing. // g_bStreamStarted = true; UpdateStatusBox("Connected... Playing"); break; } // // Handle suspension of audio stream. Notify user that the stream // is paused. // case ceAudioStreamSuspend: { Display(("ceAudioStreamSuspend\r\n")); // // Flag that the Audio is NOT currently playing. // g_bStreamStarted = false; UpdateStatusBox("Connected... Paused"); break; } // // Handle opening of control connection. // case ceRemoteControlConnectionOpen: { Display(("ceRemoteControlConnectionOpen\r\n")); // // Flag that the Remote is connected. // g_bRemoteConnected = true; break; } // // Handle closing of control connection. // case ceRemoteControlConnectionClose: { Display(("ceRemoteControlConnectionClose\r\n")); // // Flag that the Remote is no longer connected. // g_bRemoteConnected = false; break; } } } }