diff --git a/src/xrt/targets/CMakeLists.txt b/src/xrt/targets/CMakeLists.txt index 3d6b41184..ea2bc4c5f 100644 --- a/src/xrt/targets/CMakeLists.txt +++ b/src/xrt/targets/CMakeLists.txt @@ -38,4 +38,4 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(common) add_subdirectory(openxr) -add_subdirectory(prober) +add_subdirectory(cli) diff --git a/src/xrt/targets/prober/CMakeLists.txt b/src/xrt/targets/cli/CMakeLists.txt similarity index 87% rename from src/xrt/targets/prober/CMakeLists.txt rename to src/xrt/targets/cli/CMakeLists.txt index d0364bc8c..b3ebe501a 100644 --- a/src/xrt/targets/prober/CMakeLists.txt +++ b/src/xrt/targets/cli/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSL-1.0 ###### -# Create a test executable for prober functionality. +# Create a cli interface for Monado. include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../targets/common @@ -12,10 +12,12 @@ include_directories( ) set(SOURCE_FILES - main.c + cli_cmd_test.c + cli_common.h + cli_main.c + cli_prober.c ) -# depends on above generated files add_executable(prober ${SOURCE_FILES} $ @@ -26,7 +28,7 @@ add_executable(prober ) set_target_properties(prober PROPERTIES - OUTPUT_NAME prober + OUTPUT_NAME monado-cli PREFIX "" ) diff --git a/src/xrt/targets/cli/cli_cmd_test.c b/src/xrt/targets/cli/cli_cmd_test.c new file mode 100644 index 000000000..7db532edc --- /dev/null +++ b/src/xrt/targets/cli/cli_cmd_test.c @@ -0,0 +1,98 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Prints a list of found devices and tests opening some of them. + * @author Jakob Bornecrantz + */ + +#include +#include + +#include "xrt/xrt_prober.h" +#include "cli_common.h" + + +static int +do_exit(struct xrt_prober **xp_ptr, int ret) +{ + if (*xp_ptr != NULL) { + (*xp_ptr)->destroy(xp_ptr); + *xp_ptr = NULL; + } + + printf(" :: Exiting '%i'\n", ret); + + return ret; +} + +#define NUM_XDEVS 32 + +int +cli_cmd_test(int argc, const char **argv) +{ + struct xrt_device *xdevs[NUM_XDEVS] = {0}; + struct xrt_prober *xp = NULL; + int ret = 0; + + // Initialize the prober. + printf(" :: Creating prober!\n"); + + ret = xrt_prober_create(&xp); + if (ret != 0) { + return do_exit(&xp, 0); + } + + // Need to prime the prober with devices before dumping and listing. + printf(" :: Probing!\n"); + + ret = xp->probe(xp); + if (ret != 0) { + return do_exit(&xp, ret); + } + + // So the user can see what we found. + printf(" :: Dumping!\n"); + + ret = xp->dump(xp); + if (ret != 0) { + do_exit(&xp, ret); + } + + // Multiple devices can be found. + printf(" :: Selecting devices!\n"); + + ret = xp->select(xp, xdevs, NUM_XDEVS); + if (ret != 0) { + do_exit(&xp, ret); + } + if (xdevs[0] == NULL) { + printf("\tNo HMD found! :(\n"); + return do_exit(&xp, -1); + } + + for (size_t i = 0; i < NUM_XDEVS; i++) { + if (xdevs[i] == NULL) { + continue; + } + + printf("\tFound '%s'\n", xdevs[i]->name); + } + + // End of program + printf(" :: All ok, shutting down.\n"); + + for (size_t i = 0; i < NUM_XDEVS; i++) { + if (xdevs[i] == NULL) { + continue; + } + + printf("\tDestroying '%s'\n", xdevs[i]->name); + + xdevs[i]->destroy(xdevs[i]); + xdevs[i] = NULL; + } + + // Finally done + return do_exit(&xp, 0); +} diff --git a/src/xrt/targets/cli/cli_common.h b/src/xrt/targets/cli/cli_common.h new file mode 100644 index 000000000..3db326fb1 --- /dev/null +++ b/src/xrt/targets/cli/cli_common.h @@ -0,0 +1,13 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Common file for the CLI program. + * @author Jakob Bornecrantz + */ + +#pragma once + + +int +cli_cmd_test(int argc, const char **argv); diff --git a/src/xrt/targets/cli/cli_main.c b/src/xrt/targets/cli/cli_main.c new file mode 100644 index 000000000..9425711af --- /dev/null +++ b/src/xrt/targets/cli/cli_main.c @@ -0,0 +1,45 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief A cli program to configure and test Monado. + * @author Jakob Bornecrantz + */ + +#include +#include + +#include "cli_common.h" + + +#define P(...) fprintf(stderr, __VA_ARGS__) + +static int +cli_print_help(int argc, const char **argv) +{ + if (argc >= 2) { + fprintf(stderr, "Unknown command '%s'\n\n", argv[1]); + } + + P("Monado-CLI 0.0.1\n"); + P("Usage: %s command [options]\n", argv[0]); + P("\n"); + P("Commands:\n"); + P(" test - List found devices, for prober testing.\n"); + + return 1; +} + +int +main(int argc, const char **argv) +{ + if (argc <= 1) { + return cli_print_help(argc, argv); + } + + if (strcmp(argv[1], "test") == 0) { + return cli_cmd_test(argc, argv); + } else { + return cli_print_help(argc, argv); + } +} diff --git a/src/xrt/targets/cli/cli_prober.c b/src/xrt/targets/cli/cli_prober.c new file mode 100644 index 000000000..a659f66a0 --- /dev/null +++ b/src/xrt/targets/cli/cli_prober.c @@ -0,0 +1,45 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Small file to allow the prober to start. + * @author Jakob Bornecrantz + */ + +#include + +#include "target_lists.h" +#include "cli_common.h" + + +static int +ps3_eye_found(struct xrt_prober *xp, + struct xrt_prober_device **devices, + size_t index, + struct xrt_device **out_xdev) +{ + printf("Found PS3 Eye!\n"); + return 0; +} + +struct xrt_prober_entry quirks_list[] = { + {0x1415, 0x2000, ps3_eye_found, "PS3 Eye"}, + {0x0000, 0x0000, NULL, NULL}, // Terminate +}; + +struct xrt_prober_entry *entry_lists[] = { + quirks_list, target_entry_list, + NULL, // Terminate +}; + +struct xrt_prober_entry_lists list = { + entry_lists, + target_auto_list, + NULL, +}; + +int +xrt_prober_create(struct xrt_prober **out_xp) +{ + return xrt_prober_create_with_lists(out_xp, &list); +} diff --git a/src/xrt/targets/prober/main.c b/src/xrt/targets/prober/main.c deleted file mode 100644 index 6a91c3644..000000000 --- a/src/xrt/targets/prober/main.c +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2019, Collabora, Ltd. -// SPDX-License-Identifier: BSL-1.0 -/*! - * @file - * @brief A program to help test the probing code in Monado. - * @author Jakob Bornecrantz - */ - -#include -#include - -#include "target_lists.h" - - -static int -ps3_eye_found(struct xrt_prober *xp, - struct xrt_prober_device **devices, - size_t index, - struct xrt_device **out_xdev) -{ - printf("Found PS3 Eye!\n"); - return 0; -} - -struct xrt_prober_entry quirks_list[] = { - {0x1415, 0x2000, ps3_eye_found, "PS3 Eye"}, - {0x0000, 0x0000, NULL, NULL}, // Terminate -}; - -struct xrt_prober_entry *entry_lists[] = { - quirks_list, target_entry_list, - NULL, // Terminate -}; - -struct xrt_prober_entry_lists list = { - entry_lists, - target_auto_list, - NULL, -}; - -int -xrt_prober_create(struct xrt_prober **out_xp) -{ - return xrt_prober_create_with_lists(out_xp, &list); -} - -int -do_exit(struct xrt_prober **xp, int ret) -{ - if (*xp != NULL) { - (*xp)->destroy(xp); - } - - printf(" :: Exiting '%i'\n", ret); - return ret; -} - -#define NUM_XDEVS 32 - -int -main(int argc, const char **argv) -{ - struct xrt_device *xdevs[NUM_XDEVS] = {0}; - struct xrt_prober *p = NULL; - int ret = 0; - - printf(" :: Creating prober!\n"); - - ret = xrt_prober_create(&p); - if (ret != 0) { - return ret; - } - - printf(" :: Probing!\n"); - - ret = p->probe(p); - if (ret != 0) { - return do_exit(&p, ret); - } - - printf(" :: Dumping!\n"); - - ret = p->dump(p); - if (ret != 0) { - do_exit(&p, ret); - } - - printf(" :: Selecting device!\n"); - - ret = p->select(p, xdevs, NUM_XDEVS); - if (ret != 0) { - do_exit(&p, ret); - } - if (xdevs[0] == NULL) { - printf("\tNo HMD found! :(\n"); - return do_exit(&p, -1); - } - - - for (size_t i = 0; i < NUM_XDEVS; i++) { - if (xdevs[i] == NULL) { - continue; - } - - printf("\tFound '%s'\n", xdevs[i]->name); - } - - // End of program - printf(" :: All ok, shutting down.\n"); - - for (size_t i = 0; i < NUM_XDEVS; i++) { - if (xdevs[i] == NULL) { - continue; - } - - printf("\tDestroying '%s'\n", xdevs[i]->name); - - xdevs[i]->destroy(xdevs[i]); - xdevs[i] = NULL; - } - - // Finally done - return do_exit(&p, 0); -}