Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1198 → Rev 1199

/C-OSD/C-Epilepsy/main.c
0,0 → 1,133
/****************************************************************************
* Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje *
* admiralcascade@gmail.com *
* Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
****************************************************************************/
 
#include "main.h"
 
uint8_t main_mode = 0;
volatile uint8_t CEPILEPSYFLAGS = 0;
 
const uint8_t COLORS [][6] = {
{ 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010, 0b10101010}, // color one
{ 0b01010101, 0b01010101, 0b01010101, 0b01010101, 0b01010101, 0b01010101}, // color one
{ 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111} // both colors
};
 
void pin_init(void) {
#if HWVERSION == EPI10AQ41
DDRB |= (1 << PB1) | (1 << PB2); // LEDs output
DDRD |= ((1 << PD6)); // S6 output, unused for now
#elif HWVERSION == EPI10
DDRD |= (1 << PD7) | (1 << PD3); // LEDs output
#else
// hardware 1.1
DDRD |= (1 << PD7); // dual led port output
#endif
}
 
 
// random init
 
unsigned short get_seed(void) {
unsigned short seed = 0;
unsigned short *p = (unsigned short*)(RAMEND + 1);
extern unsigned short __heap_start;
 
while (p >= &__heap_start + 1)
seed ^= *(--p);
 
return seed;
}
 
/* ##########################################################################
* MAIN
* ##########################################################################*/
int main(void) {
 
LEDRED_ON // boot
 
clear();
 
 
 
pin_init();
led_out_init();
timer0_init();
timer1_init();
usart0_init();
#ifdef __AVR_ATmega644P__
//usart1_init();
#endif
buttons_init();
load_eeprom();
 
 
// enable interrupts
sei();
 
 
unsigned short seed = get_seed();
srand(seed);
 
 
// selftest
//while (1) {
/*for (uint8_t times = 0; times < 5; times++) {
for (uint8_t i = 0; i < 48; i++) {
setLed(animation, i, 1);
_delay_ms(100);
animation[i] = 0;
}
}*/
//}
 
LEDRED_OFF // finished boot
LEDGREEN_ON
 
 
// clear serial screen
//usart0_puts("\x1B[2J\x1B[H");
/*usart0_puts_pgm(PSTR("C-Epilepsy came to say hello...\r\n"));
usart0_puts_pgm(PSTR("\tVersion: "));
usart0_puts_pgm(PSTR(BUILDDATE));
#ifdef __AVR_ATmega644P__
usart0_puts_pgm(PSTR(" atmega644p"));
#endif
usart0_puts_pgm(PSTR("\r\n"));*/
 
 
while (1) {
switch (main_mode) {
case 0:
player();
break;
case 1:
nc_handler();
break;
}
 
if (mode_pressed()) {
main_mode = (main_mode + 1) % 2; // % number of modes available
blinkNumer(animation, main_mode + 1, 5);
}
 
}
 
return 0;
}