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.h>
#include <Kaleidoscope-CycleTimeReport.h> #include <Kaleidoscope-CycleTimeReport.h>
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup (void) { void setup (void) {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use (&CycleTimeReport);
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -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
@ -39,10 +39,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip), Key_skip),
}; };
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&CycleTimeReport);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -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) {

@ -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
@ -21,18 +21,25 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace kaleidoscope { namespace kaleidoscope {
class CycleTimeReport : public KaleidoscopePlugin { class CycleTimeReport : public kaleidoscope::Plugin {
public: public:
CycleTimeReport() {} CycleTimeReport() {}
void begin(void) final; EventHandlerResult onSetup();
EventHandlerResult beforeEachCycle();
EventHandlerResult afterEachCycle();
static uint32_t average_loop_time; static uint32_t average_loop_time;
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private: private:
static uint32_t next_report_time_; static uint32_t next_report_time_;
static uint32_t loop_start_time_; static uint32_t loop_start_time_;
static void loopHook(bool post_clear);
}; };
} }

Loading…
Cancel
Save