<commit_before>/********************************************************
42 Robot Car Controller (Logitech G27)
Special Thanks to HIDAPI and Feral Interactive
********************************************************/

#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include "hidapi.h"

// Headers needed for sleeping.
#include <unistd.h>


//Constants for using curl
char *ip = "192.168.2.3";
char *datturn[3] = {"/lf", "/st85", "/rt"};
char *datdir[2] = {"/rev", "/fwd"};

//Header for time
#include <time.h>

clock_t t0 = 0;

//This function allows

void	parse(unsigned char buf[256])
{
	unsigned char		gear;
	unsigned char		temp;
	unsigned short	wheel;
	int							turn;
	int							dir;
	int							on;
	clock_t					t1;

	printf("---Current State---\n");

	//Get Direction
	wheel = buf[3] + buf[4] * 256;
	printf("Turn angle: %.1f\nDirection: ", (wheel - 32767.0) / 65535.0 * 360.0);
	if (wheel < 0x7b00)
	{
		printf("left\n");
		turn = 0;
	}
	else if (wheel > 0x8300)
	{
		printf("right\n");
		turn = 2;
	}
	else
	{
		printf("straight\n");
		turn = 1;
	}

	//Get Gear
	temp = buf[2];
	gear = 0;
	while (temp){
		temp /= 2;
		gear++;
	}
	if (gear == 6)
	{
		dir = 0;
		printf("Gear set to R\n");
	}
	else
	{
		dir = 1;
		printf("Gear set to %d\n", gear);
	}

	//Check gas pedal
	if (buf[5] < 0xff){
		on = 1;
		printf("Gas is on\n");
	}
	else{
		on = 0;
		printf("Gas is off\n");
	}

	//Check brake pedal
	if (buf[6] < 0xff) {
		on &= 0;
		printf("Brake is on\n");
	}
	else{
		on &= 1;
		printf("Brake is off\n");
	}

	//Send command to car...
	t1 = clock();
	if (on && (t1 - t0) > 500)
	{
		char command[128] = "curl ";
		strcat(command, ip);
		strcat(command, datdir[dir]);
		strcat(command, datturn[turn]);
		system(command);
		t0 = clock();
	}
//	else
//		printf("no command... are you pressing the gas?\n");

	printf("--------------------\n");
}

int main(void)
{
	int 					res;
	unsigned char buf[256];
	#define MAX_STR 255
	wchar_t 			wstr[MAX_STR];
	hid_device 		*handle;
	int 					i;
	time_t				timer;
<commit_msg>Added edge case where gear is set to neutral (0)<commit_after>/********************************************************
42 Robot Car Controller (Logitech G27)
Special Thanks to HIDAPI and Feral Interactive
********************************************************/

#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include "hidapi.h"

// Headers needed for sleeping.
#include <unistd.h>


//Constants for using curl
char *ip = "192.168.2.3";
char *datturn[3] = {"/lf", "/st85", "/rt"};
char *datdir[2] = {"/rev", "/fwd"};

//Header for time
#include <time.h>

clock_t t0 = 0;

//This function allows

void	parse(unsigned char buf[256])
{
	unsigned char		gear;
	unsigned char		temp;
	unsigned short	wheel;
	int							turn;
	int							dir;
	int							on;
	clock_t					t1;

	printf("---Current State---\n");

	//Get Direction
	wheel = buf[3] + buf[4] * 256;
	printf("Turn angle: %.1f\nDirection: ", (wheel - 32767.0) / 65535.0 * 360.0);
	if (wheel < 0x7b00)
	{
		printf("left\n");
		turn = 0;
	}
	else if (wheel > 0x8300)
	{
		printf("right\n");
		turn = 2;
	}
	else
	{
		printf("straight\n");
		turn = 1;
	}

	//Get Gear
	temp = buf[2];
	gear = 0;
	while (temp){
		temp /= 2;
		gear++;
	}
	if (gear == 6)
	{
		dir = 0;
		printf("Gear set to R\n");
	}
	else
	{
		dir = 1;
		printf("Gear set to %d\n", gear);
		if (!gear)
			dir = 2;
	}

	//Check gas pedal
	if (buf[5] < 0xff){
		on = 1;
		printf("Gas is on\n");
	}
	else{
		on = 0;
		printf("Gas is off\n");
	}

	//Check brake pedal
	if (buf[6] < 0xff) {
		on &= 0;
		printf("Brake is on\n");
	}
	else{
		on &= 1;
		printf("Brake is off\n");
	}

	//Send command to car...
	t1 = clock();
	if (on && (t1 - t0) > 500 && dir < 2)
	{
		char command[128] = "curl ";
		strcat(command, ip);
		strcat(command, datdir[dir]);
		strcat(command, datturn[turn]);
		system(command);
		t0 = clock();
	}
//	else
//		printf("no command... are you pressing the gas?\n");

	printf("--------------------\n");
}

int main(void)
{
	int 					res;
	unsigned char buf[256];
	#define MAX_STR 255
	wchar_t 			wstr[MAX_STR];
	hid_device 		*handle;
	int 					i;
	time_t				timer;

{'fraction_non_alphanumeric': 0.23726381248505143, 'fraction_numerical': 0.04185601530734274, 'mean_word_length': 2.7880434782608696, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3907627', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1715, 'n_words': 459}