<commit_before>#include <stdio.h>
#include <stdint.h>

typedef struct Color Color;
typedef struct State State;

typedef uint8_t (*Color_fn)(uint8_t counter);
typedef uint8_t (*Condition)(uint8_t counter, uint8_t parameter);

struct Color {
	uint8_t red, green, blue;
};

// TODO: Find out a way to do exit conditions
struct State {
	uint8_t counter;
	Color_fn red, green, blue;
	uint8_t max;
	State *nextState;
};

// Simple color ramp
uint8_t linear(uint8_t counter) {
	return counter;
}

uint8_t zero(uint8_t counter) {
	return 0;
}

// TODO: Add exit condition processing
void nextFrame(State *st) {
	if(st->counter >= st->max) {
		st->counter = 0;
		st = st->nextState;
	} else {
		st->counter++;
	}
}

Color getColor(State *st) {
	uint8_t red = st->red(st->counter);
	uint8_t green = st->green(st->counter);
	uint8_t blue = st->blue(st->counter);
	Color col = {red, green, blue};
	return col;
}

State idle = {0, linear, zero, zero, 2, &idle};

int main(int arc, char **argv)
{
	printf("Entering main\n");

	State *curState = &idle;

	int i;
	for(i = 0; i < 10; i++) {
		Color col = getColor(curState);
		printf("counter: %u\tred: %u\t green: %u\tblue: %u\n", curState->counter, col.red, col.green, col.blue);
		nextFrame(curState);
	}

	return 0;
}<commit_msg>Added single exit condition<commit_after>#include <stdio.h>
#include <stdint.h>

typedef struct Color Color;
typedef struct State State;
typedef struct Exit Exit;

typedef uint8_t (*Color_fn)(uint8_t counter);
typedef uint8_t (*Condition)(uint8_t counter, uint8_t parameter);


// TODO: Find out a way to do exit conditions
struct State {
	uint8_t counter;
	Color_fn red, green, blue;
	uint8_t max;
	State *nextState;
	Exit *exit;
};

struct Exit {
	uint8_t byte;
	uint8_t mask;
	State *exitState;
};

struct Color {
	uint8_t red, green, blue;
};

// Simple color functions
uint8_t linear(uint8_t counter) {
	return counter;
}
uint8_t zero(uint8_t counter) {
	return 0;
}
uint8_t max(uint8_t counter) {
	return 255;
}

// Button checks
uint8_t buttonBuffer[7] = {0,0,0,0,0,0,0};
uint8_t checkButton(uint8_t byte, uint8_t mask) {
	if(buttonBuffer[byte] & mask) 
		return 1;
	else
		return 0;
}

// TODO: Add exit condition processing
State *nextFrame(State *st) {
	if(st->counter >= st->max) {
		st->counter = 0;
		st = st->nextState;
	} else if(checkButton(st->exit->byte, st->exit->mask)) {
		printf("B pressed!\n");
		st->counter = 0;
		st = st->exit->exitState;
	} else {
		st->counter++;
	}
}

Color getColor(State *st) {
	uint8_t red = st->red(st->counter);
	uint8_t green = st->green(st->counter);
	uint8_t blue = st->blue(st->counter);
	Color col = {red, green, blue};
	return col;
}


State idleState;
State shineState;
Exit shineExit;

int main(int arc, char **argv)
{
	printf("Entering main\n");

	idleState = {0, linear, zero, zero, 2, &idleState, &shineExit};
	shineState = {0, zero, zero, max, 5, &idleState, &shineExit};
	shineExit = {1, 0b00000010, &shineState};

	State *curState = &idleState;

	int i;
	for(i = 0; i < 10; i++) {
		Color col = getColor(curState);
		printf("counter: %u\tred: %u\t green: %u\tblue: %u\n", curState->counter, col.red, col.green, col.blue);
		curState = nextFrame(curState);
	}

	buttonBuffer[1] = 0b00000010;
	curState = nextFrame(curState);
	buttonBuffer[1] = 0b00000000;

	for(i = 0; i < 10; i++) {
		Color col = getColor(curState);
		printf("counter: %u\tred: %u\t green: %u\tblue: %u\n", curState->counter, col.red, col.green, col.blue);
		curState = nextFrame(curState);
	}

	return 0;
}
{'fraction_non_alphanumeric': 0.15720399429386592, 'fraction_numerical': 0.029386590584878743, 'mean_word_length': 4.248502994011976, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '4703812', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1364, 'n_words': 369}