Software UART program using Infra-Red LED and IR-Detector
Dependents: TestVirtualisation Bf_SoftSerial_IR
Diff: SoftSerial_IR.cpp
- Revision:
- 15:8d343be3382d
- Parent:
- 14:dc766032cdd6
--- a/SoftSerial_IR.cpp Fri Dec 28 10:03:35 2018 +0000 +++ b/SoftSerial_IR.cpp Fri May 15 04:11:01 2020 +0000 @@ -1,17 +1,19 @@ -// Apply for Infrared LED and IR-Detector -// Modified by JH1PJL Dec. 28th, 2018 +// Modified by K.Arai / JH1PJL May 15th, 2020 #include "SoftSerial_IR.h" -SoftSerial_IR::SoftSerial_IR(PinName TX, PinName RX, const char* name) { +SoftSerial_IR::SoftSerial_IR(PinName TX, PinName RX, const char* name) +{ tx_en = rx_en = false; read_buffer = 0; if (TX != NC) { + //tx = new DigitalOut(TX); tx = new PwmOut(TX); tx_en = true; + tx->period(1.0f / 38000.0f); // PWM = 38kHz + //tx->write(1); tx->write(0.0f); tx_bit = -1; - tx->period(1.0f / 38000.0f); // PWM = 38kHz txticker.attach(this, &SoftSerial_IR::tx_handler); } if (RX != NC) { @@ -19,39 +21,32 @@ rx_en = true; out_valid = false; rxticker.attach(this, &SoftSerial_IR::rx_handler); - rx->fall(this, &SoftSerial_IR::rx_gpio_irq_handler); + rx->fall(callback(this, &SoftSerial_IR::rx_gpio_irq_handler)); } - + baud(2400); format(); - set_parameter(); } -SoftSerial_IR::~SoftSerial_IR() { - if (tx_en){ +SoftSerial_IR::~SoftSerial_IR() +{ + if (tx_en) { delete(tx); } - if (rx_en){ + if (rx_en) { delete(rx); } } -void SoftSerial_IR::baud(int baudrate) { +void SoftSerial_IR::baud(int baudrate) +{ bit_period = 1000000 / baudrate; } -void SoftSerial_IR::format(int bits, Parity parity, int stop_bits) { +void SoftSerial_IR::format(int bits, Parity parity, int stop_bits) +{ _bits = bits; _parity = parity; _stop_bits = stop_bits; - _total_bits = 1 + _bits + _stop_bits + (bool)_parity; + _total_bits = 2 + _bits + _stop_bits + (bool)_parity; } - -void SoftSerial_IR::set_parameter( - uint32_t tick_offset, - int32_t rx_detect_center_offset - ) -{ - timestamp_offset = tick_offset; - overhead_us_IR = rx_detect_center_offset; -}