<commit_before>/*
 * GccApplication4.cpp
 *
 * Created: 5/3/2015 1:17:27 AM
 *  Author: Garrett
 */ 

#define F_CPU 16000000UL

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "libs/Neopixel.h"
#include "Animation.h"

#define GET_BIT(TGT, PIN) ((TGT) & (1 << (PIN)))
#define SET_BIT(TGT, PIN) do { TGT |= (1 << (PIN)); } while(0)
#define CLEAR_BIT(TGT, PIN) do { TGT &= ~(1 << (PIN)); } while(0)
#define TOGGLE_BIT(TGT, PIN) do { TGT ^= (1 << (PIN)); } while(0)

void setup_pins(void) {
	CLEAR_BIT(DDRB, PB1);		// Set PB1(AIN1) as input, GCN data signal
	SET_BIT(PORTB, PB1);		// Enable pull-up resistor on PB1
	SET_BIT(DDRB, PB3);		// Set PB3 as output, debug LED
}

void setup_comparator(void) {
	SET_BIT(ACSR, ACBG);		// Enable 1.1V positive input reference voltage
}

void setup_timer0(void) {
	SET_BIT(TCCR0B, CS00);
}

//static volatile Controller *controller = (Controller*)message_buffer;

volatile uint8_t is_done = 0;

bool getMessage(uint8_t message_buffer[]) {
	// Zero out input array
	for(int i = 0; i < 12; ++i) {
		message_buffer[i] = 0x00;
	}

	// Wait for first bit
	while(!GET_BIT(ACSR, ACO)) {}

	for(uint8_t cur_byte = 0; cur_byte < 11; cur_byte++) {
		for(uint8_t bitmask = 0x80; bitmask; bitmask >>= 1) {
			// Make sure the signal is high before reading
			while(GET_BIT(ACSR, ACO)) {}

			// Reset timer
			TCNT0 = 0;
			// Wait for signal to go low
			while(!GET_BIT(ACSR, ACO)) {
				if(TCNT0 >= 240)	// Timeout
					return false;
			}

			// Reset timer and wait for signal's critical point
			TCNT0 = 0;
			while(TCNT0 <= 16) {}

			// Check if signal is high
			if(!GET_BIT(ACSR, ACO)) {
				message_buffer[cur_byte] |= bitmask;
			}
		}
	}
	return true;
}

int main(void)
{
	setup_pins();
	setup_comparator();
	setup_timer0();

	ledsetup();
	initAnimation();

	uint8_t message_buffer[12] = {0};

	while(1)
	{
		while(!getMessage(message_buffer)) {}
		//nextFrame(message_buffer);
		// Test if X is high
		if(message_buffer[3] & 0x04) {
			showColor(255, 0, 0, 4);
		} else {
			showColor(0, 255, 0, 4);
		}

		_delay_us(2000);		// Wait for the 2nd paired request to pass
	}
}<commit_msg>Testing control stick driven colors<commit_after>/*
 * GccApplication4.cpp
 *
 * Created: 5/3/2015 1:17:27 AM
 *  Author: Garrett
 */ 

#define F_CPU 16000000UL

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "libs/Neopixel.h"
#include "Animation.h"

#define GET_BIT(TGT, PIN) ((TGT) & (1 << (PIN)))
#define SET_BIT(TGT, PIN) do { TGT |= (1 << (PIN)); } while(0)
#define CLEAR_BIT(TGT, PIN) do { TGT &= ~(1 << (PIN)); } while(0)
#define TOGGLE_BIT(TGT, PIN) do { TGT ^= (1 << (PIN)); } while(0)

void setup_pins(void) {
	CLEAR_BIT(DDRB, PB1);		// Set PB1(AIN1) as input, GCN data signal
	SET_BIT(PORTB, PB1);		// Enable pull-up resistor on PB1
	SET_BIT(DDRB, PB3);		// Set PB3 as output, debug LED
}

void setup_comparator(void) {
	SET_BIT(ACSR, ACBG);		// Enable 1.1V positive input reference voltage
}

void setup_timer0(void) {
	SET_BIT(TCCR0B, CS00);
}

//static volatile Controller *controller = (Controller*)message_buffer;

volatile uint8_t is_done = 0;

bool getMessage(uint8_t message_buffer[]) {
	// Zero out input array
	for(int i = 0; i < 12; ++i) {
		message_buffer[i] = 0x00;
	}

	// Wait for first bit
	while(!GET_BIT(ACSR, ACO)) {}

	for(uint8_t cur_byte = 0; cur_byte < 11; cur_byte++) {
		for(uint8_t bitmask = 0x80; bitmask; bitmask >>= 1) {
			// Make sure the signal is high before reading
			while(GET_BIT(ACSR, ACO)) {}

			// Reset timer
			TCNT0 = 0;
			// Wait for signal to go low
			while(!GET_BIT(ACSR, ACO)) {
				if(TCNT0 >= 240)	// Timeout
					return false;
			}

			// Reset timer and wait for signal's critical point
			TCNT0 = 0;
			while(TCNT0 <= 16) {}

			// Check if signal is high
			if(!GET_BIT(ACSR, ACO)) {
				message_buffer[cur_byte] |= bitmask;
			}
		}
	}
	return true;
}

int main(void)
{
	setup_pins();
	setup_comparator();
	setup_timer0();

	ledsetup();
	initAnimation();

	uint8_t message_buffer[12] = {0};

	while(1)
	{
		while(!getMessage(message_buffer)) {}
		//nextFrame(message_buffer);
		// Test if X is high
		showColor(message_buffer[5], message_buffer[6], message_buffer[7], message_buffer[8]/32);

		_delay_us(2000);		// Wait for the 2nd paired request to pass
	}
}
{'fraction_non_alphanumeric': 0.15823665893271463, 'fraction_numerical': 0.04222737819025522, 'mean_word_length': 3.5861702127659574, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 15, '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': '5634937', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1722, 'n_words': 439}