Add explicit guards to all device mode tasks to ensure the device is connected and...
[pub/USBasp.git] / Demos / Device / LowLevel / DualCDC / DualCDC.c
index 1031068..862945e 100644 (file)
@@ -229,6 +229,10 @@ void CDC1_Task(void)
        uint8_t     JoyStatus_LCL   = Joystick_GetStatus();\r
        static bool ActionSent      = false;\r
 \r
+       /* Device must be connected and configured for the task to run */\r
+       if (!(USB_IsConnected) || !(USB_ConfigurationNumber))\r
+         return;\r
+\r
        char* JoystickStrings[] =\r
                {\r
                        "Joystick Up\r\n",\r
@@ -288,6 +292,10 @@ void CDC1_Task(void)
  */\r
 void CDC2_Task(void)\r
 {\r
+       /* Device must be connected and configured for the task to run */\r
+       if (!(USB_IsConnected) || !(USB_ConfigurationNumber))\r
+         return;\r
+\r
        /* Select the Serial Rx Endpoint */\r
        Endpoint_SelectEndpoint(CDC2_RX_EPNUM);\r
        \r