X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=rf433rcv%2Fteensy%2Fexample.c;h=649f6de32f09cdb64e10de2d928d599b83ec9292;hb=f505a1c37ea1c76897991f9882de765e34f0cc98;hp=282e0bcb0ccec420d86002d65b8264f0b7dd17d9;hpb=894be2570b2c0198a4c7b87f385957c74b836bb3;p=svn42.git diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index 282e0bc..649f6de 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -33,13 +33,50 @@ volatile uint16_t output_count=0; volatile uint8_t active_buffer=0; 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 uint16_t rf_send=0; //count of bits in rf_send_buffer that should be sent +volatile uint16_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; +volatile uint16_t rf_send_buffer_len=0; + + +void reset() +{ + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1<0) { - if (read_buffer[0]=='b') //begin capture + if (read_buffer[0]=='r') //reset + reset(); + else 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; + //if (r>2) + // rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset + //else + usb_rawhid_send(rf_send_buffer, 145); + rf_send=0; + rf_send_reload=rf_send_buffer_len*8; rf_send_reload_count=read_buffer[1]; + //read_buffer[0]=rf_send_reload; + //read_buffer[1]=rf_send_reload>>8; + //read_buffer[2]=0; } } if (send_buffer) @@ -110,26 +154,28 @@ ISR(TIMER0_COMPA_vect) PORTF^=2; if (rf_send) { - if (rf_send_buffer[rf_send/8] & 0x80) + if ( ( rf_send_buffer[rf_send/8] >> ( (rf_send%8)?8-(rf_send%8):0 ) ) & 1) { - PORTF|=1; - } else { PORTF&=~1; + } else { + PORTF|=1; } - rf_send_buffer[rf_send/8]<<=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; + rf_send_reload_count--; + } else { + PORTF&=~1; + 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; + } } } } - -