Harald Albrecht
5 years ago
13 changed files with 332 additions and 63 deletions
@ -0,0 +1,48 @@ |
|||
-- Part of Multibow |
|||
|
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
-- Sends a single key tap to the USB host, optionally with modifier keys, such |
|||
-- as SHIFT (keybow.LEFT_SHIFT), CTRL (keybow.LEFT_CTRL), et cetera. The "key" |
|||
-- parameter can be a string or a Keybow key code, such as keybow.HOME, et |
|||
-- cetera. |
|||
function mb.tap(key, ...) |
|||
mb.tap_times(key, 1, ...) |
|||
end |
|||
|
|||
-- Taps the same key multiple times... |
|||
function mb.tap_times(key, times, ...) |
|||
for modifier_argno = 1, select("#", ...) do |
|||
local modifier = select(modifier_argno, ...) |
|||
if modifier then; keybow.set_modifier(modifier, keybow.KEY_DOWN); end |
|||
end |
|||
for tap = 1, times do |
|||
keybow.tap_key(key) |
|||
keybow.sleep(100) |
|||
end |
|||
for modifier_argno = 1, select("#", ...) do |
|||
local modifier = select(modifier_argno, ...) |
|||
if modifier then; keybow.set_modifier(modifier, keybow.KEY_UP); end |
|||
end |
|||
end |
|||
|
@ -0,0 +1,35 @@ |
|||
-- Part of Multibow |
|||
|
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
|
|||
-- Default LED brightness in the [0.1..1] range. |
|||
mb.brightness = 1 |
|||
|
|||
-- Sets the Keybow key LEDs maximum brightness, in the range [0.1..1]. |
|||
function mb.set_brightness(brightness) |
|||
if brightness < 0.1 then brightness = 0.1 end |
|||
if brightness > 1 then brightness = 1 end |
|||
mb.brightness = brightness |
|||
mb.activate_leds() |
|||
end |
@ -1,3 +1,5 @@ |
|||
-- Part of Multibow |
|||
|
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
@ -0,0 +1,48 @@ |
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
require "mocked-keybow" |
|||
local hwk = require("spec/hwkeys") |
|||
|
|||
describe("VSC golang keymap", function() |
|||
|
|||
local mb, go |
|||
|
|||
it("initializes", function() |
|||
mb = require("snippets/multibow") |
|||
go = require("layouts/vsc-golang") |
|||
assert.is.equal(go.keymap.name, mb.current_keymap.name) |
|||
assert.is.equal(1, #mb.registered_keymaps()) |
|||
end) |
|||
|
|||
it("colors its keys", function() |
|||
for _, keymap in pairs({go.keymap}) do |
|||
for keyno = 0, 11 do |
|||
local keydef = keymap[keyno] |
|||
if keydef then |
|||
assert.is_truthy(keydef.c) |
|||
end |
|||
end |
|||
end |
|||
end) |
|||
|
|||
end) |
@ -0,0 +1,69 @@ |
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
require "mocked-keybow" |
|||
local mb = require("snippets/multibow") |
|||
|
|||
describe("multibow keys", function() |
|||
|
|||
local tap = spy.on(keybow, "tap_key") |
|||
local mod = spy.on(keybow, "set_modifier") |
|||
|
|||
before_each(function() |
|||
tap:clear() |
|||
mod:clear() |
|||
end) |
|||
|
|||
it("taps a plain honest key", function() |
|||
mb.tap("x") |
|||
assert.spy(tap).was.called(1) |
|||
assert.spy(tap).was.called_with("x") |
|||
assert.spy(mod).was_not.called() |
|||
end) |
|||
|
|||
it("taps a plain honest key", function() |
|||
mb.tap("x", keybow.LEFT_CTRL, keybow.LEFT_SHIFT) |
|||
assert.spy(tap).was.called(1) |
|||
assert.spy(mod).was.called(4) |
|||
for _, ud in pairs({keybow.KEY_DOWN, keybow.KEY_UP}) do |
|||
assert.spy(mod).was.called_with(keybow.LEFT_CTRL, ud) |
|||
assert.spy(mod).was.called_with(keybow.LEFT_SHIFT, ud) |
|||
end |
|||
end) |
|||
|
|||
it("taps the same key repeatedly", function() |
|||
mb.tap_times("x", 3) |
|||
assert.spy(tap).was.called(3) |
|||
assert.spy(tap).was.called_with("x") |
|||
end) |
|||
|
|||
it("taps the same key repeatedly with modifiers", function() |
|||
mb.tap_times("x", 3, keybow.LEFT_CTRL) |
|||
assert.spy(tap).was.called(3) |
|||
assert.spy(tap).was.called_with("x") |
|||
assert.spy(mod).was.called(2) |
|||
for _, ud in pairs({keybow.KEY_DOWN, keybow.KEY_UP}) do |
|||
assert.spy(mod).was.called_with(keybow.LEFT_CTRL, ud) |
|||
end |
|||
end) |
|||
|
|||
end) |
@ -0,0 +1,39 @@ |
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
require "mocked-keybow" |
|||
local mb = require("snippets/multibow") |
|||
|
|||
describe("multibow LEDs", function() |
|||
|
|||
it("controls brightness", function() |
|||
mb.set_brightness(0.5) |
|||
assert.equals(0.5, mb.brightness) |
|||
|
|||
mb.set_brightness(1.1) |
|||
assert.equals(1.0, mb.brightness) |
|||
|
|||
mb.set_brightness(0) |
|||
assert.equals(0.1, mb.brightness) |
|||
end) |
|||
|
|||
end) |
Loading…
Reference in new issue