/*---------------------------------------------*\ | RGB Fan Controller - Serial Port Code File | | This file contains the functionality of the | | buffered serial port. It uses a buffer array| | and a position value. The default buffer | | size is 64 bytes, though you can increase | | it if you need a larger buffer. | | | | Adam Honse (CalcProgrammer1), 2010 | \*---------------------------------------------*/ #include "fanbus.h" unsigned char fanbus_serial_buffer[5]; //Serial buffer extern char outlet; extern char state; //USART Receive interrupt pushes the incoming byte into the buffer ISR(USART_RX_vect) { //Shift in new data fanbus_serial_buffer[0] = fanbus_serial_buffer[1]; fanbus_serial_buffer[1] = fanbus_serial_buffer[2]; fanbus_serial_buffer[2] = fanbus_serial_buffer[3]; fanbus_serial_buffer[3] = fanbus_serial_buffer[4]; fanbus_serial_buffer[4] = UDR; //Test if valid write packet if(fanbus_serial_buffer[0] == 0x00 && fanbus_serial_buffer[4] == 0xFF && fanbus_serial_buffer[2] == 0xAA) { fanbus_transmit('A'); state = fanbus_serial_buffer[3]; outlet = fanbus_serial_buffer[1]; } } void fanbus_init(unsigned int baud) { //Set baud rate UBRRH = (unsigned char) (baud >> 8); UBRRL = (unsigned char) (baud); //Set frame format: 8 data, no parity, 2 stop bits UCSRC = (0<