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

Adding keybow-mini example layout for switching 'layers' on the fly #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions sdcard/layers/mini_linux.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "keybow"

layer_linux = {}

-- layer setup --

function layer_linux.setup()
keybow.use_mini()
keybow.auto_lights(false)
keybow.clear_lights()
keybow.set_pixel(0, 155, 0, 155)
keybow.set_pixel(1, 155, 0, 155)
keybow.set_pixel(2, 255, 0, 255)
end

-- Key mappings --

function layer_linux.handle_minikey_00(pressed)
if pressed then
keybow.set_pixel(0, 255, 0, 255)
keybow.set_modifier(keybow.LEFT_META, keybow.KEY_DOWN)
keybow.tap_key("d", pressed)
keybow.set_modifier(keybow.LEFT_META, keybow.KEY_UP)
else
keybow.set_pixel(0, 155, 0, 155)
end
end

function layer_linux.handle_minikey_01(pressed)
if pressed then
keybow.set_pixel(1, 255, 0, 255)
keybow.set_modifier(keybow.LEFT_META, keybow.KEY_DOWN)
keybow.tap_key(keybow.ENTER, pressed)
keybow.set_modifier(keybow.LEFT_META, keybow.KEY_UP)
else
keybow.set_pixel(1, 155, 0, 155)
end
end

function layer_linux.handle_minikey_02(pressed)
if pressed then
keybow.set_pixel(2, 155, 0, 155)
else
keybow.set_pixel(2, 255, 0, 255)
end
end
44 changes: 44 additions & 0 deletions sdcard/layers/mini_programmer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "keybow"

layer_programmer = {}

-- layer setup --

function layer_programmer.setup()
keybow.use_mini()
keybow.auto_lights(false)
keybow.clear_lights()
keybow.set_pixel(0, 0, 155, 0)
keybow.set_pixel(1, 0, 155, 0)
keybow.set_pixel(2, 0, 255, 0)
end

-- Key mappings --

function layer_programmer.handle_minikey_00(pressed)
keybow.set_key("v", pressed)
if pressed then
keybow.set_pixel(0, 0, 255, 0)
else
keybow.set_pixel(0, 0, 155, 0)
end
end

function layer_programmer.handle_minikey_01(pressed)
keybow.set_key("c", pressed)
if pressed then
keybow.set_pixel(1, 0, 255, 0)
else
keybow.set_pixel(1, 0, 155, 0)
end
end

function layer_programmer.handle_minikey_02(pressed)
if pressed then
keybow.set_modifier(keybow.LEFT_CTRL, keybow.KEY_DOWN)
keybow.set_pixel(2, 0, 155, 0)
else
keybow.set_modifier(keybow.LEFT_CTRL, keybow.KEY_UP)
keybow.set_pixel(2, 0, 255, 0)
end
end
63 changes: 63 additions & 0 deletions sdcard/layouts/mini_layers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "keybow"
require "layers/mini_programmer"
require "layers/mini_linux"


-- define layers --

num_layers = 2
layers = {
[1] = layer_programmer,
[2] = layer_linux
}

last_layer = 1
current_layer = 1

-- check for layer change --

current_time = 0
last_pressed = current_time

function tick(time)
current_time = time
end

function layer_changer(delay)
if (current_time - last_pressed <= delay) then
if (current_layer + 1 > num_layers) then
current_layer = 1
else
current_layer = current_layer + 1
end
layers[current_layer].setup()
end
last_pressed = current_time
end

-- Keybow MINI --

function setup()
keybow.use_mini()
keybow.auto_lights(false)
keybow.clear_lights()
keybow.set_pixel(2, 255, 0, 0)
layers[current_layer].setup()
end

-- Key mappings --

function handle_minikey_00(pressed)
layers[current_layer].handle_minikey_00(pressed)
end

function handle_minikey_01(pressed)
layers[current_layer].handle_minikey_01(pressed)
end

function handle_minikey_02(pressed)
if pressed then
layer_changer(200)
end
layers[current_layer].handle_minikey_02(pressed)
end
Loading