library for implementing ir transmission
Diff: XMIT_IR.cpp
- Revision:
- 1:ae1d2167a10c
- Parent:
- 0:556f9be6047d
- Child:
- 2:2eb0a3a29b5b
diff -r 556f9be6047d -r ae1d2167a10c XMIT_IR.cpp --- a/XMIT_IR.cpp Thu Oct 04 13:57:37 2012 +0000 +++ b/XMIT_IR.cpp Sat Oct 06 01:44:32 2012 +0000 @@ -3,23 +3,67 @@ -irTransmitter::irTransmitter(PinName TX, PinName PWM) +IRTransmitter::IRTransmitter(PinName TX, PinName PWM, PinName RX, int data_buff_len, void (*fptr)(void)) { + ir_serial = new Serial(TX,RX); + ir_pwm = new PwmOut(PWM); + data_buffer_out = new char(data_buff_len); + data_buffer_in = new char(data_buff_len+2); + //Initialize modules + (*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); +} + +IRTransmitter::~IRTransmitter() +{ + delete ir_serial; + delete ir_pwm; + delete data_buffer_out; + delete data_buffer_in; } -irTransmitter::~irTransmitter() + +void IRTransmitter::MakePacket(char* data,int len) +{ + char check =0x0; + (*ir_serial).putc(ASCII_STX); + for(int i=0; i<len; i++) { + check^=data[i]; + (*ir_serial).putc(data[i]); + } + (*ir_serial).putc(check); + (*ir_serial).putc(ASCII_ETX); +} + +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; +} + +//Handle Reception of RX data (mail it to appropriate thread) +void IRTransmitter::isr_uartrx(void) +{ + //get RX data (and prevent ISR from looping forever + uint32_t RBR = LPC_UART1->RBR; //This only works for p13/p14! + + //write letter and put in mailbox + char* mail = ir_data_mailbox.alloc(); + mail[0] = (char)RBR; + ir_data_mailbox.put(mail); + + //Let message handler run + //(*threadptr_irstuff).signal_set(0x1); } -irReceiver::irReceiver() -{ -} - -irReceiver::~irReceiver() -{ - -} -