|
|
@ -1,6 +1,6 @@
|
|
|
|
/* -*- mode: c++ -*-
|
|
|
|
/* -*- mode: c++ -*-
|
|
|
|
* Kaleidoscope-CycleTimeReport -- Scan cycle time reporting
|
|
|
|
* Kaleidoscope-CycleTimeReport -- Scan cycle time reporting
|
|
|
|
* Copyright (C) 2017 Gergely Nagy
|
|
|
|
* Copyright (C) 2017, 2018 Gergely Nagy
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
@ -23,16 +23,17 @@ uint32_t CycleTimeReport::next_report_time_;
|
|
|
|
uint32_t CycleTimeReport::loop_start_time_;
|
|
|
|
uint32_t CycleTimeReport::loop_start_time_;
|
|
|
|
uint32_t CycleTimeReport::average_loop_time;
|
|
|
|
uint32_t CycleTimeReport::average_loop_time;
|
|
|
|
|
|
|
|
|
|
|
|
void CycleTimeReport::begin(void) {
|
|
|
|
EventHandlerResult CycleTimeReport::onSetup() {
|
|
|
|
Kaleidoscope.useLoopHook(loopHook);
|
|
|
|
|
|
|
|
next_report_time_ = millis() + 1000;
|
|
|
|
next_report_time_ = millis() + 1000;
|
|
|
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CycleTimeReport::loopHook(bool post_clear) {
|
|
|
|
EventHandlerResult CycleTimeReport::beforeEachCycle() {
|
|
|
|
if (!post_clear)
|
|
|
|
loop_start_time_ = micros();
|
|
|
|
return;
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (loop_start_time_) {
|
|
|
|
EventHandlerResult CycleTimeReport::afterEachCycle() {
|
|
|
|
uint32_t loop_time = micros() - loop_start_time_;
|
|
|
|
uint32_t loop_time = micros() - loop_start_time_;
|
|
|
|
|
|
|
|
|
|
|
|
if (average_loop_time)
|
|
|
|
if (average_loop_time)
|
|
|
@ -46,11 +47,24 @@ void CycleTimeReport::loopHook(bool post_clear) {
|
|
|
|
average_loop_time = 0;
|
|
|
|
average_loop_time = 0;
|
|
|
|
next_report_time_ = millis() + 1000;
|
|
|
|
next_report_time_ = millis() + 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loop_start_time_ = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
loop_start_time_ = micros();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Deprecated V1 APIs
|
|
|
|
|
|
|
|
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
|
|
|
|
|
|
|
|
void CycleTimeReport::begin() {
|
|
|
|
|
|
|
|
Kaleidoscope.useLoopHook(legacyLoopHook);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CycleTimeReport::legacyLoopHook(bool is_post_clear) {
|
|
|
|
|
|
|
|
if (is_post_clear)
|
|
|
|
|
|
|
|
::CycleTimeReport.afterEachCycle();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
::CycleTimeReport.beforeEachCycle();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
__attribute__((weak)) void cycleTimeReport(void) {
|
|
|
|
__attribute__((weak)) void cycleTimeReport(void) {
|
|
|
|