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

@ -1,17 +1,28 @@
#pragma once #pragma once
#include "Keyboardio-LEDControl.h" #include "Keyboardio-LEDControl.h"
#include "Keyboardio-Macros.h"
#include "LEDUtils.h" #include "LEDUtils.h"
class LEDNumlock : LEDMode { #define TOGGLENUMLOCK 0
#define Key_ToggleNumlock M(TOGGLENUMLOCK)
class NumLock_ : LEDMode {
public: public:
LEDNumlock (uint8_t numpadIndex); NumLock_ (void);
virtual void begin (void) final; virtual void begin (void) final;
virtual void update (void) final; virtual void update (void) final;
virtual void init (void) final; virtual void init (void) final;
static const macro_t *toggle (byte row, byte col, uint8_t numPadLayer);
private: 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