Skip to content

Commit a44621d

Browse files
committed
enhanced usb reconnection
1 parent d5d238a commit a44621d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pio_workspace/src/power_main.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,19 @@ bool create_entities()
558558
return true;
559559
}
560560

561-
void reConnectUSB() {
562-
USB1_USBCMD = 0; // disconnect USB
563-
delay(50); // enough time for USB hubs/ports to detect disconnect
564-
USB1_USBCMD = 1;
561+
void disconnectUSB() {
562+
USB1_USBCMD = 0;
563+
}
564+
void connectUSB() {
565+
USB1_USBCMD = 1;
565566
}
566567

567568
void destroy_entities()
568569
{
570+
disconnectUSB();
571+
delay(25);
569572
digitalWrite(9, HIGH);
570-
reConnectUSB();
573+
571574
rmw_context_t * rmw_context = rcl_context_get_rmw_context(&support.context);
572575
(void) rmw_uros_set_context_entity_destroy_session_timeout(rmw_context, 0);
573576

@@ -578,7 +581,10 @@ void destroy_entities()
578581
rclc_executor_fini(&executor);
579582
rcl_node_fini(&node);
580583
rclc_support_fini(&support);
584+
585+
delay(25);
581586
digitalWrite(9, LOW);
587+
connectUSB();
582588
}
583589

584590
void power_setup() {

0 commit comments

Comments
 (0)