<commit_before>// usleep() hack
#define _BSD_SOURCE

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>

#include "ctlra.h"
#include "global.h"

static volatile uint32_t done;

void sighndlr(int signal)
{
	done = 1;
}

struct ctlra_supported_t {
	uint32_t vendor_id;
	uint32_t device_id;
	ctlra_event_func ctlra_poll;
	ctlra_feedback_func update_state;
};

static const struct ctlra_supported_t ctlra_supported[] = {
	{0x17cc, 0x1400, kontrol_d2_func, kontrol_d2_update_state},
	{0x17cc, 0x1210, kontrol_z1_func, kontrol_z1_update_state},
	//{0x17cc, 0x12 TODO,kontrol_f1_func, kontrol_f1_update_state},
	{0x17cc, 0x1220, kontrol_x1_func, kontrol_x1_update_state},
	//{0x17cc, 0x12, mm_func, mm_update_state},
};
#define CTLRA_SUPPORTED_SIZE (sizeof(ctlra_supported) /\
			     sizeof(ctlra_supported[0]))

int accept_dev_func(const struct ctlra_dev_info_t *info,
		    ctlra_event_func *event_func,
		    ctlra_feedback_func *feedback_func,
		    void **userdata_for_event_func,
		    void *userdata)
{
	/* Application *MUST* handle each device that it knows - or provide
	 * a generic function for handling events and writing feedback. */
	for(unsigned i = 0; i < CTLRA_SUPPORTED_SIZE; i++) {
		if(info->vendor_id == ctlra_supported[i].vendor_id &&
		   info->device_id == ctlra_supported[i].device_id) {
			*event_func = ctlra_supported[i].ctlra_poll;
			*feedback_func = ctlra_supported[i].update_state;
			*userdata_for_event_func = userdata;
			printf("App: accepting %s %s (%x:%x)\n",
			       info->vendor, info->device,
			       info->vendor_id, info->device_id);
			/* Accept */
			return 1;
		}
	}
	printf("App: Rejecting controller %s %s (%x:%x), no App for this device\n",
	       info->vendor, info->device,
	       info->vendor_id, info->device_id);
	/* Deny */
	return 0;
}

int main(int argc, char** argv)
{
	signal(SIGINT, sighndlr);

	struct dummy_data dummy;
	memset(&dummy, 0, sizeof(struct dummy_data));
	void *future = 0x0;

	if(argc > 1) {
		dummy.print_events = 1;
	}

	struct ctlra_t *ctlra = ctlra_create(NULL);


	int num_devs = ctlra_probe(ctlra, accept_dev_func, &dummy);
	printf("probe num_devs %d\n", num_devs);

	audio_init(&dummy);

	while(!done) {
		ctlra_idle_iter(ctlra);
		usleep(100);
	}

	audio_exit();

	ctlra_exit(ctlra);

	return 0;

#if 0
	struct ctlra_list_t ctlra_list;
	TAILQ_INIT(&ctlra_list);
	for(uint32_t i = 0; i < CTLRA_SUPPORTED_SIZE; i++) {
		const struct ctlra_supported_t* sup = &ctlra_supported[i];
		struct ctlra_dev_t* ctlra_dev = ctlra_dev_connect(ctlra,
							      sup->dev_id,
		                          sup->ctlra_poll,
		                          &dummy,
		                          future);
		if(ctlra_dev) {
			struct ctlra_t *dev = calloc(1, sizeof(struct ctlra_t));
			if(!dev) return -1;
			dev->ctlra = ctlra_dev;
			dev->update_state = sup->update_state;

			struct ctlra_dev_info_t info;
			ctlra_dev_get_info(dev->ctlra, &info);
			printf("Vegas: connected to ctlra_dev %s %s\n",
			       info.vendor, info.device);

			TAILQ_INSERT_TAIL(&ctlra_list, dev, list);
		}
	}

	audio_init(&dummy);

	struct ctlra_t* dev;
	dummy.revision = 0;
	uint64_t controller_revision = 0;
	while(!done) {
		/* Poll all controllers
		TAILQ_FOREACH(dev, &ctlra_list, list) {
			ctlra_dev_poll(dev->ctlra);
		}
		*/
		ctlra_idle_iter(ctlra);

		/* If revision of state is new, update state of controllers */
		if (dummy.revision != controller_revision) {
			TAILQ_FOREACH(dev, &ctlra_list, list) {
				dev->update_state(dev->ctlra, &dummy);
			}
			controller_revision = dummy.revision;
		}

		usleep(100);
	}

	audio_init(&dummy);

	audio_exit();

	ctlra_exit(ctlra);

	return 0;
#endif

}<commit_msg>vegas: cleanup dead code<commit_after>// usleep() hack
#define _BSD_SOURCE

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>

