From 6c7aa8f7f32ddce4e07280a6e81573fe1bb276be Mon Sep 17 00:00:00 2001 From: Florian Fleissner Date: Thu, 2 May 2019 09:45:19 +0200 Subject: [PATCH] Refactored LEDMode related classes This commit does the following: * factor out class AccessTransientLEDMode to an individual file * factor out class LEDModeInterface to individual files * fix the file header comment in LEDMode.h Signed-off-by: Florian Fleissner --- .../plugin/AccessTransientLEDMode.h | 40 ++++++++++++++++++ src/kaleidoscope/plugin/LEDMode.h | 40 ++---------------- .../{LEDMode.cpp => LEDModeInterface.cpp} | 5 +-- src/kaleidoscope/plugin/LEDModeInterface.h | 42 +++++++++++++++++++ 4 files changed, 87 insertions(+), 40 deletions(-) create mode 100644 src/kaleidoscope/plugin/AccessTransientLEDMode.h rename src/kaleidoscope/plugin/{LEDMode.cpp => LEDModeInterface.cpp} (84%) create mode 100644 src/kaleidoscope/plugin/LEDModeInterface.h diff --git a/src/kaleidoscope/plugin/AccessTransientLEDMode.h b/src/kaleidoscope/plugin/AccessTransientLEDMode.h new file mode 100644 index 00000000..5cb353df --- /dev/null +++ b/src/kaleidoscope/plugin/AccessTransientLEDMode.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017-2018 Keyboard.io, Inc. + * + * 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 the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +namespace kaleidoscope { +namespace plugin { + +class AccessTransientLEDMode { + public: + + // This method is called when a plugin's LED mode is activated. + // Derived plugins may reimplement it to store the id of their + // exported LED mode. A plugin can thus check + // whether their LED mode is currently active. + // + void registerLEDModeActivated(uint8_t led_mode_id) { + led_mode_id_ = led_mode_id; + } + + protected: + + uint8_t led_mode_id_ = 255; /* 255 means uninitialized */ +}; + +} // end namespace plugin +} // end namespace kaleidoscope diff --git a/src/kaleidoscope/plugin/LEDMode.h b/src/kaleidoscope/plugin/LEDMode.h index 2459ba95..e734046b 100644 --- a/src/kaleidoscope/plugin/LEDMode.h +++ b/src/kaleidoscope/plugin/LEDMode.h @@ -1,4 +1,4 @@ -/* Kaleidoscope-LEDControl - LED control plugin for Kaleidoscope +/* Kaleidoscope-LEDMode - LED modes for Kaleidoscope * Copyright (C) 2017-2018 Keyboard.io, Inc. * * This program is free software: you can redistribute it and/or modify it under @@ -17,6 +17,8 @@ #pragma once #include "kaleidoscope/plugin.h" +#include "kaleidoscope/plugin/AccessTransientLEDMode.h" +#include "kaleidoscope/plugin/LEDModeInterface.h" namespace kaleidoscope { @@ -27,42 +29,6 @@ class LEDModeManager; namespace plugin { -class LEDModeInterface { - public: - - void activate(); - - // This auxiliary class helps to generate a verbose error message - // in case that there is no TransientLEDMode typedef or nested - // class present in a derived class of LEDModeInterface. - // - struct _____LEDModeInterface_derived_class_is_missing_a_TransientLEDMode_typedef_or_nested_class_____ {}; - typedef _____LEDModeInterface_derived_class_is_missing_a_TransientLEDMode_typedef_or_nested_class_____ NoLEDMode; - - // By redefining TransientLEDMode, derived plugins export - // a LED mode that becomes part of the set of LED modes whose - // lifetime is handled dynamically. - // - typedef NoLEDMode DynamicLEDMode; -}; - -class AccessTransientLEDMode { - public: - - // This method is called when a plugin's LED mode is activated. - // Derived plugins may reimplement it to store the id of their - // exported LED mode. A plugin can thus check - // whether their LED mode is currently active. - // - void registerLEDModeActivated(uint8_t led_mode_id) { - led_mode_id_ = led_mode_id; - } - - protected: - - uint8_t led_mode_id_ = 255; /* 255 means uninitialized */ -}; - /** Base class for LED modes. * * LED modes are a special kind of plugin, they are in charge of updating LED diff --git a/src/kaleidoscope/plugin/LEDMode.cpp b/src/kaleidoscope/plugin/LEDModeInterface.cpp similarity index 84% rename from src/kaleidoscope/plugin/LEDMode.cpp rename to src/kaleidoscope/plugin/LEDModeInterface.cpp index ed422ab0..6205f0eb 100644 --- a/src/kaleidoscope/plugin/LEDMode.cpp +++ b/src/kaleidoscope/plugin/LEDModeInterface.cpp @@ -1,4 +1,4 @@ -/* Kaleidoscope-LEDControl - LED control plugin for Kaleidoscope +/* * Copyright (C) 2017-2018 Keyboard.io, Inc. * * This program is free software: you can redistribute it and/or modify it under @@ -15,9 +15,8 @@ */ -#include +#include #include -#include namespace kaleidoscope { namespace plugin { diff --git a/src/kaleidoscope/plugin/LEDModeInterface.h b/src/kaleidoscope/plugin/LEDModeInterface.h new file mode 100644 index 00000000..aca5f7ac --- /dev/null +++ b/src/kaleidoscope/plugin/LEDModeInterface.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017-2018 Keyboard.io, Inc. + * + * 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 the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +namespace kaleidoscope { +namespace plugin { + +class LEDModeInterface { + public: + + void activate(); + + // This auxiliary class helps to generate a verbose error message + // in case that there is no TransientLEDMode typedef or nested + // class present in a derived class of LEDModeInterface. + // + struct _____LEDModeInterface_derived_class_is_missing_a_TransientLEDMode_typedef_or_nested_class_____ {}; + typedef _____LEDModeInterface_derived_class_is_missing_a_TransientLEDMode_typedef_or_nested_class_____ NoLEDMode; + + // By redefining TransientLEDMode, derived plugins export + // a LED mode that becomes part of the set of LED modes whose + // lifetime is handled dynamically. + // + typedef NoLEDMode DynamicLEDMode; +}; + +} // end namespace plugin +} // end namespace kaleidoscope