mirror of
https://github.com/keyboardio/Kaleidoscope.git
synced 2025-12-12 20:35:54 +01:00
LEDBrightnessControl plugin
Signed-off-by: Peter Davis <davispw@gmail.com>
This commit is contained in:
committed by
Jesse Vincent
parent
e6d040baae
commit
6c64f66004
55
examples/LEDs/LEDBrightnessControl/LEDBrightnessControl.ino
Normal file
55
examples/LEDs/LEDBrightnessControl/LEDBrightnessControl.ino
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- mode: c++ -*-
|
||||
* kaleidoscope::plugin::LEDBrightnessControl -- LED brightness up/down keys
|
||||
* Copyright (C) 2025 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Kaleidoscope.h>
|
||||
#include <Kaleidoscope-LEDControl.h>
|
||||
#include <Kaleidoscope-LEDBrightnessControl.h>
|
||||
#include <Kaleidoscope-LEDEffect-Rainbow.h>
|
||||
|
||||
// clang-format off
|
||||
KEYMAPS(
|
||||
[0] = KEYMAP_STACKED
|
||||
(
|
||||
Key_LEDBrightnessDown, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDBrightnessUp,
|
||||
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
|
||||
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
|
||||
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
|
||||
|
||||
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
||||
Key_NoKey,
|
||||
|
||||
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
|
||||
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
|
||||
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
||||
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
|
||||
|
||||
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
|
||||
Key_NoKey),
|
||||
)
|
||||
// clang-format on
|
||||
|
||||
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
|
||||
LEDBrightnessControl,
|
||||
LEDRainbowWaveEffect);
|
||||
|
||||
void setup() {
|
||||
Kaleidoscope.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Kaleidoscope.loop();
|
||||
}
|
||||
6
examples/LEDs/LEDBrightnessControl/sketch.json
Normal file
6
examples/LEDs/LEDBrightnessControl/sketch.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cpu": {
|
||||
"fqbn": "keyboardio:avr:model01",
|
||||
"port": ""
|
||||
}
|
||||
}
|
||||
1
examples/LEDs/LEDBrightnessControl/sketch.yaml
Normal file
1
examples/LEDs/LEDBrightnessControl/sketch.yaml
Normal file
@@ -0,0 +1 @@
|
||||
default_fqbn: keyboardio:avr:model01
|
||||
35
plugins/Kaleidoscope-LEDBrightnessControl/README.md
Normal file
35
plugins/Kaleidoscope-LEDBrightnessControl/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# LEDBrightnessControl
|
||||
|
||||
The `LEDBrightnessControl` plugin provides a way to change the brightness of all
|
||||
LEDs on a keyboard.
|
||||
|
||||
## Using the plugin
|
||||
|
||||
```c++
|
||||
#include <Kaleidoscope.h>
|
||||
#include <Kaleidoscope-EEPROM-Settings.h>
|
||||
#include <Kaleidoscope-LEDControl.h>
|
||||
#include <Kaleidoscope-LEDBrightnessControl.h>
|
||||
#include <Kaleidoscope-LEDEffect-Rainbow.h>
|
||||
#include <Kaleidoscope-FocusSerial.h>
|
||||
|
||||
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
|
||||
LEDControl,
|
||||
LEDOff,
|
||||
LEDRainbowEffect,
|
||||
LEDRainbowWaveEffect,
|
||||
Focus,
|
||||
LEDBrightnessControl);
|
||||
|
||||
void setup() {
|
||||
Kaleidoscope.setup();
|
||||
}
|
||||
```
|
||||
|
||||
### Use with `LEDBrightnessConfig`
|
||||
|
||||
`LEDBrightnessControl` does not persist brightness changes. `LEDBrightnessConfig` will reset the brightness on each restart to the configured default.
|
||||
|
||||
## Dependencies
|
||||
|
||||
* [Kaleidoscope-LEDControl](Kaleidoscope-LEDControl.md)
|
||||
@@ -0,0 +1,7 @@
|
||||
name=Kaleidoscope-LEDBrightnessControl
|
||||
version=0.0.0
|
||||
sentence=LED Brightness up/down keys
|
||||
maintainer=Kaleidoscope's Developers <jesse@keyboard.io>
|
||||
url=https://github.com/keyboardio/Kaleidoscope
|
||||
author=davispw
|
||||
paragraph=
|
||||
@@ -0,0 +1,25 @@
|
||||
/* Kaleidoscope-LEDBrightnessControl -- LED Brightness configuration, with EEPROM persistence
|
||||
* Copyright 2022-2025 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.
|
||||
*
|
||||
* Additional Permissions:
|
||||
* As an additional permission under Section 7 of the GNU General Public
|
||||
* License Version 3, you may link this software against a Vendor-provided
|
||||
* Hardware Specific Software Module under the terms of the MCU Vendor
|
||||
* Firmware Library Additional Permission Version 1.0.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kaleidoscope/plugin/LEDBrightnessControl.h" // IWYU pragma: export
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Kaleidoscope-LEDBrightnessControl -- LED brightness up/down keys
|
||||
* Copyright 2025 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.
|
||||
*
|
||||
* Additional Permissions:
|
||||
* As an additional permission under Section 7 of the GNU General Public
|
||||
* License Version 3, you may link this software against a Vendor-provided
|
||||
* Hardware Specific Software Module under the terms of the MCU Vendor
|
||||
* Firmware Library Additional Permission Version 1.0.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kaleidoscope/plugin/LEDBrightnessControl.h"
|
||||
|
||||
#include <Kaleidoscope-FocusSerial.h> // for Focus
|
||||
#include <stdint.h> // for uint8_t, uint16_t
|
||||
|
||||
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
|
||||
#include "kaleidoscope/keyswitch_state.h" // for keyToggledOn
|
||||
#include "kaleidoscope/keyswitch_state.h" // for keyToggledOn
|
||||
#include "kaleidoscope/plugin/LEDControl.h" // for LEDControl
|
||||
|
||||
namespace kaleidoscope {
|
||||
namespace plugin {
|
||||
|
||||
using ledbrightnesscontrol::BRIGHTNESS_INCREMENT;
|
||||
|
||||
EventHandlerResult LEDBrightnessControl::onKeyEvent(KeyEvent &event) {
|
||||
if ((event.key == Key_LEDBrightnessUp ||
|
||||
event.key == Key_LEDBrightnessDown) &&
|
||||
keyToggledOn(event.state)) {
|
||||
uint8_t brightness = LEDControl::getBrightness();
|
||||
if (event.key == Key_LEDBrightnessUp &&
|
||||
brightness <= 255 - BRIGHTNESS_INCREMENT) {
|
||||
brightness += BRIGHTNESS_INCREMENT;
|
||||
} else if (event.key == Key_LEDBrightnessDown &&
|
||||
brightness >= BRIGHTNESS_INCREMENT) {
|
||||
brightness -= BRIGHTNESS_INCREMENT;
|
||||
}
|
||||
LEDControl::setBrightness(brightness);
|
||||
}
|
||||
}
|
||||
|
||||
EventHandlerResult LEDBrightnessControl::onNameQuery() {
|
||||
return ::Focus.sendName(F("LEDBrightnessControl"));
|
||||
}
|
||||
|
||||
} // namespace plugin
|
||||
} // namespace kaleidoscope
|
||||
|
||||
kaleidoscope::plugin::LEDBrightnessControl LEDBrightnessControl;
|
||||
@@ -0,0 +1,52 @@
|
||||
/* Kaleidoscope-LEDBrightnessControl -- LED brightness up/down keys
|
||||
* Copyright 2022-2025 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.
|
||||
*
|
||||
* Additional Permissions:
|
||||
* As an additional permission under Section 7 of the GNU General Public
|
||||
* License Version 3, you may link this software against a Vendor-provided
|
||||
* Hardware Specific Software Module under the terms of the MCU Vendor
|
||||
* Firmware Library Additional Permission Version 1.0.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kaleidoscope-Ranges.h> // for LED_BRIGHTNESS_UP, LED_BRIGHTNESS_DOWN
|
||||
#include <stdint.h> // for uint8_t, uint16_t
|
||||
|
||||
#include "kaleidoscope/KeyEvent.h" // for KeyEvent
|
||||
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
|
||||
#include "kaleidoscope/plugin.h" // for Plugin
|
||||
#include "kaleidoscope/key_defs.h" // for Key
|
||||
|
||||
constexpr Key Key_LEDBrightnessUp = Key(kaleidoscope::ranges::LED_BRIGHTNESS_UP);
|
||||
constexpr Key Key_LEDBrightnessDown = Key(kaleidoscope::ranges::LED_BRIGHTNESS_DOWN);
|
||||
|
||||
namespace kaleidoscope {
|
||||
namespace plugin {
|
||||
|
||||
namespace ledbrightnesscontrol {
|
||||
constexpr uint8_t BRIGHTNESS_INCREMENT = 16;
|
||||
}
|
||||
|
||||
class LEDBrightnessControl : public kaleidoscope::Plugin {
|
||||
public:
|
||||
EventHandlerResult onNameQuery();
|
||||
EventHandlerResult onKeyEvent(KeyEvent &event);
|
||||
};
|
||||
|
||||
} // namespace plugin
|
||||
} // namespace kaleidoscope
|
||||
|
||||
extern kaleidoscope::plugin::LEDBrightnessControl LEDBrightnessControl;
|
||||
@@ -93,6 +93,8 @@ enum : uint16_t {
|
||||
CS_FIRST,
|
||||
CS_LAST = CS_FIRST + MAX_CS_KEYS,
|
||||
KEYCLICK_TOGGLE,
|
||||
LED_BRIGHTNESS_UP,
|
||||
LED_BRIGHTNESS_DOWN,
|
||||
|
||||
SAFE_START,
|
||||
KALEIDOSCOPE_SAFE_START = SAFE_START
|
||||
|
||||
@@ -67,6 +67,8 @@ class Issue1010 : public ::testing::Test {
|
||||
CS_FIRST,
|
||||
CS_LAST = CS_FIRST + MAX_CS_KEYS,
|
||||
KEYCLICK_TOGGLE,
|
||||
LED_BRIGHTNESS_UP,
|
||||
LED_BRIGHTNESS_DOWN,
|
||||
SAFE_START,
|
||||
KALEIDOSCOPE_SAFE_START = SAFE_START
|
||||
};
|
||||
@@ -150,6 +152,10 @@ TEST_F(Issue1010, RangesHaveNotChanged) {
|
||||
uint16_t(kaleidoscope::ranges::CS_LAST));
|
||||
ASSERT_EQ(uint16_t(Issue1010::KEYCLICK_TOGGLE),
|
||||
uint16_t(kaleidoscope::ranges::KEYCLICK_TOGGLE));
|
||||
ASSERT_EQ(uint16_t(Issue1010::LED_BRIGHTNESS_UP),
|
||||
uint16_t(kaleidoscope::ranges::LED_BRIGHTNESS_UP));
|
||||
ASSERT_EQ(uint16_t(Issue1010::LED_BRIGHTNESS_DOWN),
|
||||
uint16_t(kaleidoscope::ranges::LED_BRIGHTNESS_DOWN));
|
||||
ASSERT_EQ(uint16_t(Issue1010::SAFE_START),
|
||||
uint16_t(kaleidoscope::ranges::SAFE_START));
|
||||
ASSERT_EQ(uint16_t(Issue1010::KALEIDOSCOPE_SAFE_START),
|
||||
|
||||
Reference in New Issue
Block a user