library for implementing ir transmission
Diff: XMIT_IR.cpp
- Revision:
- 5:ad52a062d494
- Parent:
- 4:55946953c6e3
- Child:
- 6:281167565d6d
diff -r 55946953c6e3 -r ad52a062d494 XMIT_IR.cpp --- a/XMIT_IR.cpp Sat Oct 06 12:52:28 2012 +0000 +++ b/XMIT_IR.cpp Sat Oct 06 14:40:38 2012 +0000 @@ -2,7 +2,7 @@ #include "XMIT_IR.h" -IRTransmitter::IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr)(void)) +IRTransmitter::IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr_isr_rx)(void), void (*fptr_isr_tx)(void)) { ir_serial = new Serial(TX,RX); ir_pwm = new PwmOut(PWM); @@ -13,7 +13,8 @@ (*ir_pwm).period(1.0/38000.0); //38kHz Modulation Freq (*ir_pwm) = 0.5; //pulse width = 50% (*ir_serial).baud(2400); - (*ir_serial).attach(fptr,Serial::RxIrq); + (*ir_serial).attach(fptr_isr_rx,Serial::RxIrq); + (*ir_serial).attach(fptr_isr_tx,Serial::TxIrq); //Initialize Variables for(int i=0; i<data_buff_len+3; i++) @@ -44,19 +45,12 @@ } (*ir_serial).putc(check); (*ir_serial).putc(ASCII_ETX); + + /*char* mail = ir_txdata_mailbox.alloc(); + mail[0] = (char)data; + ir_txdata_mailbox.put(mail);*/ } -/*char IRTransmitter::ReadPacket(char* data) -{ - osEvent evt = ir_data_mailbox.get(); - if(evt.status == osEventMail) { - char* mail = (char*)evt.value.p; - (*data) = (*mail); - ir_data_mailbox.free(mail); - return 0; - } - return 1; -}*/ char IRTransmitter::ReadPacket(char* data, int len) @@ -69,7 +63,7 @@ // -len: length of character array char return_state=0; - osEvent evt = ir_data_mailbox.get(); + osEvent evt = ir_rxdata_mailbox.get(); while(evt.status == osEventMail) { char* mail = (char*)evt.value.p; (*data) = (*mail); @@ -91,12 +85,12 @@ } } - ir_data_mailbox.free(mail); + ir_rxdata_mailbox.free(mail); if(return_state) { return return_state; } - evt = ir_data_mailbox.get(); + evt = ir_rxdata_mailbox.get(); } return return_state; } @@ -132,11 +126,17 @@ } -void IRTransmitter::isr(char data) +void IRTransmitter::isr_rx(char data) { - char* mail = ir_data_mailbox.alloc(); + char* mail = ir_rxdata_mailbox.alloc(); mail[0] = (char)data; - ir_data_mailbox.put(mail); + ir_rxdata_mailbox.put(mail); } +void IRTransmitter::isr_tx() +{ + //char* mail = ir_rxdata_mailbox.alloc(); + //mail[0] = (char)data; + //ir_rxdata_mailbox.put(mail); +}