Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed MxSS ISO layouts in QMK configuator (hopefully) #3352

Merged
merged 16 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed RGBLED color selection to work using hue and saturation rathe…
…r than RGB

Added code for LED state change on layer change
  • Loading branch information
MxBlu committed Jul 7, 2018
commit e6501eb73ebc9fd0ba97a12296b8df9e88bd669d
17 changes: 9 additions & 8 deletions keyboards/mxss/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include QMK_KEYBOARD_H
#include "rgblight.h"
#include "mxss_frontled.h"

// Predefined colors for layers
// Format: {red, green, blue}
// Format: {hue, saturation}
// {0, 0} to turn off the LED
// Add additional rows to handle more layers
LED_TYPE layer_colors[] = {
{0, 0, 0}, // Color for Layer 0
{255, 0, 0}, // Color for Layer 1
{0, 255, 0}, // Color for Layer 2
{0, 0, 255}, // Color for Layer 3
hs_set layer_colors[] = {
{0, 0}, // Color for Layer 0
{86, 255}, // Color for Layer 1
{36, 255}, // Color for Layer 2
{185, 255}, // Color for Layer 3
};
const size_t lc_size = sizeof(layer_colors) / sizeof(uint16_t);

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT( /* Base */
Expand All @@ -44,7 +46,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

const size_t array_size = sizeof(keymaps) / sizeof(uint16_t);

const uint16_t PROGMEM fn_actions[] = {

Expand Down
44 changes: 33 additions & 11 deletions keyboards/mxss/mxss.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

#include QMK_KEYBOARD_H
#include "tmk_core/common/eeprom.h"
#include "tmk_core/common/action_layer.h"
#include "rgblight.h"
#include "mxss_frontled.h"

// Variables for controlling front LED application
uint8_t fled_mode;
uint8_t fled_val;
uint8_t fled_mode; // Mode for front LEDs
uint8_t fled_val; // Brightness for front leds (0 - 255)
LED_TYPE fleds[2]; // Front LED rgb values for indicator mode use

LED_TYPE fleds[2];
extern hs_set layer_colors[];
extern const size_t lc_size;

void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up

// If EEPROM config exists, load it
if (eeprom_is_valid()) {
fled_config fled_conf;
Expand All @@ -38,16 +38,24 @@ void matrix_init_kb(void) {
// Else, default config
} else {
fled_mode = FLED_INDI;
fled_val = 3;
fled_val = 10 * FLED_VAL_STEP;
}

// Set default values for leds
setrgb(0, 0, 0, &fleds[0]);
setrgb(0, 0, 0, &fleds[1]);

// Enable capslock led if enabled on host
if (fled_mode == FLED_INDI && (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) {
setrgb(FLED_CAPS_R, FLED_CAPS_G, FLED_CAPS_B, &fleds[0]);
// Handle lighting for indicator mode
if (fled_mode == FLED_INDI) {
// Enable capslock led if enabled on host
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))
sethsv(FLED_CAPS_H, FLED_CAPS_S, fled_val, &fleds[0]);

// Determine and set colour of layer LED according to current layer
// if hue = sat = 0, leave LED off
uint8_t layer = biton32(layer_state);
if (layer < lc_size && !(layer_colors[layer].hue == 0 && layer_colors[layer].hue == 0))
sethsv(layer_colors[layer].hue, layer_colors[layer].sat, fled_val, &fleds[1]);
}

matrix_init_user();
Expand All @@ -70,14 +78,28 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
void led_set_kb(uint8_t usb_led) {
// Set indicator LED appropriately, whether it is used or not
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
setrgb(FLED_CAPS_R, FLED_CAPS_G, FLED_CAPS_B, &fleds[0]);
sethsv(FLED_CAPS_H, FLED_CAPS_S, fled_val, &fleds[0]);
} else {
setrgb(0, 0, 0, &fleds[0]);
}

led_set_user(usb_led);
}

uint32_t layer_state_set_kb(uint32_t state) {

// Determine and set colour of layer LED according to current layer
// if hue = sat = 0, leave LED off
uint8_t layer = biton32(state);

if (layer < lc_size && !(layer_colors[layer].hue == 0 && layer_colors[layer].hue == 0))
sethsv(layer_colors[layer].hue, layer_colors[layer].sat, fled_val, &fleds[1]);
else
setrgb(0, 0, 0, &fleds[1]);

return state;
}

// EEPROM Management

bool eeprom_is_valid(void)
Expand Down
11 changes: 7 additions & 4 deletions keyboards/mxss/mxss_frontled.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
#ifndef MXSS_FRONTLED_H
#define MXSS_FRONTLED_H

// RGBLED index for front LEDs
#define RGBLIGHT_FLED1 14
#define RGBLIGHT_FLED2 15

// Brightness increase step for front LEDs
#define FLED_VAL_STEP 8

// QMK never uses more then 32bytes of EEPROM, so our region starts there
// Magic value to verify the state of the EEPROM
#define EEPROM_MAGIC 0xC3E7
Expand All @@ -37,10 +41,9 @@
#define FLED_RGB 0b10
#define FLED_UNDEF 0b11

// Hard-coded color for capslock indicator in FLED_INDI mode
#define FLED_CAPS_R 255
#define FLED_CAPS_G 0
#define FLED_CAPS_B 0
// Hard-coded color for capslock indicator in FLED_INDI mode, H:0% S:100% = Red
#define FLED_CAPS_H 0
#define FLED_CAPS_S 255

typedef union {
uint8_t raw;
Expand Down
4 changes: 2 additions & 2 deletions keyboards/mxss/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ void rgblight_set(void) {
break;

case FLED_RGB:
sethsv(fled_hs[0].hue, fled_hs[0].sat, fled_val * 32, &led[RGBLIGHT_FLED1]);
sethsv(fled_hs[1].hue, fled_hs[1].sat, fled_val * 32, &led[RGBLIGHT_FLED2]);
sethsv(fled_hs[0].hue, fled_hs[0].sat, fled_val, &led[RGBLIGHT_FLED1]);
sethsv(fled_hs[1].hue, fled_hs[1].sat, fled_val, &led[RGBLIGHT_FLED2]);
break;

default:
Expand Down