Skip to content

Commit

Permalink
reduced CPU load for WINX86 interface utilizing TrhoughSerial strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgitt committed Jul 2, 2017
1 parent 7a61550 commit bfe935c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion interfaces/WINX86/PJON_WINX86_Interface.h
Expand Up @@ -67,7 +67,7 @@
std::chrono::high_resolution_clock::now() - begin_ts std::chrono::high_resolution_clock::now() - begin_ts
).count(); ).count();
if(elapsed_usec >= delay_value) break; if(elapsed_usec >= delay_value) break;
std::this_thread::sleep_for(std::chrono::microseconds(1)); std::this_thread::sleep_for(std::chrono::microseconds(50));
} }
}; };


Expand Down
4 changes: 3 additions & 1 deletion strategies/ThroughSerial/ThroughSerial.h
Expand Up @@ -85,12 +85,14 @@ class ThroughSerial {


uint16_t receive_byte(uint32_t time_out = TS_BYTE_TIME_OUT) { uint16_t receive_byte(uint32_t time_out = TS_BYTE_TIME_OUT) {
uint32_t time = PJON_MICROS(); uint32_t time = PJON_MICROS();
while((uint32_t)(PJON_MICROS() - time) < time_out) while((uint32_t)(PJON_MICROS() - time) < time_out) {
if(PJON_SERIAL_AVAILABLE(serial)) { if(PJON_SERIAL_AVAILABLE(serial)) {
_last_reception_time = PJON_MICROS(); _last_reception_time = PJON_MICROS();
uint16_t read = (uint8_t)PJON_SERIAL_READ(serial); uint16_t read = (uint8_t)PJON_SERIAL_READ(serial);
if(read >= 0) return read; if(read >= 0) return read;
} }
delayMicroseconds(time_out / 10);
}
return PJON_FAIL; return PJON_FAIL;
}; };


Expand Down

0 comments on commit bfe935c

Please sign in to comment.