Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] A new key grouping based approach to flexible layer selection #594

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* -*- mode: c++ -*-
* Basic -- A very basic Kaleidoscope example
* Copyright (C) 2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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.h"

#include "Kaleidoscope-LED-ActiveLayerColor.h"

// This example demonstrates how keys can be grouped by
// a decision function that relies on a keymap layer kind of array
// that stores the key group id of every individual key.
//
// Please note that the function groupOfKey(..) may only return values
// in the range [0;5].

enum { AMap, BMap };

/* *INDENT-OFF* */
KEYMAPS(
[AMap] = KEYMAP_STACKED
(
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_2, ShiftToLayer(BMap)),

Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_1, ShiftToLayer(BMap))
),

[BMap] = KEYMAP_STACKED
(
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___,

Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___
)
)
/* *INDENT-ON* */

KALEIDOSCOPE_INIT_PLUGINS(
LEDControl,
LEDActiveLayerColorEffect
)

KEY_GROUP_IDS_STACKED(
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0,
0,

0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2,
0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0,
0
)

uint8_t groupOfKey(KeyAddr key_addr) {
return GROUP_OF_KEY(key_addr);
}

void setup() {
Kaleidoscope.setup();

static const cRGB layerColormap[] PROGMEM = {
CRGB(128, 0, 0),
CRGB(0, 128, 0)
};

LEDActiveLayerColorEffect.setColormap(layerColormap);
}

void loop() {
Kaleidoscope.loop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/* -*- mode: c++ -*-
* Basic -- A very basic Kaleidoscope example
* Copyright (C) 2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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.h"

#include "Kaleidoscope-LED-ActiveLayerColor.h"

// This example demonstrates how keys can be grouped using conditionals
// in a decision function.
//
// Please note that the function groupOfKey(...) may only return values
// in the range [0;5].

enum { AMap, BMap };

/* *INDENT-OFF* */
KEYMAPS(
[AMap] = KEYMAP_STACKED
(
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_1, ShiftToLayer(BMap)),

Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_0 | KEY_GROUP_2, ShiftToLayer(BMap))
),

[BMap] = KEYMAP_STACKED
(
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___,

Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___
)
)
/* *INDENT-ON* */

KALEIDOSCOPE_INIT_PLUGINS(
LEDControl,
LEDActiveLayerColorEffect
)

uint8_t groupOfKey(KeyAddr key_addr) {
return key_addr.row();
}

void setup() {
Kaleidoscope.setup();

static const cRGB layerColormap[] PROGMEM = {
CRGB(128, 0, 0),
CRGB(0, 128, 0)
};

LEDActiveLayerColorEffect.setColormap(layerColormap);
}

void loop() {
Kaleidoscope.loop();
}
88 changes: 88 additions & 0 deletions examples/Features/KeyGroups/Default/Default.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* -*- mode: c++ -*-
* Basic -- A very basic Kaleidoscope example
* Copyright (C) 2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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.h"

#include "Kaleidoscope-LED-ActiveLayerColor.h"

// This example demonstrates the default key grouping mechanism
// where the left hand is assigned to key group 0 (KEY_GROUP_LEFT_HAND),
// the right hand to key group 1 (KEY_GROUP_RIGHT_HAND).

enum { AMap, BMap };

/* *INDENT-OFF* */
KEYMAPS(
[AMap] = KEYMAP_STACKED
(
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_RIGHT_HAND, ShiftToLayer(BMap)),

Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,
Key_A, Key_A, Key_A, Key_A, Key_A, Key_A, Key_A,

Key_A, Key_A, Key_A, Key_A,
KeyGroup(KEY_GROUP_LEFT_HAND, ShiftToLayer(BMap))
),

[BMap] = KEYMAP_STACKED
(
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___,

Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,
Key_B, Key_B, Key_B, Key_B, Key_B, Key_B, Key_B,

Key_B, Key_B, Key_B, Key_B,
___
)
)
/* *INDENT-ON* */

KALEIDOSCOPE_INIT_PLUGINS(
LEDControl,
LEDActiveLayerColorEffect
)

void setup() {
Kaleidoscope.setup();

static const cRGB layerColormap[] PROGMEM = {
CRGB(128, 0, 0),
CRGB(0, 128, 0)
};

LEDActiveLayerColorEffect.setColormap(layerColormap);
}

void loop() {
Kaleidoscope.loop();
}
20 changes: 20 additions & 0 deletions src/Kaleidoscope-KeyGroups.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* -*- mode: c++ -*-
* Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope
* Copyright (C) 2018 Keyboard.io, Inc
*
* 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/key_groups.h"
1 change: 1 addition & 0 deletions src/kaleidoscope/Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/

namespace kaleidoscope {

/** Kaleidoscope Hardware base class.
* Essential methods all hardware libraries must implement.
*/
Expand Down
18 changes: 15 additions & 3 deletions src/kaleidoscope/device/ez/ErgoDox.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ namespace kaleidoscope {
namespace device {
namespace ez {

struct ErgoDoxKeyScannerProps : kaleidoscope::driver::keyscanner::BaseProps {
KEYSCANNER_PROPS(14, 6);
};

class ErgoDoxKeyScanner : public kaleidoscope::device::ATmega32U4KeyboardProps::KeyScanner {
public:

static constexpr bool isOnLeftHalf(ErgoDoxKeyScannerProps::KeyAddr key_addr) {
return key_addr.row() < 7;
}
};

struct ErgoDoxProps : public kaleidoscope::device::ATmega32U4KeyboardProps {
struct KeyScannerProps : kaleidoscope::driver::keyscanner::BaseProps {
KEYSCANNER_PROPS(14, 6);
};

typedef ErgoDoxKeyScannerProps KeyScannerProps;
typedef ErgoDoxKeyScanner KeyScanner;
typedef kaleidoscope::driver::bootloader::avr::HalfKay Bootloader;
};

Expand Down
2 changes: 1 addition & 1 deletion src/kaleidoscope/device/keyboardio/Model01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void Model01KeyScanner::scanMatrix() {
// halves, with eight keys per logical row.

constexpr byte HIGH_BIT = B10000000;
constexpr byte HAND_BIT = B00001000;
constexpr byte HAND_BIT = Model01KeyScannerProps::HAND_BIT;
constexpr byte ROW_BITS = B00110000;
constexpr byte COL_BITS = B00000111;

Expand Down
8 changes: 8 additions & 0 deletions src/kaleidoscope/device/keyboardio/Model01.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ class Model01LEDDriver;

struct Model01KeyScannerProps : public kaleidoscope::driver::keyscanner::BaseProps {
KEYSCANNER_PROPS(4, 16);

static constexpr byte HAND_BIT = B00001000;
};

#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01KeyScannerProps> {
private:
typedef Model01KeyScanner ThisType;
public:

static void setup();
static void scanMatrix();
static void readMatrix();
Expand All @@ -98,6 +101,11 @@ class Model01KeyScanner : public kaleidoscope::driver::keyscanner::Base<Model01K

static void setKeyscanInterval(uint8_t interval);

static constexpr bool isOnLeftHalf(KeyAddr key_addr) {
// If HAND_BIT is set, we are on the right hand side
return !(key_addr.col() & Model01KeyScannerProps::HAND_BIT);
}

protected:
static keydata_t leftHandState;
static keydata_t rightHandState;
Expand Down
Loading