Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 475fc4c2ae
commit ee78ff88a7

@ -23,10 +23,10 @@ the box, without any further configuration:
#include <Kaleidoscope.h>
#include <Kaleidoscope-CycleTimeReport.h>
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup (void) {
Serial.begin(9600);
Kaleidoscope.use (&CycleTimeReport);
Kaleidoscope.setup ();
}
```

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -39,10 +39,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip),
};
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup() {
Serial.begin(9600);
Kaleidoscope.use(&CycleTimeReport);
Kaleidoscope.setup();
}

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -23,34 +23,48 @@ uint32_t CycleTimeReport::next_report_time_;
uint32_t CycleTimeReport::loop_start_time_;
uint32_t CycleTimeReport::average_loop_time;
void CycleTimeReport::begin(void) {
Kaleidoscope.useLoopHook(loopHook);
EventHandlerResult CycleTimeReport::onSetup() {
next_report_time_ = millis() + 1000;
return EventHandlerResult::OK;
}
void CycleTimeReport::loopHook(bool post_clear) {
if (!post_clear)
return;
EventHandlerResult CycleTimeReport::beforeEachCycle() {
loop_start_time_ = micros();
return EventHandlerResult::OK;
}
if (loop_start_time_) {
uint32_t loop_time = micros() - loop_start_time_;
EventHandlerResult CycleTimeReport::afterEachCycle() {
uint32_t loop_time = micros() - loop_start_time_;
if (average_loop_time)
average_loop_time = (average_loop_time + loop_time) / 2;
else
average_loop_time = loop_time;
if (average_loop_time)
average_loop_time = (average_loop_time + loop_time) / 2;
else
average_loop_time = loop_time;
if (millis() >= next_report_time_) {
cycleTimeReport();
if (millis() >= next_report_time_) {
cycleTimeReport();
average_loop_time = 0;
next_report_time_ = millis() + 1000;
}
loop_start_time_ = 0;
} else {
loop_start_time_ = micros();
average_loop_time = 0;
next_report_time_ = millis() + 1000;
}
return EventHandlerResult::OK;
}
// 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) {

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -21,18 +21,25 @@
#include <Kaleidoscope.h>
namespace kaleidoscope {
class CycleTimeReport : public KaleidoscopePlugin {
class CycleTimeReport : public kaleidoscope::Plugin {
public:
CycleTimeReport() {}
void begin(void) final;
EventHandlerResult onSetup();
EventHandlerResult beforeEachCycle();
EventHandlerResult afterEachCycle();
static uint32_t average_loop_time;
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private:
static uint32_t next_report_time_;
static uint32_t loop_start_time_;
static void loopHook(bool post_clear);
};
}

Loading…
Cancel
Save