Skip to content

Commit

Permalink
Merge pull request #649 from kareltucek/control_perkeyrgb2
Browse files Browse the repository at this point in the history
Allow overriding key rgb.
  • Loading branch information
mondalaci authored Jul 25, 2023
2 parents 685f626 + 7217c9b commit ac84c00
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc-dev/reference-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ The following grammar is supported:
COMMAND = set keymapAction.LAYERID.KEYID ACTION
COMMAND = set backlight.strategy { functional | constantRgb | perKeyRgb }
COMMAND = set backlight.constantRgb.rgb <number 0-255 (NUMBER)> <number 0-255 (NUMBER)> <number 0-255 (NUMBER)><number 0-255 (NUMBER)>
COMMAND = set backlight.keyRgb.LAYERID.KEYID <number 0-255 (NUMBER)> <number 0-255 (NUMBER)> <number 0-255 (NUMBER)>
COMMAND = set leds.enabled BOOLEAN
COMMAND = set leds.brightness <0-1 multiple of default (FLOAT)>
COMMAND = set leds.fadeTimeout <seconds to fade after (NUMBER)>
Expand Down Expand Up @@ -558,6 +559,7 @@ For the purpose of toggling functionality on and off, and for global constants m
- backlight:
- `backlight.strategy { functional | constantRgb | perKeyRgb }` sets backlight strategy.
- `backlight.constantRgb.rgb NUMBER NUMBER NUMBER` allows setting custom constant colour for entire keyboard. E.g.: `set backlight.strategy constantRgb; set backlight.constantRgb.rgb 255 0 0` to make entire keyboard shine red.
- `backlight.keyRgb.LAYERID.KEYID NUMBER NUMBER NUMBER` allows overriding color of the key. This override will last until reload of keymap and will apply to all backlight strategies.

- general led configuration:
- `leds.enabled BOOLEAN` turns on/off all keyboard leds: i.e., backlight, indicator leds, segment display
Expand Down
6 changes: 6 additions & 0 deletions right/src/config_parser/parse_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ static void parseKeyActionColor(key_action_t *keyAction, config_buffer_t *buffer
keyAction->color.red = ReadUInt8(buffer);
keyAction->color.green = ReadUInt8(buffer);
keyAction->color.blue = ReadUInt8(buffer);
keyAction->colorOverridden = false;
} else {
keyAction->color.red = 0;
keyAction->color.green = 0;
keyAction->color.blue = 0;
keyAction->colorOverridden = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions right/src/key_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
} ATTR_PACKED playMacro;
};
rgb_t color;
bool colorOverridden;
} ATTR_PACKED key_action_t;

typedef struct {
Expand Down
13 changes: 11 additions & 2 deletions right/src/ledmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ static void setPerKeyRGB(const rgb_t* color, uint8_t slotId, uint8_t keyId)
static void updateLedsByConstantRgbStrategy() {
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
setPerKeyRGB(&LedMap_ConstantRGB, slotId, keyId);
key_action_t *keyAction = &CurrentKeymap[ActiveLayer][slotId][keyId];
if (keyAction->colorOverridden) {
setPerKeyRGB(&keyAction->color, slotId, keyId);
} else {
setPerKeyRGB(&LedMap_ConstantRGB, slotId, keyId);
}
}
}
}
Expand Down Expand Up @@ -202,7 +207,11 @@ static void updateLedsByFunctionalStrategy() {
break;
}

setPerKeyRGB(&KeyActionColors[keyActionColor], slotId, keyId);
if (keyAction->colorOverridden) {
setPerKeyRGB(&keyAction->color, slotId, keyId);
} else {
setPerKeyRGB(&KeyActionColors[keyActionColor], slotId, keyId);
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions right/src/macro_set_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,34 @@ static void backlightStrategy(const char* arg1, const char *textEnd)
}
}

static void keyRgb(const char* arg1, const char *textEnd)
{
const char* arg2 = proceedByDot(arg1, textEnd);

layer_id_t layerId = Macros_ParseLayerId(arg1, textEnd);
uint8_t keyId = Macros_ParseInt(arg2, textEnd, NULL);
const char* r = NextTok(arg2, textEnd);
const char* g = NextTok(r, textEnd);
const char* b = NextTok(g, textEnd);
rgb_t rgb;
rgb.red = Macros_ParseInt(r, textEnd, NULL);
rgb.green = Macros_ParseInt(g, textEnd, NULL);
rgb.blue = Macros_ParseInt(b, textEnd, NULL);

if (Macros_ParserError) {
return;
}

uint8_t slotIdx = keyId/64;
uint8_t inSlotIdx = keyId%64;

CurrentKeymap[layerId][slotIdx][inSlotIdx].colorOverridden = true;
CurrentKeymap[layerId][slotIdx][inSlotIdx].color = rgb;

LedSlaveDriver_UpdateLeds();
}


static void constantRgb(const char* arg1, const char *textEnd)
{
if (TokenMatches(arg1, textEnd, "rgb")) {
Expand Down Expand Up @@ -331,6 +359,9 @@ static void backlight(const char* arg1, const char *textEnd)
else if (TokenMatches(arg1, textEnd, "constantRgb")) {
constantRgb(proceedByDot(arg1, textEnd), textEnd);
}
else if (TokenMatches(arg1, textEnd, "keyRgb")) {
keyRgb(proceedByDot(arg1, textEnd), textEnd);
}
else {
Macros_ReportError("parameter not recognized:", arg1, textEnd);
}
Expand Down

0 comments on commit ac84c00

Please sign in to comment.