New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual device #41

Merged
merged 122 commits into from Oct 2, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+50 −99
Diff settings

Always

Just for now

Viewing a subset of changes. View all

virtual: device probe working, ui clickable

For #6, but events are not yet propgated from the UI
back into the application. This requires callbacks in the
avtka code to be implemented, and events to be sent via
the callback, utilizing the info of the PMD to identify
what type of event.

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
  • Loading branch information...
harryhaaren committed Aug 22, 2017
commit d14d14475e7a5849cc9d704e6f0a4972edbf21ef
View
@@ -113,10 +113,11 @@ struct ctlra_dev_t *ctlra_dev_connect(struct ctlra_t *ctlra,
int32_t
ctlra_dev_virtualize(struct ctlra_t *c, struct ctlra_dev_info_t *info)
{
/* call into AVTKA and virtualize the device, passing info through
* the future (void *) to the AVTKA backend. */
CTLRA_INFO(c, "virtualizing dev with info %p\n", info);
/* call into AVTKA and virtualize the device */
struct ctlra_dev_t *dev =
ctlra_dev_connect(c, ctlra_avtka_connect, 0x0, 0x0, 0x0);
struct ctlra_dev_t *dev = ctlra_dev_connect(c, ctlra_avtka_connect,
0x0, 0x0, info);
if(!dev)
CTLRA_WARN(c, "avtka dev returned %p\n", dev);
View
@@ -41,29 +41,12 @@
#define PUGL_PARENT 0x0
static const char *
avtka_control_get_name(enum ctlra_event_type_t type, uint32_t control)
{
if(type == CTLRA_EVENT_BUTTON && control == 0)
return "Test Button";
if(type == CTLRA_EVENT_SLIDER && control == 0)
return "Test Slider";
return 0;
}
#define CONTROLS_SIZE 10
#define AVTK 0x01
#define VIRTUAL 0x01
/* Represents the the virtual AVTK UI */
struct avtka_t {
/* base handles usb i/o etc */
struct ctlra_dev_t base;
/* represents the Avtka UI */
struct avtka_t *a;
/* current value of each controller is stored here */
float hw_values[CONTROLS_SIZE];
};
static uint32_t avtka_poll(struct ctlra_dev_t *base)
@@ -102,24 +85,24 @@ avtka_disconnect(struct ctlra_dev_t *base)
struct ctlra_dev_t *
ctlra_avtka_connect(ctlra_event_func event_func, void *userdata, void *future)
{
printf("%s\n", __func__);
(void)future;
struct avtka_t *dev = (struct avtka_t *)calloc(1, sizeof(struct avtka_t));
if(!dev)
goto fail;
struct ctlra_dev_info_t *info = future;
/* reuse the existing info from the device backend, amended as
* appropriate below */
dev->base.info = *info;
snprintf(dev->base.info.vendor, sizeof(dev->base.info.vendor),
"%s", "OpenAV Avtka");
"%s", "OpenAV Virtual Ctlra");
snprintf(dev->base.info.device, sizeof(dev->base.info.device),
"%s", "Virtual Ctlra");
dev->base.info.vendor_id = AVTK;
dev->base.info.device_id = VIRTUAL;
"%s %s", info->vendor, info->device);
dev->base.poll = avtka_poll;
dev->base.disconnect = avtka_disconnect;
dev->base.light_set = avtka_light_set;
dev->base.info.get_name = avtka_control_get_name;
dev->base.event_func = event_func;
dev->base.event_func_userdata = userdata;
@@ -130,26 +113,50 @@ ctlra_avtka_connect(ctlra_event_func event_func, void *userdata, void *future)
.h = 240
};
char name[64];
snprintf(name, sizeof(name), "%s:%s", dev->base.info.vendor,
snprintf(name, sizeof(name), "%s - %s", dev->base.info.vendor,
dev->base.info.device);
struct avtka_t *a = avtka_create(name, &opts);
struct avtka_item_opts_t item = {
.name = "Dial 1",
.x = 10, .y = 10, .w = 50, .h = 50,
.draw = AVTKA_DRAW_DIAL,
.interact = AVTKA_INTERACT_CLICK,
};
uint32_t button1 = avtka_item_create(a, &item);
item.x = 70;
snprintf(item.name, sizeof(item.name), "Dial 2");
uint32_t button2 = avtka_item_create(a, &item);
printf("items created %d and %d\n", button1, button2);
for(int i = 0; i < info->control_count[CTLRA_EVENT_BUTTON]; i++) {
struct ctlra_item_info_t *item =
&info->control_info[CTLRA_EVENT_BUTTON][i];
struct avtka_item_opts_t ai = {
//.name = name,
.x = item->x,
.y = item->y,
.w = item->w,
.h = item->h,
.draw = AVTKA_DRAW_BUTTON,
.interact = AVTKA_INTERACT_CLICK,
};
avtka_item_create(a, &ai);
}
for(int i = 0; i < info->control_count[CTLRA_EVENT_SLIDER]; i++) {
struct ctlra_item_info_t *item =
&info->control_info[CTLRA_EVENT_SLIDER][i];
const char *name = ctlra_info_get_name(info,
CTLRA_EVENT_SLIDER, i);
struct avtka_item_opts_t ai = {
.x = item->x,
.y = item->y,
.w = item->w,
.h = item->h,
.interact = AVTKA_INTERACT_CLICK,
};
ai.draw = (item->flags & CTLRA_ITEM_FADER) ?
AVTKA_DRAW_SLIDER : AVTKA_DRAW_DIAL;
snprintf(ai.name, sizeof(ai.name), "%s", name);
avtka_item_create(a, &ai);
}
/* pass in back-pointer to ctlra_dev_t class for sending events */
dev->a = a;
return (struct ctlra_dev_t *)dev;
fail:
free(dev);
@@ -136,71 +136,14 @@ int main(int argc, char **argv)
signal(SIGINT, sighndlr);
#if 0
struct avtka_opts_t opts = {
.w = info->size_x,
.h = info->size_y,
};
char dev_name[64];
snprintf(dev_name, sizeof(dev_name), "Ctlra VDev: %s %s",
info->vendor, info->device);
struct avtka_t *a = avtka_create(dev_name, &opts);
if(info != NULL) {
printf("static info %s %s\n buttons = %d\n sliders %d\n",
info->vendor, info->device,
info->control_count[CTLRA_EVENT_BUTTON],
info->control_count[CTLRA_EVENT_SLIDER]);
for(int i = 0; i < info->control_count[CTLRA_EVENT_BUTTON]; i++) {
struct ctlra_item_info_t *item =
&info->control_info[CTLRA_EVENT_BUTTON][i];
struct avtka_item_opts_t ai = {
//.name = name,
.x = item->x,
.y = item->y,
.w = item->w,
.h = item->h,
.draw = AVTKA_DRAW_BUTTON,
};
avtka_item_create(a, &ai);
}
printf("sliders\n");
for(int i = 0; i < info->control_count[CTLRA_EVENT_SLIDER]; i++) {
struct ctlra_item_info_t *item =
&info->control_info[CTLRA_EVENT_SLIDER][i];
const char *name = ctlra_info_get_name(info,
CTLRA_EVENT_SLIDER, i);
printf("%d, %s: %d %d\t%d %d\n", i, name,
item->x, item->y,
item->w, item->h);
struct avtka_item_opts_t ai = {
.x = item->x,
.y = item->y,
.w = item->w,
.h = item->h,
};
ai.draw = (item->flags & CTLRA_ITEM_FADER) ?
AVTKA_DRAW_SLIDER : AVTKA_DRAW_DIAL;
snprintf(ai.name, sizeof(ai.name), "%s", name);
avtka_item_create(a, &ai);
}
}
#endif
struct ctlra_t *ctlra = ctlra_create(NULL);
int num_devs = ctlra_probe(ctlra, accept_dev_func, 0x0);
printf("connected devices %d\n", num_devs);
/* add a virtualized device */
struct ctlra_dev_id_t id;
id.type = CTLRA_DEV_TYPE_USB_HID;
struct ctlra_dev_info_t *info = ctlra_dev_get_info_by_id(&id);
/* add a virtualized device */
ctlra_dev_virtualize(ctlra, info);
int i = 0;
ProTip! Use n and p to navigate between commits in a pull request.