diff --git a/examples/LEDs/LED-Brightness/LED-Brightness.ino b/examples/LEDs/LED-Brightness/LED-Brightness.ino new file mode 100644 index 00000000..5f184150 --- /dev/null +++ b/examples/LEDs/LED-Brightness/LED-Brightness.ino @@ -0,0 +1,77 @@ +/* -*- mode: c++ -*- + * LED-Brightness.ino -- Example to show LED brightness control + * Copyright (C) 2020 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 . + */ + +#include +#include +#include + +// *INDENT-OFF* +KEYMAPS( + [0] = KEYMAP_STACKED + ( + Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, + 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, + M(0), + + 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, + M(1)), +) +// *INDENT-ON* + +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + Macros, + LEDRainbowWaveEffect); + +const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { + if (keyToggledOn(keyState)) { + uint8_t brightness = LEDControl.getBrightness(); + + if (macroIndex == 0) { + if (brightness > 10) + brightness -= 10; + else + brightness = 0; + } else if (macroIndex == 1) { + if (brightness < 245) + brightness += 10; + else + brightness = 255; + } + + LEDControl.setBrightness(brightness); + } + + return MACRO_NONE; +} + +void setup() { + Kaleidoscope.setup(); + LEDRainbowWaveEffect.brightness(255); +} + +void loop() { + Kaleidoscope.loop(); +} diff --git a/src/kaleidoscope/device/dygma/Raise.cpp b/src/kaleidoscope/device/dygma/Raise.cpp index 42465d45..012ba8e3 100644 --- a/src/kaleidoscope/device/dygma/Raise.cpp +++ b/src/kaleidoscope/device/dygma/Raise.cpp @@ -1,7 +1,7 @@ /* -*- mode: c++ -*- * kaleidoscope::device::dygma::Raise -- Kaleidoscope device plugin for Dygma Raise - * Copyright (C) 2017-2019 Keyboard.io, Inc - * Copyright (C) 2017-2019 Dygma Lab S.L. + * Copyright (C) 2017-2020 Keyboard.io, Inc + * Copyright (C) 2017-2020 Dygma Lab S.L. * * 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 @@ -144,6 +144,19 @@ constexpr uint8_t RaiseLEDDriver::led_map[][RaiseLEDDriverProps::led_count + 1]; constexpr uint8_t RaiseLEDDriverProps::key_led_map[]; +void RaiseLEDDriver::setBrightness(uint8_t brightness) { + RaiseHands::leftHand.setBrightness(brightness); + RaiseHands::rightHand.setBrightness(brightness); + for (uint8_t i = 0; i < LED_BANKS; i++) { + isLEDChangedLeft[i] = true; + isLEDChangedRight[i] = true; + } +} + +uint8_t RaiseLEDDriver::getBrightness() { + return RaiseHands::leftHand.getBrightness(); +} + void RaiseLEDDriver::syncLeds() { // left and right sides for (uint8_t i = 0; i < LED_BANKS; i ++) { diff --git a/src/kaleidoscope/device/dygma/Raise.h b/src/kaleidoscope/device/dygma/Raise.h index 5d59edc1..921da20e 100644 --- a/src/kaleidoscope/device/dygma/Raise.h +++ b/src/kaleidoscope/device/dygma/Raise.h @@ -1,7 +1,7 @@ /* -*- mode: c++ -*- * kaleidoscope::device::dygma::Raise -- Kaleidoscope device plugin for Dygma Raise - * Copyright (C) 2017-2019 Keyboard.io, Inc - * Copyright (C) 2017-2019 Dygma Lab S.L. + * Copyright (C) 2017-2020 Keyboard.io, Inc + * Copyright (C) 2017-2020 Dygma Lab S.L. * * 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 @@ -61,6 +61,8 @@ class RaiseLEDDriver : public kaleidoscope::driver::led::Base brightness_adjustment_) + c -= brightness_adjustment_; + else + c = 0; + + data[i + 1] = pgm_read_byte(&gamma8[c]); } uint8_t result = twi_.writeTo(data, ELEMENTS(data)); } -void Hand::setAllLEDsTo(cRGB color) { - uint8_t data[] = {TWI_CMD_LED_SET_ALL_TO, - pgm_read_byte(&gamma8[color.r]), - pgm_read_byte(&gamma8[color.g]), - pgm_read_byte(&gamma8[color.b]) - }; - twi_.writeTo(data, ELEMENTS(data)); -} - -void Hand::setOneLEDTo(byte led, cRGB color) { - uint8_t data[] = {TWI_CMD_LED_SET_ONE_TO, - led, - pgm_read_byte(&gamma8[color.r]), - pgm_read_byte(&gamma8[color.g]), - pgm_read_byte(&gamma8[color.b]) - }; - twi_.writeTo(data, ELEMENTS(data)); -} - } } } diff --git a/src/kaleidoscope/device/dygma/raise/Hand.h b/src/kaleidoscope/device/dygma/raise/Hand.h index 261fb6ed..bc2e3a5b 100644 --- a/src/kaleidoscope/device/dygma/raise/Hand.h +++ b/src/kaleidoscope/device/dygma/raise/Hand.h @@ -74,8 +74,6 @@ class Hand { bool moreKeysWaiting(); void sendLEDData(); void sendLEDBank(uint8_t bank); - void setOneLEDTo(byte led, cRGB color); - void setAllLEDsTo(cRGB color); keydata_t getKeyData(); bool readKeys(); uint8_t controllerAddress(); @@ -83,10 +81,18 @@ class Hand { return twi_.crc_errors(); } + void setBrightness(uint8_t brightness) { + brightness_adjustment_ = 255 - brightness; + } + uint8_t getBrightness() { + return 255 - brightness_adjustment_; + } + LEDData_t led_data; bool online = false; private: + uint8_t brightness_adjustment_ = 0; int ad01_; TWI twi_; keydata_t key_data_; diff --git a/src/kaleidoscope/device/keyboardio/Imago.cpp b/src/kaleidoscope/device/keyboardio/Imago.cpp index 8721016f..e5e965bd 100644 --- a/src/kaleidoscope/device/keyboardio/Imago.cpp +++ b/src/kaleidoscope/device/keyboardio/Imago.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Keyboardio-Imago -- Imago hardware support for Kaleidoscope - * Copyright (C) 2018, 2019 Keyboard.io, Inc + * Copyright (C) 2018, 2019, 2020 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU General Public License as @@ -98,6 +98,15 @@ cRGB ImagoLEDDriver::getCrgbAt(uint8_t i) { return led_data[i]; } +uint8_t ImagoLEDDriver::adjustBrightness(uint8_t value) { + if (value > brightness_adjustment_) + value -= brightness_adjustment; + else + value = 0; + + return value; +} + void ImagoLEDDriver::syncLeds() { // if (!isLEDChanged) // return; @@ -110,9 +119,9 @@ void ImagoLEDDriver::syncLeds() { selectRegister(LED_REGISTER_DATA0); for (auto i = 1; i < LED_REGISTER_DATA0_SIZE; i += 3) { - data[i] = led_data[last_led].b; - data[i + 1] = led_data[last_led].g; - data[i + 2] = led_data[last_led].r; + data[i] = adjustBrightness(led_data[last_led].b); + data[i + 1] = adjustBrightness(led_data[last_led].g); + data[i + 2] = adjustBrightness(led_data[last_led].r); last_led++; } @@ -130,9 +139,9 @@ void ImagoLEDDriver::syncLeds() { selectRegister(LED_REGISTER_DATA1); for (auto i = 1; i < LED_REGISTER_DATA1_SIZE; i += 3) { - data[i] = led_data[last_led].b; - data[i + 1] = led_data[last_led].g; - data[i + 2] = led_data[last_led].r; + data[i] = adjustBrightness(led_data[last_led].b); + data[i + 1] = adjustBrightness(led_data[last_led].g); + data[i + 2] = adjustBrightness(led_data[last_led].r); last_led++; } diff --git a/src/kaleidoscope/device/keyboardio/Imago.h b/src/kaleidoscope/device/keyboardio/Imago.h index b6801ede..ccf45943 100644 --- a/src/kaleidoscope/device/keyboardio/Imago.h +++ b/src/kaleidoscope/device/keyboardio/Imago.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Keyboardio-Imago -- Imago hardware support for Kaleidoscope - * Copyright (C) 2018, 2019 Keyboard.io, Inc + * Copyright (C) 2018, 2019, 2020 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU General Public License as @@ -58,12 +58,22 @@ class ImagoLEDDriver : public kaleidoscope::driver::led::Base