<commit_before>#include "control.h"

/**
 * Get the device for sensor input
 * @method getSensirDeviceFileName
 * @param  position (1|2)
 * @return
 */
char *getSensorDeviceFileName(int position) {

	char buff[20];

	/* get the devicenames of sensors */
	static const char *command = "grep -E 'Handlers|EV' /proc/bus/input/devices |"
	                             "grep -B1 100013 |"
	                             "grep -Eo event[0-9]+ |"
	                             "tr -d '\\n'";

	/* device path prefix */
	char path_prefix[20] = "/dev/input/";

	/* Sensor device names */
	char sensor_device_1[10];
	char sensor_device_2[10];

	/* Run the command */
	FILE *cmd = popen(command, "r");

	if (cmd == NULL) {
		printf("Could not determine sensor device file\n");
	}

	/* zero the string */
	memset(&buff, 0, 20);

	/* zero the string */
	memset(&sensor_device_1, 0, 10);

	/* zero the string */
	memset(&sensor_device_2, 0, 10);

	/* Read back the info from the command */
	fgets(buff, 20, cmd);

	/* Close the file */
	pclose(cmd);

	if (strlen(buff) > 0) {
		// Assumes the length of the device name is 6 chars long
		// copy the first device name
		strncpy(sensor_device_1, buff, 6);

		// copy the second device name
		strncpy(sensor_device_2, &buff[6], 6);
	} else {
		return 0;
	}

	if (conf->verbose) {
		printf("%s\n", sensor_device_1);
		printf("%s\n", sensor_device_2);
	}

	/* return the sensor device */
	if (position == 1) {
		return (strdup(strcat(path_prefix, sensor_device_1)));
	} else if (position == 2) {
		return (strdup(strcat(path_prefix, sensor_device_2)));
	}

	return 0;
}

/**
 * Controller loop
 * @method control_run_loop
 * @return boolean
 */
int control_run_loop() {

	if (conf->verbose)
		puts("Starting Controller");

	struct timeval tv;

	uint8_t shift_pressed = 0;

	input_event event;

	fd_set master;
	fd_set read_set;

	bool playing = FALSE;
	bool end = FALSE;

	int fd_max = 0;
	int listen_fd = 0;

	/* Get the keyboard file descriptos */
	if (conf->verbose)
		puts("Getting sensor 1");
	int sensor_device_1 = openDeviceFile(getSensorDeviceFileName(1));

	/* Get the keyboard file descriptos */
	if (conf->verbose)
		puts("Getting sensor 1");
	int sensor_device_2 = openDeviceFile(getSensorDeviceFileName(2));

	if (!(sensor_device_1 > 0) || !(sensor_device_2 > 0)) {
		perror("Could not get sensors");
		exit(EXIT_FAILURE);
	}

 if (wiringPiSetupGpio () == -1)
		exit(EXIT_FAILURE);

  pinMode (LED, OUTPUT) ;         //set the pin to output
  // switch gpio pin to disable relay
  digitalWrite(LED, ON);

	// use avahi to find the server
	// if there is no server address,
	if (conf->avahi || NULL == conf->server_address) {
		do {<commit_msg>turn LED OFF by default at load<commit_after>#include "control.h"

/**
 * Get the device for sensor input
 * @method getSensirDeviceFileName
 * @param  position (1|2)
 * @return
 */
char *getSensorDeviceFileName(int position) {

	char buff[20];

	/* get the devicenames of sensors */
	static const char *command = "grep -E 'Handlers|EV' /proc/bus/input/devices |"
	                             "grep -B1 100013 |"
	                             "grep -Eo event[0-9]+ |"
	                             "tr -d '\\n'";

	/* device path prefix */
	char path_prefix[20] = "/dev/input/";

	/* Sensor device names */
	char sensor_device_1[10];
	char sensor_device_2[10];

	/* Run the command */
	FILE *cmd = popen(command, "r");

	if (cmd == NULL) {
		printf("Could not determine sensor device file\n");
	}

	/* zero the string */
	memset(&buff, 0, 20);

	/* zero the string */
	memset(&sensor_device_1, 0, 10);

	/* zero the string */
	memset(&sensor_device_2, 0, 10);

	/* Read back the info from the command */
	fgets(buff, 20, cmd);

	/* Close the file */
	pclose(cmd);

	if (strlen(buff) > 0) {
		// Assumes the length of the device name is 6 chars long
		// copy the first device name
		strncpy(sensor_device_1, buff, 6);

		// copy the second device name
		strncpy(sensor_device_2, &buff[6], 6);
	} else {
		return 0;
	}

	if (conf->verbose) {
		printf("%s\n", sensor_device_1);
		printf("%s\n", sensor_device_2);
	}

	/* return the sensor device */
	if (position == 1) {
		return (strdup(strcat(path_prefix, sensor_device_1)));
	} else if (position == 2) {
		return (strdup(strcat(path_prefix, sensor_device_2)));
	}

	return 0;
}

/**
 * Controller loop
 * @method control_run_loop
 * @return boolean
 */
int control_run_loop() {

	if (conf->verbose)
		puts("Starting Controller");

	struct timeval tv;

	uint8_t shift_pressed = 0;

	input_event event;

	fd_set master;
	fd_set read_set;

	bool playing = FALSE;
	bool end = FALSE;

	int fd_max = 0;
	int listen_fd = 0;

	/* Get the keyboard file descriptos */
	if (conf->verbose)
		puts("Getting sensor 1");
	int sensor_device_1 = openDeviceFile(getSensorDeviceFileName(1));

	/* Get the keyboard file descriptos */
	if (conf->verbose)
		puts("Getting sensor 1");
	int sensor_device_2 = openDeviceFile(getSensorDeviceFileName(2));

	if (!(sensor_device_1 > 0) || !(sensor_device_2 > 0)) {
		perror("Could not get sensors");
		exit(EXIT_FAILURE);
	}

	if (wiringPiSetupGpio () == -1)
		exit(EXIT_FAILURE);

	//set the pin to output
	pinMode (LED, OUTPUT);

	// switch gpio pin to disable relay
	digitalWrite(LED, OFF);

	// use avahi to find the server
	// if there is no server address,
	if (conf->avahi || NULL == conf->server_address) {
		do {
{'fraction_non_alphanumeric': 0.14086601003530944, 'fraction_numerical': 0.02378740011150344, 'mean_word_length': 3.1178270849273146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7006248', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1871, 'n_words': 544}