#ifndef F_CPU
#define F_CPU 8000000UL
#endif

#include <stdint.h>
#include <avr/eeprom.h>
#include <avr/io.h>

#define EESIZE (1+E2END)

#include "Lichterkette.h"
#include "light_ws2812.h"
#include "ws2812_config.h"

typedef struct {
	const uint8_t	numLED;				
	const uint8_t colorWhiteR;
	const uint8_t colorWhiteG;
	const uint8_t colorWhiteB;
	const	uint8_t colorOrangeR;
	const uint8_t	colorOrangeG;
	const uint8_t	colorOrangeB;
	const uint8_t	colorRedR;
	const uint8_t	colorRedG;
	const uint8_t	colorRedB;
} eeprom_t;
eeprom_t eepPrefs EEMEM = {
	.numLED         = 6,
	.colorWhiteR    = 0x30,
	.colorWhiteG    = 0x30,
	.colorWhiteB    = 0x30,
	.colorOrangeR   = 0x90,
	.colorOrangeG   = 0x40,
	.colorOrangeB   = 0x00,
	.colorRedR   		= 0x50,
	.colorRedG   		= 0x00,
	.colorRedB   		= 0x00
};
eeprom_t ramPrefs;
uint8_t i;

void changeColorsInLEDs(char useCase) {
	switch (useCase) {
		case 'd': {
			for (i=0;i<ramPrefs.numLED;i++) {
				led[i].r = 0;				led[i].g = 0;				led[i].b = 0;
			}
			break;
		}
		case 'n': {
			led[2].r = ramPrefs.colorWhiteR;			led[2].g = ramPrefs.colorWhiteG;			led[2].b = ramPrefs.colorWhiteB;
			led[5].r = ramPrefs.colorWhiteR;			led[5].g = ramPrefs.colorWhiteG;			led[5].b = ramPrefs.colorWhiteB;
			led[1].r = ramPrefs.colorRedR;			led[1].g = ramPrefs.colorRedG;			led[1].b = ramPrefs.colorRedB;
			led[4].r = ramPrefs.colorRedR;			led[4].g = ramPrefs.colorRedG;			led[4].b = ramPrefs.colorRedG;
			break;
		}
	}
	ws2812_setleds(led, ramPrefs.numLED);
}

int main(void) {
	CLKPR=_BV(CLKPCE);		// Clock Prescaler Change Enable
  CLKPR=0;          		// Set Clock Prescale Register to 1 (attiny 25/45/85/24/44/84/13/13A)
	
	eeprom_read_block(&ramPrefs, &eepPrefs, sizeof(ramPrefs));
	struct cRGB led[ramPrefs.numLED];	
	changeColorsInLEDs('d');	// Alle einmal ausmachen am Anfang.
	changeColorsInLEDs('n');	// Normalbeleuchtung.
	return 0;
}
