library for implementing ir transmission
Revision 7:01243fe65940, committed 2012-10-06
- Comitter:
- cmulady
- Date:
- Sat Oct 06 17:45:20 2012 +0000
- Parent:
- 6:281167565d6d
- Commit message:
- good stopping point. ir tx works well enough
Changed in this revision
XMIT_IR.cpp | Show annotated file Show diff for this revision Revisions of this file |
XMIT_IR.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 281167565d6d -r 01243fe65940 XMIT_IR.cpp --- a/XMIT_IR.cpp Sat Oct 06 17:36:37 2012 +0000 +++ b/XMIT_IR.cpp Sat Oct 06 17:45:20 2012 +0000 @@ -2,7 +2,7 @@ #include "XMIT_IR.h" -IRTransmitter::IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr_isr_rx)(void), void (*fptr_isr_tx)(void)) +IRTransmitter::IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr_isr_rx)(void)) { ir_serial = new Serial(TX,RX); ir_pwm = new PwmOut(PWM); @@ -14,11 +14,6 @@ (*ir_pwm) = 0.5; //pulse width = 50% (*ir_serial).baud(2400); (*ir_serial).attach(fptr_isr_rx,Serial::RxIrq); - (*ir_serial).attach(fptr_isr_tx,Serial::TxIrq); - -// uint_32 tmp = LPC_UART1->IER; - -// LPC_UART1->IER = tmp; //Initialize Variables for(int i=0; i<data_buff_len+3; i++) @@ -42,38 +37,15 @@ void IRTransmitter::MakePacket(char* data,int len) { char check =0x0; - Timer t; - t.reset(); - t.start(); - - //(*ir_serial).putc(ASCII_STX); - mail_tx_packet(ASCII_STX); + + (*ir_serial).putc(ASCII_STX); for(int i=0; i<len; i++) { check^=data[i]; - //(*ir_serial).putc(data[i]); - mail_tx_packet(data[i]); + (*ir_serial).putc(data[i]); } - //(*ir_serial).putc(check); - mail_tx_packet(check); - //(*ir_serial).putc(ASCII_ETX); - mail_tx_packet(ASCII_ETX); - - t.stop(); - int time = t.read_ms(); - (*debug_port).printf("\nms=%d\n",time); + (*ir_serial).putc(check); + (*ir_serial).putc(ASCII_ETX); - char tmp = isr_tx(); - LPC_UART1->THR = (uint32_t)data; - - - -} - -void IRTransmitter::mail_tx_packet(char data) -{ - char* mail = ir_txdata_mailbox.alloc(); - mail[0] = data; - ir_txdata_mailbox.put(mail); } @@ -102,10 +74,6 @@ } (*debug_port).printf(" PKT_VALID=0x%02X.",packet_is_valid(len));*/ - if((*data)=='?') { - (*debug_port).putc('*'); - } - if(packet_is_valid(len)==0) { @@ -163,22 +131,4 @@ ir_rxdata_mailbox.put(mail); } -char IRTransmitter::isr_tx(void) -{ - //char* mail = ir_rxdata_mailbox.alloc(); - //mail[0] = (char)data; - //ir_rxdata_mailbox.put(mail); - char data = 0xF1; - osEvent evt = ir_txdata_mailbox.get(); - if(evt.status == osEventMail) { - char* mail = (char*)evt.value.p; - data = (*mail); - - //(*ir_serial).putc(data); - ir_rxdata_mailbox.free(mail); - } - //(*debug_port).printf("TX=0x%02X.",data); - return data; -} -
diff -r 281167565d6d -r 01243fe65940 XMIT_IR.h --- a/XMIT_IR.h Sat Oct 06 17:36:37 2012 +0000 +++ b/XMIT_IR.h Sat Oct 06 17:45:20 2012 +0000 @@ -11,23 +11,19 @@ class IRTransmitter { public: - IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr_isr_rx)(void), void (*fptr_isr_tx)(void)); + IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr_isr_rx)(void)); ~IRTransmitter(); void MakePacket(char* data,int len); char ReadPacket(char* data, int len); - void isr_uartrx(void); void isr_rx(char data); - char isr_tx(void); void set_debug_port(Serial* port); private: char packet_is_valid(int data_len); void update_packet_buffer(char new_data, int data_len); - void mail_tx_packet(char data); public: - Mail<char,32> ir_rxdata_mailbox; - Mail<char,32> ir_txdata_mailbox; + Mail<char,64> ir_rxdata_mailbox; Serial* debug_port;