Add explicit guards to all device mode tasks to ensure the device is connected and...
[pub/USBasp.git] / Demos / Device / LowLevel / Keyboard / Keyboard.c
index 2527148..9950484 100644 (file)
@@ -377,13 +377,13 @@ void ReceiveNextReport(void)
 /** Function to manage HID report generation and transmission to the host, when in report mode. */\r
 void HID_Task(void)\r
 {\r
-       /* Check if the USB system is connected to a host */\r
-       if (USB_IsConnected)\r
-       {\r
-               /* Send the next keypress report to the host */\r
-               SendNextReport();\r
+       /* Device must be connected and configured for the task to run */\r
+       if (!(USB_IsConnected) || !(USB_ConfigurationNumber))\r
+         return;\r
+         \r
+       /* Send the next keypress report to the host */\r
+       SendNextReport();\r
                \r
-               /* Process the LED report sent from the host */\r
-               ReceiveNextReport();\r
-       }\r
+       /* Process the LED report sent from the host */\r
+       ReceiveNextReport();\r
 }\r