Jordan Earls
/
pjon_testing
Testing getting PJON working on mbed https://github.com/gioblu/PJON
Diff: pjon.cpp
- Revision:
- 2:5648483c5dbc
- Parent:
- 1:bd0ee507dd4c
--- a/pjon.cpp Sun Jan 10 09:41:00 2016 +0000 +++ b/pjon.cpp Sat Jan 16 15:51:23 2016 +0000 @@ -222,11 +222,22 @@ /* Receive byte for an initial BIT_SPACER bit + standard bit total duration. (freak condition used to avoid micros() overflow bug) */ - while(response == FAIL && !(t.read_us() >= BIT_SPACER + BIT_WIDTH)) + int time = 0; + while(response == FAIL && !(t.read_us() >= BIT_SPACER + BIT_WIDTH)){ response = this->receive_byte(); +if(t.read_us() >= 101 && t.read_us() <= time){ + DigitalOut myled2(LED4); + myled2 = 1; +} +time = t.read_us(); + } t.stop(); - if (response == ACK || response == NAK) return response; + if (response == ACK || response == NAK) { + DigitalOut myled(LED2); + myled = 1; + return response; + } return FAIL; }; @@ -361,13 +372,16 @@ /* Do nothing until the pin stops to be HIGH or passed more time than BIT_SPACER duration (freak condition used to avoid micros() overflow bug) */ //MBED needed? while (_input_pin && !(t.read_us() >= BIT_SPACER)); + /* Save how much time passed */ time = t.read_us(); /* is for sure less than BIT_SPACER, and if is more than ACCEPTANCE (a minimum HIGH duration) and what is coming after is a LOW bit probably a byte is coming so try to receive it. */ - t.stop(); + t.stop(); if(time >= ACCEPTANCE && !this->syncronization_bit()){ + DigitalOut myled(LED3); + myled = 1; return (int)this->read_byte(); }