2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
11 #include <util/delay.h>
12 #include <avr/pgmspace.h>
13 #include <avr/interrupt.h>
16 #include "r0ketbeam.h"
31 uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(115200, F_CPU
));
45 void loop(){ //one frame
46 static uint8_t escape_state
= 0;
47 uint16_t receive_state
= 1;
48 //primitive somewhat messy state machine of the uart interface
49 do{ //Always empty the receive buffer since there are _delay_xxs in the following code and thus this might not run all that often.
50 receive_state
= uart_getc();
51 char c
= receive_state
&0xFF;
52 receive_state
&= 0xFF00;
57 //eats [n] commands: 's' (0x73) led value sets led number [led] to [value]
58 // 'b' (0x62) buffer buffer buffer buffer sets the whole frame buffer
59 // 'a' (0x61) meter value sets analog meter number [meter] to [value]
60 // 'r' (0x72) read the frame buffer
61 // 'd' (0x64) display digit digit digit digit sets the 7-segment display (CAUTION: "display" currently is ignored)
62 //this device will utter a "'c' (0x63) num state" when switch [num] changes state to [state]
63 //commands are terminated by \n
67 receive_state
|= 0x02;
70 receive_state
|= 0x02;
87 case 0: //Do not assume anything about the variables used
90 #ifdef HAS_LED_SUPPORT
98 #endif//HAS_LED_SUPPORT
99 #ifdef HAS_PWM_SUPPORT
104 #endif//HAS_PWM_SUPPORT
105 #ifdef HAS_LED_SUPPORT
108 for(uint8_t i
=0; i
<sizeof(frameBuffer
); i
++){
109 uart_puthex(frameBuffer
[i
]);
113 #endif//HAS_LED_SUPPORT
114 #ifdef HAS_7SEG_SUPPORT
119 #endif//HAS_7SEG_SUPPORT
122 #ifdef HAS_LED_SUPPORT
132 secondFrameBuffer
[(uint8_t) nbuf
] = c
;
139 #endif//HAS_LED_SUPPORT
140 #ifdef HAS_PWM_SUPPORT
148 pwm_val
[(uint8_t) nbuf
] = c
;
151 #endif//HAS_PWM_SUPPORT
152 #ifdef HAS_7SEG_SUPPORT
158 l7seg_buf
[(uint8_t)bpos
] = c
;
164 #endif//HAS_7SEG_SUPPORT
167 }while(!receive_state
);