mirror of
https://github.com/osiweb/unified_retro_keyboard.git
synced 2024-11-19 00:06:15 +00:00
modifier cleanups
- add caps key function, similar to shift. This is intended for a DIP switch setting to switch the keyboard between all CAPS and upper/lower modes. - clean up the modifier state enums to include all legal values - clean up the modifier index value calculation to improve readability.
This commit is contained in:
parent
f0772180cb
commit
088af21650
@ -1,3 +1,5 @@
|
||||
# -*- makefile -*-
|
||||
|
||||
ARCH ?= atmega328p
|
||||
KEYMAP ?= ascii
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# -*- makefile -*-
|
||||
|
||||
ARCH ?= atmega328p
|
||||
KEYMAP ?= ascii
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
ARCH = test
|
||||
# -*- makefile -*-
|
||||
|
||||
ARCH = test
|
||||
KEYMAP = test
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
// File recommented by recomment.cpp
|
||||
// on Dec 9 2019 at 10:14:05.
|
||||
//
|
||||
// -*-mode : C;
|
||||
// tab - width : 2; indent-tabs-mode: nil -*-
|
||||
//
|
||||
@ -61,6 +58,7 @@ void asdf_modifier_shift_activate(void)
|
||||
shift_state = SHIFT_ON_ST;
|
||||
}
|
||||
|
||||
|
||||
// PROCEDURE: asdf_modifier_shiftlock_activate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
@ -94,6 +92,36 @@ void asdf_modifier_shiftlock_activate(void)
|
||||
}
|
||||
}
|
||||
|
||||
// PROCEDURE: asdf_modifier_caps_activate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
//
|
||||
// DESCRIPTION: sets CAPS state to ON (without disturbing the caps lock state)
|
||||
//
|
||||
// SIDE EFFECTS: see DESCRIPTION
|
||||
//
|
||||
// COMPLEXITY: 1
|
||||
//
|
||||
void asdf_modifier_caps_activate(void)
|
||||
{
|
||||
caps_state |= CAPS_ON_ST;
|
||||
}
|
||||
|
||||
// PROCEDURE: asdf_modifier_caps_deactivate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
//
|
||||
// DESCRIPTION: sets CAPS state to OFF (without disturbing the caps lock state)
|
||||
//
|
||||
// SIDE EFFECTS: see DESCRIPTION
|
||||
//
|
||||
// COMPLEXITY: 1
|
||||
//
|
||||
void asdf_modifier_caps_deactivate(void)
|
||||
{
|
||||
caps_state &= ~CAPS_ON_ST;
|
||||
}
|
||||
|
||||
// PROCEDURE: asdf_modifier_capslock_activate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
@ -106,7 +134,7 @@ void asdf_modifier_shiftlock_activate(void)
|
||||
//
|
||||
void asdf_modifier_capslock_activate(void)
|
||||
{
|
||||
caps_state ^= CAPS_ON_ST;
|
||||
caps_state ^= CAPS_LOCKED_ST;
|
||||
}
|
||||
|
||||
// PROCEDURE: asdf_modifier_ctrl_activate
|
||||
@ -213,8 +241,20 @@ void asdf_modifiers_init(void)
|
||||
//
|
||||
modifier_index_t asdf_modifier_index(void)
|
||||
{
|
||||
return modifier_indices[((uint8_t)(shift_state & 1) // shift active
|
||||
| ((uint8_t)(shift_state >> 1)) // shiftlock active
|
||||
| (uint8_t) caps_state // caps active
|
||||
| (uint8_t) ctrl_state)]; // ctrl active
|
||||
uint8_t modifier = 0;
|
||||
if (shift_state) {
|
||||
modifier |= ASDF_MODIFIERS_SHIFT_MASK;
|
||||
}
|
||||
if (caps_state) {
|
||||
modifier |= ASDF_MODIFIERS_CAPS_MASK;
|
||||
}
|
||||
if (ctrl_state) {
|
||||
modifier |= ASDF_MODIFIERS_CTRL_MASK;
|
||||
}
|
||||
|
||||
return modifier_indices[modifier];
|
||||
}
|
||||
|
||||
|
||||
//-------|---------|---------+---------+---------+---------+---------+---------+
|
||||
// Above line is 80 columns, and should display completely in the editor.
|
||||
|
@ -1,6 +1,3 @@
|
||||
// File recommented by recomment.cpp
|
||||
// on Dec 9 2019 at 10:14:05.
|
||||
//
|
||||
// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
|
||||
//
|
||||
// Unfified Keyboard Project
|
||||
@ -26,9 +23,31 @@
|
||||
#if !defined(ASDF_MODIFIERS_H)
|
||||
#define ASDF_MODIFIERS_H
|
||||
|
||||
typedef enum { SHIFT_OFF_ST = 0, SHIFT_ON_ST = 0x01, SHIFT_LOCKED_ST = 0x02 } shift_state_t;
|
||||
typedef enum { CAPS_OFF_ST = 0, CAPS_ON_ST = 0x02 } caps_state_t;
|
||||
typedef enum { CTRL_OFF_ST = 0, CTRL_ON_ST = 0x04 } ctrl_state_t;
|
||||
#define ASDF_MODIFIERS_SHIFT_POS 0
|
||||
#define ASDF_MODIFIERS_CAPS_POS 1
|
||||
#define ASDF_MODIFIERS_CTRL_POS 2
|
||||
|
||||
#define ASDF_MODIFIERS_SHIFT_MASK (1 << ASDF_MODIFIERS_SHIFT_POS)
|
||||
#define ASDF_MODIFIERS_CAPS_MASK (1 << ASDF_MODIFIERS_CAPS_POS)
|
||||
#define ASDF_MODIFIERS_CTRL_MASK (1 << ASDF_MODIFIERS_CTRL_POS)
|
||||
|
||||
typedef enum {
|
||||
SHIFT_OFF_ST = 0,
|
||||
SHIFT_ON_ST = 1,
|
||||
SHIFT_LOCKED_ST = 2,
|
||||
SHIFT_BOTH_ST = 3 // Never explicitly set. SHIFT and SHIFTLOCK together.
|
||||
|
||||
} shift_state_t;
|
||||
|
||||
typedef enum {
|
||||
CAPS_OFF_ST = 0,
|
||||
CAPS_ON_ST = 1,
|
||||
CAPS_LOCKED_ST = 2,
|
||||
CAPS_BOTH_ST = 3 // Never explicitly set. CAPS and CAPSLOCK together.
|
||||
} caps_state_t;
|
||||
|
||||
typedef enum { CTRL_OFF_ST = 0, CTRL_ON_ST = 1 } ctrl_state_t;
|
||||
|
||||
typedef enum {
|
||||
MOD_PLAIN_MAP = 0,
|
||||
MOD_SHIFT_MAP,
|
||||
@ -61,6 +80,12 @@ void asdf_modifier_shiftlock_activate(void);
|
||||
//
|
||||
void asdf_modifier_capslock_activate(void);
|
||||
|
||||
// PROCEDURE: asdf_modifier_caps_activate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
// DESCRIPTION: sets CAPS state to ON (without disturbing the caps lock state)
|
||||
void asdf_modifier_caps_activate(void);
|
||||
|
||||
// PROCEDURE: asdf_modifier_ctrl_activate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
@ -96,6 +121,12 @@ void asdf_modifier_shiftlock_deactivate(void);
|
||||
//
|
||||
void asdf_modifier_capslock_deactivate(void);
|
||||
|
||||
// PROCEDURE: asdf_modifier_caps_deactivate
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
// DESCRIPTION: sets CAPS state to OFF (without disturbing the caps lock state)
|
||||
void asdf_modifier_caps_deactivate(void);
|
||||
|
||||
// PROCEDURE: asdf_modifiers_init
|
||||
// INPUTS: none
|
||||
// OUTPUTS: none
|
||||
|
@ -279,6 +279,81 @@ void ctrl_double_shiftlock_returns_to_ctrl_map(void)
|
||||
TESTMAP(MOD_CTRL_MAP);
|
||||
}
|
||||
|
||||
// CAPS give caps
|
||||
void caps_gives_caps(void)
|
||||
{
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
}
|
||||
|
||||
// CAPS and release gives plain
|
||||
void caps_and_release_gives_plain(void)
|
||||
{
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_deactivate();
|
||||
TESTMAP(MOD_PLAIN_MAP);
|
||||
}
|
||||
|
||||
|
||||
// CAPSLOCK and CAPS gives caps
|
||||
void capslock_and_caps_gives_caps(void)
|
||||
{
|
||||
asdf_modifier_capslock_activate();
|
||||
asdf_modifier_capslock_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
}
|
||||
|
||||
// CAPSLOCK and CAPS and release CAPS gives caps
|
||||
void capslock_and_caps_and_release_gives_caps(void)
|
||||
{
|
||||
asdf_modifier_capslock_activate();
|
||||
asdf_modifier_capslock_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
}
|
||||
|
||||
// CAPS and CAPSLOCK gives caps
|
||||
void caps_and_capslock_gives_caps(void)
|
||||
{
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_capslock_activate();
|
||||
asdf_modifier_capslock_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
}
|
||||
|
||||
// CAPS and CAPSLOCK and release CAPS gives caps
|
||||
void caps_and_capslock_and_release_gives_caps(void)
|
||||
{
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_capslock_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
}
|
||||
|
||||
// CAPS and CAPSLOCK and release CAPS then CAPSLOCK gives plain
|
||||
void caps_and_capslock_and_release_and_capslock_gives_plain(void)
|
||||
{
|
||||
asdf_modifier_caps_activate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_capslock_activate();
|
||||
asdf_modifier_capslock_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_caps_deactivate();
|
||||
TESTMAP(MOD_CAPS_MAP);
|
||||
asdf_modifier_capslock_activate();
|
||||
asdf_modifier_capslock_deactivate();
|
||||
TESTMAP(MOD_PLAIN_MAP);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -306,7 +381,13 @@ int main(void)
|
||||
RUN_TEST(ctrl_shiftlock_gives_ctrl_map);
|
||||
RUN_TEST(ctrl_double_caps_returns_to_ctrl_map);
|
||||
RUN_TEST(ctrl_double_shiftlock_returns_to_ctrl_map);
|
||||
|
||||
RUN_TEST(caps_gives_caps);
|
||||
RUN_TEST(caps_and_release_gives_plain);
|
||||
RUN_TEST(capslock_and_caps_gives_caps);
|
||||
RUN_TEST(capslock_and_caps_and_release_gives_caps);
|
||||
RUN_TEST(caps_and_capslock_gives_caps);
|
||||
RUN_TEST(caps_and_capslock_and_release_gives_caps);
|
||||
RUN_TEST(caps_and_capslock_and_release_and_capslock_gives_plain);
|
||||
// toggle shiftlock_mode switches the shiftlock behavior to toggle_mode
|
||||
// calling toggle_shiftlock_mode twice leaves shiftlock behavior in hold mode
|
||||
// calling toggle_shiftlock_mode three times leaves shiftlock behavior in toggle mode
|
||||
|
Loading…
Reference in New Issue
Block a user