avoid float -> int64 conversion #1977

cherry picking...
This commit is contained in:
rusefillc 2020-11-24 14:11:41 -05:00
parent ab8d6ff0df
commit bca35aa2f9
1 changed files with 8 additions and 21 deletions

View File

@ -65,34 +65,21 @@ bool isRunningBenchTest(void) {
static void runBench(brain_pin_e brainPin, OutputPin *output, float delayMs, float onTimeMs, float offTimeMs,
int count) {
int delaySt = delayMs < 1 ? 1 : TIME_MS2I(delayMs);
int onTimeSt = onTimeMs < 1 ? 1 : TIME_MS2I(onTimeMs);
int offTimeSt = offTimeMs < 1 ? 1 : TIME_MS2I(offTimeMs);
if (delaySt < 0) {
scheduleMsg(logger, "Invalid delay %.2f", delayMs);
return;
}
if (onTimeSt <= 0) {
scheduleMsg(logger, "Invalid onTime %.2f", onTimeMs);
return;
}
if (offTimeSt <= 0) {
scheduleMsg(logger, "Invalid offTime %.2f", offTimeMs);
return;
}
scheduleMsg(logger, "Running bench: ON_TIME=%.2f ms OFF_TIME=%.2fms Counter=%d", onTimeMs, offTimeMs, count);
int delayUs = MS2US(maxF(1, delayMs));
int onTimeUs = MS2US(maxF(1, onTimeMs));
int offTimeUs = MS2US(maxF(1, offTimeMs));
scheduleMsg(logger, "Running bench: ON_TIME=%.2f us OFF_TIME=%.2f us Counter=%d", onTimeUs, offTimeUs, count);
scheduleMsg(logger, "output on %s", hwPortname(brainPin));
if (delaySt != 0) {
chThdSleep(delaySt);
}
chThdSleepMicroseconds(delayUs);
isRunningBench = true;
for (int i = 0; i < count; i++) {
output->setValue(true);
chThdSleep(onTimeSt);
chThdSleepMicroseconds(onTimeUs);
output->setValue(false);
chThdSleep(offTimeSt);
chThdSleepMicroseconds(offTimeUs);
}
scheduleMsg(logger, "Done!");
isRunningBench = false;