Skip to content

Commit fc7aabb

Browse files
committed
Support fractional seconds for delay
Allow power cycle delay to be fractional seconds, e.g. not only 2 sec, but also like 0.3 sec or 1.5 sec.
1 parent f80467f commit fc7aabb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

uhubctl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static char opt_vendor[16] = "";
200200
static char opt_location[32] = ""; /* Hub location a-b.c.d */
201201
static int opt_ports = ALL_HUB_PORTS; /* Bitmask of ports to operate on */
202202
static int opt_action = POWER_KEEP;
203-
static int opt_delay = 2;
203+
static double opt_delay = 2;
204204
static int opt_repeat = 1;
205205
static int opt_wait = 20; /* wait before repeating in ms */
206206
static int opt_exact = 0; /* exact location match - disable USB3 duality handling */
@@ -234,7 +234,7 @@ static int print_usage()
234234
"--ports, -p - ports to operate on [all hub ports].\n"
235235
"--loc, -l - limit hub by location [all smart hubs].\n"
236236
"--vendor, -n - limit hub by vendor id [%s] (partial ok).\n"
237-
"--delay, -d - delay for cycle action [%d sec].\n"
237+
"--delay, -d - delay for cycle action [%g sec].\n"
238238
"--repeat, -r - repeat power off count [%d] (some devices need it to turn off).\n"
239239
"--exact, -e - exact location (no USB3 duality handling).\n"
240240
"--reset, -R - reset hub after each power-on action, causing all devices to reassociate.\n"
@@ -796,7 +796,7 @@ int main(int argc, char *argv[])
796796
}
797797
break;
798798
case 'd':
799-
opt_delay = atoi(optarg);
799+
opt_delay = atof(optarg);
800800
break;
801801
case 'r':
802802
opt_repeat = atoi(optarg);
@@ -962,7 +962,7 @@ int main(int argc, char *argv[])
962962
libusb_close(devh);
963963
}
964964
if (k == 0 && opt_action == POWER_CYCLE)
965-
sleep_ms(opt_delay * 1000);
965+
sleep_ms((int)(opt_delay * 1000));
966966
}
967967
rc = 0;
968968
cleanup:

0 commit comments

Comments
 (0)