Added new Relay Controller Board project (thanks to OBinou).
[pub/USBasp.git] / Demos / Host / Incomplete / BluetoothHost / Lib / BluetoothHCICommands.c
index b4720e5..4870fff 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
@@ -72,7 +72,6 @@ static bool Bluetooth_GetNextHCIEventHeader(void)
        }\r
          \r
        Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));\r
        }\r
          \r
        Pipe_Read_Stream_LE(&HCIEventHeader, sizeof(HCIEventHeader));\r
-         \r
        Pipe_Freeze();\r
 \r
        return true;\r
        Pipe_Freeze();\r
 \r
        return true;\r
@@ -81,11 +80,14 @@ static bool Bluetooth_GetNextHCIEventHeader(void)
 static void Bluetooth_DiscardRemainingHCIEventParameters(void)\r
 {\r
        Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);\r
 static void Bluetooth_DiscardRemainingHCIEventParameters(void)\r
 {\r
        Pipe_SelectPipe(BLUETOOTH_EVENTS_PIPE);\r
-       \r
        Pipe_Unfreeze();\r
        Pipe_Unfreeze();\r
+\r
        Pipe_Discard_Stream(HCIEventHeader.ParameterLength);\r
        Pipe_ClearIN();\r
        Pipe_Discard_Stream(HCIEventHeader.ParameterLength);\r
        Pipe_ClearIN();\r
+\r
        Pipe_Freeze();\r
        Pipe_Freeze();\r
+       \r
+       HCIEventHeader.ParameterLength = 0;\r
 }\r
 \r
 void Bluetooth_ProcessHCICommands(void)\r
 }\r
 \r
 void Bluetooth_ProcessHCICommands(void)\r
@@ -329,6 +331,10 @@ void Bluetooth_ProcessHCICommands(void)
                                                         \r
                                        Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;\r
                                }\r
                                                         \r
                                        Bluetooth_HCIProcessingState = Bluetooth_Conn_SendPINCode;\r
                                }\r
+                               else if (HCIEventHeader.EventCode == EVENT_COMMAND_COMPLETE)\r
+                               {\r
+                                       BT_DEBUG("(HCI) >> Command Complete", NULL);\r
+                               }\r
                                \r
                                BT_DEBUG("(HCI) -- Unread Event Param Length: %d", HCIEventHeader.ParameterLength);\r
 \r
                                \r
                                BT_DEBUG("(HCI) -- Unread Event Param Length: %d", HCIEventHeader.ParameterLength);\r
 \r
@@ -393,17 +399,6 @@ void Bluetooth_ProcessHCICommands(void)
                               sizeof(Bluetooth_DeviceConfiguration.PINCode));\r
                        \r
                        Bluetooth_SendHCICommand(&PINCodeRequestParams, sizeof(PINCodeRequestParams));\r
                               sizeof(Bluetooth_DeviceConfiguration.PINCode));\r
                        \r
                        Bluetooth_SendHCICommand(&PINCodeRequestParams, sizeof(PINCodeRequestParams));\r
-               \r
-                       do\r
-                       {\r
-                               while (!(Bluetooth_GetNextHCIEventHeader()))\r
-                               {                               \r
-                                       if (USB_HostState == HOST_STATE_Unattached)\r
-                                         return;\r
-                               }\r
-\r
-                               Bluetooth_DiscardRemainingHCIEventParameters();\r
-                       } while (HCIEventHeader.EventCode != EVENT_COMMAND_COMPLETE);\r
 \r
                        Bluetooth_HCIProcessingState     = Bluetooth_PrepareToProcessEvents;\r
                        break;\r
 \r
                        Bluetooth_HCIProcessingState     = Bluetooth_PrepareToProcessEvents;\r
                        break;\r