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.
+77 −2
Diff settings

Always

Just for now

Viewing a subset of changes. View all

wip: static info struct exposed to sample app

  • Loading branch information...
harryhaaren committed Jun 5, 2017
commit 04fb58e10ab72bdd0963629e31cd9e62d762692f
View
@@ -17,6 +17,7 @@ struct ctlra_dev_connect_func_t {
uint32_t vid;
uint32_t pid;
ctlra_dev_connect_func connect;
struct ctlra_dev_info_t *info;
};
/* TODO: Cleanup this registration method to be in the .c files of each
@@ -33,6 +34,8 @@ CTLRA_DEVICE_DECL(ni_maschine_mikro_mk2);
CTLRA_DEVICE_DECL(ni_maschine_jam);
CTLRA_DEVICE_DECL(akai_apc);
CTLRA_DEVICE_INFO(ni_kontrol_z1);
static const struct ctlra_dev_connect_func_t devices[] = {
{0, 0, 0},
{0x17cc, 0x1400, CTLRA_DEVICE_FUNC(ni_kontrol_d2)},
@@ -206,6 +209,13 @@ void ctlra_dev_get_info(const struct ctlra_dev_t *dev,
info->get_name = dev->info.get_name;
}
int ctlra_dev_get_info_by_id(struct ctlra_dev_id_t *id,
struct ctlra_dev_info_t ** info)
{
//printf("%s: name %s\n", __func__, );
*info = &CTLRA_DEVICE_INFO_NAME(ni_kontrol_z1);
}
const char * ctlra_info_get_name(const struct ctlra_dev_info_t *info,
enum ctlra_event_type_t type,
uint32_t control_id)
View
@@ -123,7 +123,7 @@ struct ctlra_grid_info_t {
* represent a control such as a slider or dial, but also feedback only
* items such as an LED, or screen.
*/
struct ctlra_control_info_t {
struct ctlra_item_info_t {
char name[CTLRA_STR_MAX]; /* Human readable name of the item */
uint32_t x; /* location of item on X axis */
uint32_t y; /* location of item on Y axis */
@@ -132,6 +132,30 @@ struct ctlra_control_info_t {
/* TODO: figure out how to expose capabilities of item */
};
#define CTLRA_DEV_TYPE_INVALID 0
#define CTLRA_DEV_TYPE_USB_HID 1
#define CTLRA_DEV_TYPE_BLUETOOTH 2
#define CTLRA_DEV_TYPE_USB_MIDI 3
/** ID struct for a USB HID device */
struct ctlra_dev_usb_hid_t {
/** USB Vendor ID */
uint32_t vendor_id;
/** USB device ID */
uint32_t device_id;
/** Serial number from USB library (if available) */
uint64_t serial_number;
};
struct ctlra_dev_id_t {
/* integer representing the type of this device.
* Eg: CTLRA_DEV_TYPE_USB_HID */
uint32_t type;
union {
struct ctlra_dev_usb_hid_t usb_hid;
};
};
/** Struct that provides info about the controller. Passed to the
* application on probe().
*/
@@ -164,6 +188,15 @@ struct ctlra_dev_info_t {
* buttons by accessing the array by *ctlra_event_type_t*
* CTRLA_EVENT_BUTTON */
uint32_t control_count[CTLRA_EVENT_T_COUNT];
/** An array pointers to ctlra_item_info_t structures.
* The pointers can be used to look up information about each
* control that the device has.
*/
struct ctlra_item_info_t *control_info[CTLRA_EVENT_T_COUNT];
/* TODO: feedback/led only ctlra_item info */
struct ctlra_grid_info_t grid_info[CTLRA_NUM_GRIDS_MAX];
/** @internal function to get name from device. Application must
@@ -293,6 +326,17 @@ int32_t ctlra_dev_screen_get_data(struct ctlra_dev_t *dev,
void ctlra_dev_get_info(const struct ctlra_dev_t *dev,
struct ctlra_dev_info_t * info);
/** Get the info struct for a controller by an ID. Note that the controller
* hardware itself does not have to be present to retrieve this info. The
* expected utilization of this function is to allow virtual controllers be

This comment has been minimized.

@foolswood

foolswood Sep 18, 2017

Contributor

"virtual controllers to be"

@foolswood

foolswood Sep 18, 2017

Contributor

"virtual controllers to be"

This comment has been minimized.

@harryhaaren

harryhaaren Sep 18, 2017

Contributor

+1 yep

@harryhaaren

harryhaaren Sep 18, 2017

Contributor

+1 yep

* created for testing and hardware-less development.
* @retval 0 Success
* @retval -ENOTSUP This device ID does not support getting info.
*/
int ctlra_dev_get_info_by_id(struct ctlra_dev_id_t *id,
struct ctlra_dev_info_t ** info);
/** Get the human readable name for *control_id* from *dev*. The
* control id is passed in eg: event.button.id, or can be any of the
* DEVICE_NAME_CONTROLS enumeration. Ownership of the string *remains* in
@@ -284,7 +284,6 @@ ctlra_ni_kontrol_z1_connect(ctlra_event_func event_func,
snprintf(dev->base.info.device, sizeof(dev->base.info.device),
"%s", "Kontrol Z1");
dev->base.info.control_count[CTLRA_EVENT_BUTTON] = BUTTONS_SIZE;
dev->base.info.control_count[CTLRA_EVENT_SLIDER] = SLIDERS_SIZE;
dev->base.info.get_name = ni_kontrol_z1_control_get_name;
@@ -318,3 +317,15 @@ ctlra_ni_kontrol_z1_connect(ctlra_event_func event_func,
return 0;
}
struct ctlra_dev_info_t ctlra_ni_kontrol_z1_info = {
.vendor = "Native Instruments",
.device = "Kontrol Z1",
.vendor_id = NI_VENDOR,
.device_id = NI_KONTROL_Z1,
/*
.control_count[CTLRA_EVENT_T_COUNT] = {
},
*/
};
View
@@ -217,6 +217,11 @@ extern struct ctlra_dev_t * ctlra_ ## name ## _connect( \
void *userdata, void *future)
/* Macro returns the function name registered using above macro */
#define CTLRA_DEVICE_FUNC(name) ctlra_ ## name ## _connect
/* Macro to declare an extern info struct for a device */
#define CTLRA_DEVICE_INFO(name) \
extern struct ctlra_dev_info_t ctlra_ ## name ## _info;
/* Macro that returns the name of the info struct */
#define CTLRA_DEVICE_INFO_NAME(name) ctlra_ ## name ## _info
/* Helper function for dealing with wrapped encoders */
static inline int8_t ctlra_dev_encoder_wrap_16(uint8_t newer, uint8_t older)
View
@@ -140,6 +140,11 @@ int main(int argc, char **argv)
signal(SIGINT, sighndlr);
struct ctlra_dev_id_t id;
struct ctlra_dev_info_t *info;
int ret = ctlra_dev_get_info_by_id(&id, &info);
printf("static info %s\n", info->device);
struct ctlra_t *ctlra = ctlra_create(NULL);
int num_devs = ctlra_probe(ctlra, accept_dev_func, 0x0);
printf("connected devices %d\n", num_devs);
ProTip! Use n and p to navigate between commits in a pull request.