Commit 249b9a03 authored by Jakob Bornecrantz's avatar Jakob Bornecrantz
Browse files

t/cli: Turn prober command into a cli interface for Monado

parent 699bb8d5
......@@ -38,4 +38,4 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(common)
add_subdirectory(openxr)
add_subdirectory(prober)
add_subdirectory(cli)
......@@ -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}
$<TARGET_OBJECTS:aux_os>
......@@ -26,7 +28,7 @@ add_executable(prober
)
set_target_properties(prober PROPERTIES
OUTPUT_NAME prober
OUTPUT_NAME monado-cli
PREFIX ""
)
......
......@@ -2,101 +2,75 @@
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief A program to help test the probing code in Monado.
* @brief Prints a list of found devices and tests opening some of them.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#include "target_lists.h"
#include "xrt/xrt_prober.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)
do_exit(struct xrt_prober **xp_ptr, int ret)
{
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);
if (*xp_ptr != NULL) {
(*xp_ptr)->destroy(xp_ptr);
*xp_ptr = NULL;
}
printf(" :: Exiting '%i'\n", ret);
return ret;
}
#define NUM_XDEVS 32
int
main(int argc, const char **argv)
cli_cmd_test(int argc, const char **argv)
{
struct xrt_device *xdevs[NUM_XDEVS] = {0};
struct xrt_prober *p = NULL;
struct xrt_prober *xp = NULL;
int ret = 0;
// Initialize the prober.
printf(" :: Creating prober!\n");
ret = xrt_prober_create(&p);
ret = xrt_prober_create(&xp);
if (ret != 0) {
return ret;
return do_exit(&xp, 0);
}
// Need to prime the prober with devices before dumping and listing.
printf(" :: Probing!\n");
ret = p->probe(p);
ret = xp->probe(xp);
if (ret != 0) {
return do_exit(&p, ret);
return do_exit(&xp, ret);
}
// So the user can see what we found.
printf(" :: Dumping!\n");
ret = p->dump(p);
ret = xp->dump(xp);
if (ret != 0) {
do_exit(&p, ret);
do_exit(&xp, ret);
}
printf(" :: Selecting device!\n");
// Multiple devices can be found.
printf(" :: Selecting devices!\n");
ret = p->select(p, xdevs, NUM_XDEVS);
ret = xp->select(xp, xdevs, NUM_XDEVS);
if (ret != 0) {
do_exit(&p, ret);
do_exit(&xp, ret);
}
if (xdevs[0] == NULL) {
printf("\tNo HMD found! :(\n");
return do_exit(&p, -1);
return do_exit(&xp, -1);
}
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
......@@ -120,5 +94,5 @@ main(int argc, const char **argv)
}
// Finally done
return do_exit(&p, 0);
return do_exit(&xp, 0);
}
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Common file for the CLI program.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#pragma once
int
cli_cmd_test(int argc, const char **argv);
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief A cli program to configure and test Monado.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#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);
}
}
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Small file to allow the prober to start.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <stdio.h>
#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);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment