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(57600, F_CPU
));
32 //FIXME what was the following line for?
46 uint8_t somecycle
= 0; //FIXME debug value
48 void loop(){ //one frame
49 static uint8_t escape_state
= 0;
50 uint16_t receive_state
= 1;
51 //primitive somewhat messy state machine of the uart interface
52 do{ //Always empty the receive buffer since there are _delay_xxs in the following code and thus this might not run all that often.
53 receive_state
= uart_getc();
54 char c
= receive_state
&0xFF;
55 receive_state
&= 0xFF00;
60 //eats [n] commands: 's' (0x73) led value sets led number [led] to [value]
61 // 'b' (0x62) buffer buffer buffer buffer sets the whole frame buffer
62 // 'a' (0x61) meter value sets analog meter number [meter] to [value]
63 // 'r' (0x72) read the frame buffer
64 // 'd' (0x64) display digit digit digit digit sets the 7-segment display (CAUTION: "display" currently is ignored)
65 //this device will utter a "'c' (0x63) num state" when switch [num] changes state to [state]
66 //commands are terminated by \n
70 receive_state
|= 0x02;
73 receive_state
|= 0x02;
90 case 0: //Do not assume anything about the variables used
93 #ifdef HAS_LED_SUPPORT
101 #endif//HAS_LED_SUPPORT
102 #ifdef HAS_PWM_SUPPORT
107 #endif//HAS_PWM_SUPPORT
108 #ifdef HAS_NOISE_MAKER_SUPPORT
117 #endif//HAS_NOISE_MAKER_SUPPORT
118 #ifdef HAS_LED_SUPPORT
121 for(uint8_t i
=0; i
<sizeof(frameBuffer
); i
++){
122 uart_puthex(frameBuffer
[i
]);
126 #endif//HAS_LED_SUPPORT
127 #ifdef HAS_7SEG_SUPPORT
132 #endif//HAS_7SEG_SUPPORT
135 #ifdef HAS_LED_SUPPORT
145 secondFrameBuffer
[(uint8_t) nbuf
] = c
;
152 #endif//HAS_LED_SUPPORT
153 #ifdef HAS_PWM_SUPPORT
158 if(nbuf
>= PWM_COUNT
)
163 pwm_val
[(uint8_t) nbuf
] = c
;
164 uart_puts_p(PSTR("ACK\n"));
167 #endif//HAS_PWM_SUPPORT
168 #ifdef HAS_7SEG_SUPPORT
174 l7seg_buf
[(uint8_t)bpos
] = c
;
180 #endif//HAS_7SEG_SUPPORT
183 }while(!receive_state
);