Merge pull request #2 from keyboardio/f/macroification

Turn the plugin into a macro
pull/365/head
Jesse Vincent 8 years ago committed by GitHub
commit b06b2fcc73

@ -3,50 +3,63 @@
#include "KeyboardioFirmware.h"
#include "layers.h"
static uint8_t numpadIndex;
static uint8_t storedLEDMode;
static uint8_t us;
uint8_t NumLock_::previousLEDMode;
uint8_t NumLock_::us;
bool NumLock_::isActive;
byte NumLock_::row = 255, NumLock_::col = 255;
LEDNumlock::LEDNumlock (uint8_t numpadIdx) {
numpadIndex = numpadIdx;
NumLock_::NumLock_ (void) {
}
void
LEDNumlock::begin (void) {
NumLock_::begin (void) {
us = LEDControl.mode_add (this);
loop_hook_use (this->loopHook);
}
void
LEDNumlock::init (void) {
if (!Layer.isOn (numpadIndex)) {
NumLock_::init (void) {
if (!isActive) {
LEDControl.next_mode();
}
}
void
LEDNumlock::update (void) {
for (uint8_t i = 0; i < 44; i++) {
LEDControl.led_set_crgb_at(i, {0, 0, 0});
NumLock_::update (void) {
for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) {
Key k = Layer.lookup (r, c);
if (k.raw < Key_NumLock.raw || k.raw > Key_KeypadDot.raw)
continue;
LEDControl.led_set_crgb_at(r, c, {255, 0, 0});
}
for (uint8_t i = 44; i < LED_COUNT; i++) {
LEDControl.led_set_crgb_at(i, {255, 0, 0});
}
cRGB color = breath_compute ();
LEDControl.led_set_crgb_at (60, color);
if (row > ROWS || col > COLS)
return;
cRGB color = breath_compute();
LEDControl.led_set_crgb_at (row, col, color);
}
void
LEDNumlock::loopHook (bool postClear) {
if (!postClear)
return;
const macro_t *
NumLock_::toggle (byte row_, byte col_, uint8_t numPadLayer) {
row = row_;
col = col_;
if (!Layer.isOn (numpadIndex)) {
if (LEDControl.get_mode () != us)
storedLEDMode = LEDControl.get_mode ();
LEDControl.set_mode (storedLEDMode);
if (Layer.isOn (numPadLayer)) {
isActive = false;
LEDControl.set_mode (previousLEDMode);
Layer.off (numPadLayer);
} else {
isActive = true;
previousLEDMode = LEDControl.get_mode ();
LEDControl.set_mode (us);
Layer.on (numPadLayer);
}
return MACRO(T(NumLock), END);
}
NumLock_ NumLock;

@ -1,17 +1,28 @@
#pragma once
#include "Keyboardio-LEDControl.h"
#include "Keyboardio-Macros.h"
#include "LEDUtils.h"
class LEDNumlock : LEDMode {
#define TOGGLENUMLOCK 0
#define Key_ToggleNumlock M(TOGGLENUMLOCK)
class NumLock_ : LEDMode {
public:
LEDNumlock (uint8_t numpadIndex);
NumLock_ (void);
virtual void begin (void) final;
virtual void update (void) final;
virtual void init (void) final;
static const macro_t *toggle (byte row, byte col, uint8_t numPadLayer);
private:
static void loopHook (bool postClear);
static uint8_t previousLEDMode;
static uint8_t us;
static bool isActive;
static byte row, col;
};
extern NumLock_ NumLock;

Loading…
Cancel
Save