Add a LEDMode based on AlphaSquare.

The new singleton objects implements a LED mode where each pressed key
will light up the appropriate symbol on the LEDs, on the side it was
pressed on. We use different timers for each half.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago committed by Gergely Nagy
parent ca1cd7c590
commit 29841ec02e

@ -75,9 +75,9 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
} }
void setup () { void setup () {
Kaleidoscope.setup (KEYMAP_SIZE); Kaleidoscope.setup ();
Kaleidoscope.use (&LEDControl, &AlphaSquare, &Macros, NULL); USE_PLUGINS (&AlphaSquare, &AlphaSquareEffect, &Macros);
AlphaSquare.color = { 0xcb, 0xc0, 0xff }; AlphaSquare.color = { 0xcb, 0xc0, 0xff };
} }

@ -19,3 +19,4 @@
#pragma once #pragma once
#include <Kaleidoscope/LED-AlphaSquare.h> #include <Kaleidoscope/LED-AlphaSquare.h>
#include <Kaleidoscope/AlphaSquare-Effect.h>

@ -0,0 +1,76 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-AlphaSquare -- 4x4 pixel LED alphabet
* Copyright (C) 2017 Gergely Nagy
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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-LED-AlphaSquare.h>
namespace KaleidoscopePlugins {
namespace LEDEffects {
uint16_t AlphaSquareEffect::length = 200;
uint32_t AlphaSquareEffect::endTimeLeft, AlphaSquareEffect::endTimeRight;
Key AlphaSquareEffect::lastKeyLeft, AlphaSquareEffect::lastKeyRight;
AlphaSquareEffect::AlphaSquareEffect (void) {
}
void
AlphaSquareEffect::begin (void) {
Kaleidoscope.useEventHandlerHook (eventHandlerHook);
LEDMode::begin ();
}
void
AlphaSquareEffect::update (void) {
if (endTimeLeft && millis () > endTimeLeft) {
::AlphaSquare.clear (lastKeyLeft);
endTimeLeft = 0;
}
if (endTimeRight && millis () > endTimeRight) {
::AlphaSquare.clear (lastKeyRight);
endTimeRight = 0;
}
}
Key
AlphaSquareEffect::eventHandlerHook (Key key, byte row, byte col, uint8_t keyState) {
if (keyState & INJECTED)
return key;
if (key < Key_A || key > Key_0)
return key;
if (!key_is_pressed (keyState))
return key;
uint8_t displayCol = 2;
if (col < COLS / 2) {
lastKeyLeft = key;
endTimeLeft = millis () + length;
} else {
lastKeyRight = key;
endTimeRight = millis () + length;
displayCol = 10;
}
::AlphaSquare.display (key, displayCol);
return key;
}
};
};
KaleidoscopePlugins::LEDEffects::AlphaSquareEffect AlphaSquareEffect;

@ -0,0 +1,43 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-AlphaSquare -- 4x4 pixel LED alphabet
* Copyright (C) 2017 Gergely Nagy
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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.h>
#include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins {
namespace LEDEffects {
class AlphaSquareEffect : public LEDMode {
public:
AlphaSquareEffect (void);
virtual void begin (void) final;
virtual void update (void) final;
static uint16_t length;
private:
static uint32_t endTimeLeft, endTimeRight;
static Key lastKeyLeft, lastKeyRight;
static Key eventHandlerHook (Key key, uint8_t row, uint8_t col, uint8_t keyState);
};
};
};
extern KaleidoscopePlugins::LEDEffects::AlphaSquareEffect AlphaSquareEffect;

@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>

Loading…
Cancel
Save