#include "ctlra.h"
#include "global.h"

static volatile uint32_t done;

void sighndlr(int signal)
{
	done = 1;
}

struct ctlra_supported_t {
	uint32_t vendor_id;
	uint32_t device_id;
	ctlra_event_func ctlra_poll;
	ctlra_feedback_func update_state;
};

static const struct ctlra_supported_t ctlra_supported[] = {
	{0x17cc, 0x1400, kontrol_d2_func, kontrol_d2_update_state},
	{0x17cc, 0x1210, kontrol_z1_func, kontrol_z1_update_state},
	//{0x17cc, 0x12 TODO,kontrol_f1_func, kontrol_f1_update_state},
	{0x17cc, 0x1220, kontrol_x1_func, kontrol_x1_update_state},
	//{0x17cc, 0x12, mm_func, mm_update_state},
};
#define CTLRA_SUPPORTED_SIZE (sizeof(ctlra_supported) /\
			     sizeof(ctlra_supported[0]))

int accept_dev_func(const struct ctlra_dev_info_t *info,
		    ctlra_event_func *event_func,
		    ctlra_feedback_func *feedback_func,
		    void **userdata_for_event_func,
		    void *userdata)
{
	/* Application *MUST* handle each device that it knows - or provide
	 * a generic function for handling events and writing feedback. */
	for(unsigned i = 0; i < CTLRA_SUPPORTED_SIZE; i++) {
		if(info->vendor_id == ctlra_supported[i].vendor_id &&
		   info->device_id == ctlra_supported[i].device_id) {
			*event_func = ctlra_supported[i].ctlra_poll;
			*feedback_func = ctlra_supported[i].update_state;
			*userdata_for_event_func = userdata;
			printf("App: accepting %s %s (%x:%x)\n",
			       info->vendor, info->device,
			       info->vendor_id, info->device_id);
			/* Accept */
			return 1;
		}
	}
	printf("App: Rejecting controller %s %s (%x:%x), no App for this device\n",
	       info->vendor, info->device,
	       info->vendor_id, info->device_id);
	/* Deny */
	return 0;
}

int main(int argc, char** argv)
{
	signal(SIGINT, sighndlr);

	struct dummy_data dummy;
	memset(&dummy, 0, sizeof(struct dummy_data));
	void *future = 0x0;

	if(argc > 1) {
		dummy.print_events = 1;
	}

	struct ctlra_t *ctlra = ctlra_create(NULL);

	int num_devs = ctlra_probe(ctlra, accept_dev_func, &dummy);
	printf("probe num_devs %d\n", num_devs);

	audio_init(&dummy);

	while(!done) {
		ctlra_idle_iter(ctlra);
		usleep(100);
	}

	audio_exit();

	ctlra_exit(ctlra);

	return 0;
}
{'fraction_non_alphanumeric': 0.1290855067679102, 'fraction_numerical': 0.02344007923407065, 'mean_word_length': 4.087321578505458, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2740978', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2379, 'n_words': 477}