Implement reactive lighting effects (#18)

This commit is contained in:
Darkhan
2021-09-12 09:26:27 +02:00
committed by bwisn
parent fb5829fa31
commit b63980e0ef
3 changed files with 36 additions and 0 deletions
+4
View File
@@ -89,6 +89,10 @@ void matrix_scan_kb() {
*/
bool OVERRIDE process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
if (AP2_LED_ENABLED && AP2_LED_DYNAMIC_PROFILE) {
annepro2LedForwardKeypress(record->event.key.row, record->event.key.col);
}
switch (keycode) {
case KC_AP2_BT1:
annepro2_ble_broadcast(0);
+26
View File
@@ -2,14 +2,19 @@
#include "annepro2.h"
#include "qmk_ap2_led.h"
bool AP2_LED_ENABLED = false;
bool AP2_LED_DYNAMIC_PROFILE = false;
void annepro2LedDisable(void)
{
sdPut(&SD0, CMD_LED_OFF);
AP2_LED_ENABLED = false;
}
void annepro2LedEnable(void)
{
sdPut(&SD0, CMD_LED_ON);
AP2_LED_ENABLED = true;
}
void annepro2LedUpdate(uint8_t row, uint8_t col)
@@ -31,6 +36,8 @@ void annepro2LedSetProfile(uint8_t prof)
{
sdPut(&SD0, CMD_LED_SET_PROFILE);
sdPut(&SD0, prof);
uint8_t buf = sdGet(&SD0);
AP2_LED_DYNAMIC_PROFILE = buf;
}
uint8_t annepro2LedGetProfile()
@@ -52,6 +59,8 @@ uint8_t annepro2LedGetNumProfiles()
void annepro2LedNextProfile()
{
sdPut(&SD0, CMD_LED_NEXT_PROFILE);
uint8_t buf = sdGet(&SD0);
AP2_LED_DYNAMIC_PROFILE = buf;
}
void annepro2LedNextIntensity()
@@ -94,3 +103,20 @@ void annepro2LedResetForegroundColor()
annepro2LedSetProfile(currentProfile);
}
/*
* If enabled, this data is sent to LED MCU on every keypress.
* In order to improve performance, both row and column values
* are packed into a single byte.
* Row range is [0, 4] and requires only 3 bits.
* Column range is [0, 13] and requires 4 bits.
*
* In order to differentiate this command from regular commands,
* the leftmost bit is set to 1 (0b10000000).
* Following it are 3 bits of row and 4 bits of col.
* 1 + 3 + 4 = 8 bits - only a single byte is sent for every keypress.
*/
void annepro2LedForwardKeypress(uint8_t row, uint8_t col)
{
uint8_t msg = 0b10000000 | (row << 4) | col;
sdPut(&SD0, msg);
}
+6
View File
@@ -14,6 +14,7 @@
#define CMD_LED_NEXT_INTENSITY 0xC
#define CMD_LED_NEXT_ANIMATION_SPEED 0xD
#define CMD_LED_SET_FOREGROUND_COLOR 0xE
#define CMD_LED_KEYPRESS 0xF
void annepro2LedDisable(void);
void annepro2LedEnable(void);
@@ -30,3 +31,8 @@ void annepro2LedNextIntensity(void);
void annepro2LedNextAnimationSpeed(void);
void annepro2LedSetForegroundColor(uint8_t red, uint8_t green, uint8_t blue);
void annepro2LedResetForegroundColor(void);
void annepro2LedForwardKeypress(uint8_t row, uint8_t col);
extern bool AP2_LED_ENABLED;
extern bool AP2_LED_DYNAMIC_PROFILE;