summaryrefslogtreecommitdiff
path: root/common/layer_switch.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-15 18:48:36 +0900
committertmk <nobody@nowhere>2013-02-15 18:48:36 +0900
commitd9f287586635a401b8d6a80614bee6dbebe2f18c (patch)
tree19e9e3116127e6e966c23d499d7ea879de3b78e8 /common/layer_switch.c
parentf8d289e66965f99469292370c3b9200a03254f8e (diff)
Replace layer_stack with layer_switch
Diffstat (limited to 'common/layer_switch.c')
-rw-r--r--common/layer_switch.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/common/layer_switch.c b/common/layer_switch.c
new file mode 100644
index 0000000000..9bc804e641
--- /dev/null
+++ b/common/layer_switch.c
@@ -0,0 +1,68 @@
+#include <stdint.h>
+#include "keyboard.h"
+#include "action.h"
+#include "debug.h"
+#include "layer_switch.h"
+
+
+uint16_t layer_switch_stat = 0;
+
+
+uint16_t layer_switch_stat_get(void)
+{
+ return layer_switch_stat;
+}
+
+void layer_switch_stat_set(uint16_t stat)
+{
+ layer_switch_stat = stat;
+ layer_switch_debug();
+}
+
+void layer_switch_clear(void)
+{
+ layer_switch_stat = 0;
+ layer_switch_debug();
+}
+
+void layer_switch_on(uint8_t layer)
+{
+ layer_switch_stat |= (1<<layer);
+ layer_switch_debug();
+}
+
+void layer_switch_off(uint8_t layer)
+{
+ layer_switch_stat &= ~(1<<layer);
+ layer_switch_debug();
+}
+
+void layer_switch_inv(uint8_t layer)
+{
+ layer_switch_stat ^= (1<<layer);
+ layer_switch_debug();
+}
+
+void layer_switch_debug(void)
+{
+ debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n");
+}
+
+action_t layer_switch_get_action(key_t key)
+{
+ action_t action;
+ action.code = ACTION_TRANSPARENT;
+
+ /* higher layer first */
+ for (int8_t i = 15; i >= 0; i--) {
+ if (layer_switch_stat & (1<<i)) {
+ action = action_for_key(i, key);
+ if (action.code != ACTION_TRANSPARENT) {
+ layer_switch_debug();
+ debug("layer_switch: used. "); debug_dec(i); debug("\n");
+ return action;
+ }
+ }
+ }
+ return action;
+}