From 7011fe563b583d7940247a7a01265b7f8675fee8 Mon Sep 17 00:00:00 2001 From: px4dev Date: Tue, 12 Mar 2013 00:40:22 -0700 Subject: Move PWM rate configuration, etc. into a separate utility and out of the individual drivers. --- apps/drivers/px4io/px4io.cpp | 50 +++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'apps/drivers/px4io/px4io.cpp') diff --git a/apps/drivers/px4io/px4io.cpp b/apps/drivers/px4io/px4io.cpp index 803e74469..9854402f0 100644 --- a/apps/drivers/px4io/px4io.cpp +++ b/apps/drivers/px4io/px4io.cpp @@ -1501,6 +1501,26 @@ extern "C" __EXPORT int px4io_main(int argc, char *argv[]); namespace { +void +start(int argc, char *argv[]) +{ + if (g_dev != nullptr) + errx(1, "already loaded"); + + /* create the driver - it will set g_dev */ + (void)new PX4IO(); + + if (g_dev == nullptr) + errx(1, "driver alloc failed"); + + if (OK != g_dev->init()) { + delete g_dev; + errx(1, "driver init failed"); + } + + exit(0); +} + void test(void) { @@ -1595,34 +1615,8 @@ px4io_main(int argc, char *argv[]) if (argc < 2) goto out; - if (!strcmp(argv[1], "start")) { - - if (g_dev != nullptr) - errx(1, "already loaded"); - - /* create the driver - it will set g_dev */ - (void)new PX4IO(); - - if (g_dev == nullptr) - errx(1, "driver alloc failed"); - - if (OK != g_dev->init()) { - delete g_dev; - errx(1, "driver init failed"); - } - - /* look for the optional pwm update rate for the supported modes */ - if ((argc > 2) && (strcmp(argv[2], "-u") == 0 || strcmp(argv[2], "--update-rate") == 0)) { - if (argc > 2 + 1) { -#warning implement this - } else { - fprintf(stderr, "missing argument for pwm update rate (-u)\n"); - return 1; - } - } - - exit(0); - } + if (!strcmp(argv[1], "start")) + start(argc - 1, argv + 1); if (!strcmp(argv[1], "recovery")) { -- cgit v1.2.3