From: Othmar Gsenger Date: Tue, 13 Dec 2011 18:33:51 +0000 (+0000) Subject: added basic sender features X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=894be2570b2c0198a4c7b87f385957c74b836bb3;p=svn42.git added basic sender features --- diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index ad07cda..282e0bc 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -28,12 +28,18 @@ #include "usb_rawhid.h" #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) - +#define RF_SEND_BUFFER_LEN_MAX 128 volatile uint16_t output_count=0; volatile uint8_t active_buffer=0; -volatile uint8_t send_buffer=0; -uint8_t read_buffer[64]; -uint8_t write_buffer[2][64]; +volatile uint16_t send_buffer=0; +volatile uint8_t capture=0; +volatile uint8_t rf_send=0; //count of bits in rf_send_buffer that should be sent +volatile uint8_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent +volatile uint8_t rf_send_reload_count=0; // number of repetitions (times rf_send gets reloaded; +uint8_t read_buffer[64]; // buffer for reading usb signals +uint8_t write_buffer[2][64]; // buffer for writing usb signals +uint8_t rf_send_buffer[RF_SEND_BUFFER_LEN_MAX]; // buffer for sending rf433 signals +uint8_t rf_send_buffer_len=0; int main(void) { @@ -59,8 +65,37 @@ int main(void) _delay_ms(1000); while (1) { // if received data, do something with it - //r = usb_rawhid_recv(read_buffer, 0); - //if (r>0) + int8_t r = usb_rawhid_recv(read_buffer, 0); + if (r>0) + { + if (read_buffer[0]=='b') //begin capture + capture=1; + else if (read_buffer[0]=='e') //end capture + capture=0; + else if (read_buffer[0]=='f') //fill send buffer + { + int8_t byte_rem = r-1; + while(byte_rem && rf_send_buffer_len2) + rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset + else + rf_send_reload=rf_send_buffer_len*8; + rf_send_reload_count=read_buffer[1]; + } + } if (send_buffer) { send_buffer=0; @@ -73,13 +108,27 @@ int main(void) ISR(TIMER0_COMPA_vect) { PORTF^=2; - write_buffer[active_buffer][output_count/8]<<=1; - write_buffer[active_buffer][output_count++/8]|=PINB&1; - if (output_count>=64*8) + if (rf_send) { - output_count=0; - active_buffer=active_buffer?0:1; - send_buffer=1; + if (rf_send_buffer[rf_send/8] & 0x80) + { + PORTF|=1; + } else { + PORTF&=~1; + } + rf_send_buffer[rf_send/8]<<=1; + rf_send--; + } else if (rf_send_reload_count) { + rf_send=rf_send_reload; + } else if (capture) { + write_buffer[active_buffer][output_count/8]<<=1; + write_buffer[active_buffer][output_count++/8]|=PINB&1; + if (output_count>=64*8) + { + output_count=0; + active_buffer=active_buffer?0:1; + send_buffer=1; + } } }