Merge pull request #1 from keyboardio/f/plugin-v2

Updated to use the new plugin APIs
pull/389/head
Gergely Nagy 7 years ago committed by GitHub
commit 11cc38d6bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,16 +23,17 @@ 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_) {
EventHandlerResult CycleTimeReport::afterEachCycle() {
uint32_t loop_time = micros() - loop_start_time_;
if (average_loop_time)
@ -46,11 +47,24 @@ void CycleTimeReport::loopHook(bool post_clear) {
average_loop_time = 0;
next_report_time_ = millis() + 1000;
}
loop_start_time_ = 0;
} else {
loop_start_time_ = micros();
}
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