Compare commits
75 Commits
examples/f
...
main
Author | SHA1 | Date |
---|---|---|
Alpha Chen | 0bb3928aea | 2 years ago |
Alpha Chen | 7954cc8f25 | 2 years ago |
Alpha Chen | 9fb691f44a | 2 years ago |
Gergely Nagy | ff19f144f8 | 2 years ago |
Michael Richters | a0045f4d9e | 2 years ago |
Michael Richters | 51125f215b | 2 years ago |
Michael Richters | c84aa58470 | 2 years ago |
Michael Richters | 789cc218c6 | 2 years ago |
Michael Richters | adaa3b7a01 | 2 years ago |
Alpha Chen | a43b89ce51 | 2 years ago |
Alpha Chen | 02157d30c7 | 2 years ago |
Gergely Nagy | 2f1c96ab4e | 2 years ago |
Gergely Nagy | 49a691e0f9 | 2 years ago |
Norwin | 3655f9a517 | 2 years ago |
Norwin | e22773ab5b | 2 years ago |
Jesse Vincent | fefc6699ba | 2 years ago |
Taylor Yu | e233e96be7 | 2 years ago |
Jesse Vincent | 18d0292d64 | 2 years ago |
Taylor Yu | af69f6a72b | 2 years ago |
Taylor Yu | 0ac320baeb | 2 years ago |
Jesse Vincent | 95ea4e3175 | 2 years ago |
Gergely Nagy | d0f1a812b0 | 2 years ago |
Gergely Nagy | 6a12467b84 | 2 years ago |
Jesse Vincent | b949ca89b1 | 2 years ago |
Jesse Vincent | cf798497e2 | 2 years ago |
Gergely Nagy | ca9b4cb50c | 2 years ago |
Taylor Yu | 04d608c9f6 | 2 years ago |
Jesse Vincent | 9bf6eba010 | 2 years ago |
Gergely Nagy | f21dda9a51 | 2 years ago |
Gergely Nagy | 28d6d66e98 | 2 years ago |
Jesse Vincent | ae9e561028 | 2 years ago |
Jesse Vincent | f181d55124 | 2 years ago |
Jesse Vincent | be28b367ce | 2 years ago |
Taylor Yu | 45bd9d1a3d | 2 years ago |
Gergely Nagy | 75b911b27d | 2 years ago |
Gergely Nagy | a5afaf1eb4 | 2 years ago |
Gergely Nagy | 26340b7edb | 2 years ago |
Gergely Nagy | 8ac4d9f5c1 | 2 years ago |
Gergely Nagy | a9f4f16e31 | 2 years ago |
Jesse Vincent | 7b66d8dfb5 | 2 years ago |
Jesse Vincent | 8196adab6c | 2 years ago |
Gergely Nagy | 96fbfb0628 | 2 years ago |
Gergely Nagy | a4b84057b0 | 2 years ago |
Jesse Vincent | 62a0fae04d | 2 years ago |
Gergely Nagy | cd82afd50a | 2 years ago |
Gergely Nagy | 7f4090f126 | 2 years ago |
Jesse Vincent | 63bcf212f3 | 2 years ago |
Gergely Nagy | db7b0af730 | 2 years ago |
Jesse Vincent | f3fe7c9023 | 2 years ago |
Taylor Yu | 1301bebc09 | 2 years ago |
Taylor Yu | d16f2c93b8 | 2 years ago |
Jesse Vincent | becf816dbe | 2 years ago |
Taylor Yu | af3dc61710 | 2 years ago |
Jesse Vincent | 35aa03b63d | 2 years ago |
Taylor Yu | 4a030ae7e8 | 2 years ago |
Taylor Yu | cf66803288 | 2 years ago |
Jesse Vincent | 8f3fab579b | 2 years ago |
Gergely Nagy | b114110645 | 2 years ago |
Gergely Nagy | e52cf5c821 | 2 years ago |
Jesse Vincent | f5639dd5ba | 2 years ago |
Gergely Nagy | 9d0dddb79a | 2 years ago |
Jesse Vincent | 51b272e598 | 2 years ago |
Tatsuhiko Miyagawa | 1e36ab17a6 | 2 years ago |
Jesse Vincent | 9d374292ba | 2 years ago |
Gergely Nagy | 9b9911bdb5 | 2 years ago |
Gergely Nagy | dde7caeee9 | 2 years ago |
Gergely Polonkai | d794035f6c | 2 years ago |
Jesse Vincent | 4087f43534 | 2 years ago |
Gergely Nagy | 6fd2fa153b | 2 years ago |
Jesse Vincent | bc0466aa22 | 2 years ago |
Gergely Nagy | 2a902e9b74 | 2 years ago |
Jesse Vincent | d12515105f | 3 years ago |
Gergely Nagy | b243b0c1c5 | 3 years ago |
Gergely Nagy | da024d6bf9 | 3 years ago |
Gergely Nagy | b5f0fc5ec9 | 3 years ago |
@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# focus-send - Trivial Focus testing tool
|
||||||
|
# Copyright (C) 2018-2022 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/>.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
OS=$(uname -s)
|
||||||
|
|
||||||
|
# igncr absorbs CR from Focus CRLF line endings
|
||||||
|
# -echo is needed because raw doesn't turn it off on Linux
|
||||||
|
STTY_ARGS="9600 raw igncr -echo"
|
||||||
|
|
||||||
|
case ${OS} in
|
||||||
|
Linux)
|
||||||
|
DEVICE="${DEVICE:-/dev/ttyACM0}"
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
# bash on macOS has a bug that randomly drops serial input
|
||||||
|
if [ -n "$BASH_VERSION" ] && [ -x /bin/dash ]; then
|
||||||
|
# Prevent loop in case someone exported it
|
||||||
|
export -n BASH_VERSION
|
||||||
|
exec /bin/dash "$0" "$@"
|
||||||
|
fi
|
||||||
|
DEVICE="${DEVICE:-/dev/cu.usbmodemCkbio01E}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error Unknown OS : ${OS}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Redirect prior to running stty, because macOS sometimes resets termios
|
||||||
|
# state upon last close of a terminal device.
|
||||||
|
exec < "${DEVICE}"
|
||||||
|
# shellcheck disable=SC2086 # intentional word splitting
|
||||||
|
stty $STTY_ARGS
|
||||||
|
|
||||||
|
read_reply () {
|
||||||
|
while read -r line; do
|
||||||
|
if [ "${line}" = "." ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "${line}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Flush any invalid commands out of input buffer.
|
||||||
|
# This could happen after a failed upload.
|
||||||
|
echo ' ' > "${DEVICE}"
|
||||||
|
read_reply > /dev/null
|
||||||
|
echo "$@" >"${DEVICE}"
|
||||||
|
read_reply
|
@ -1,45 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# focus-test - Trivial Focus testing tool
|
|
||||||
# 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/>.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
OS=$(uname -s)
|
|
||||||
|
|
||||||
case ${OS} in
|
|
||||||
Linux)
|
|
||||||
DEVICE="${DEVICE:-/dev/ttyACM0}"
|
|
||||||
stty -F "${DEVICE}" 9600 raw -echo
|
|
||||||
;;
|
|
||||||
Darwin)
|
|
||||||
DEVICE="${DEVICE:-/dev/cu.usbmodemCkbio01E}"
|
|
||||||
stty -f "${DEVICE}" 9600 raw -echo
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Error Unknown OS : ${OS}" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
exec 3<"${DEVICE}"
|
|
||||||
echo "$@" >"${DEVICE}"
|
|
||||||
|
|
||||||
while read -r line <&3; do
|
|
||||||
line="$(echo -n "${line}" | tr -d '\r')"
|
|
||||||
if [ "${line}" == "." ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "${line}"
|
|
||||||
done
|
|
@ -0,0 +1,36 @@
|
|||||||
|
# FirmwareVersion
|
||||||
|
|
||||||
|
Implements a new focus command - version - that simply prints the version set up
|
||||||
|
at compile time.
|
||||||
|
|
||||||
|
## Using the plugin
|
||||||
|
|
||||||
|
To use the plugin, first define the version to be printed, then include the
|
||||||
|
header, and activate the plugin.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#define KALEIDOSCOPE_FIRMWARE_VERSION "0.1.2"
|
||||||
|
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-FirmwareVersion.h>
|
||||||
|
#include <Kaleidoscope-FocusSerial.h>
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(Focus,
|
||||||
|
FirmwareVersion);
|
||||||
|
|
||||||
|
void setup () {
|
||||||
|
Kaleidoscope.setup ();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Focus commands
|
||||||
|
|
||||||
|
The plugin provides a single Focus command: `version`.
|
||||||
|
|
||||||
|
### `version`
|
||||||
|
|
||||||
|
> Prints the version configured at build time.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [Kaleidoscope-FocusSerial](Kaleidoscope-FocusSerial.md)
|
@ -0,0 +1,7 @@
|
|||||||
|
name=Kaleidoscope-FirmwareVersion
|
||||||
|
version=0.0.0
|
||||||
|
sentence=Provides a Focus command to print a preconfigured version
|
||||||
|
maintainer=Kaleidoscope's Developers <jesse@keyboard.io>
|
||||||
|
url=https://github.com/keyboardio/Kaleidoscope
|
||||||
|
author=Keyboardio
|
||||||
|
paragraph=
|
@ -0,0 +1,20 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-FirmwareVersion -- Provides a Focus command to print a version
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kaleidoscope/plugin/FirmwareVersion.h" // IWYU pragma: export
|
@ -0,0 +1,56 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-FirmwareVersion -- Provides a Focus command to print a version
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef KALEIDOSCOPE_FIRMWARE_VERSION
|
||||||
|
#define KALEIDOSCOPE_FIRMWARE_VERSION "0.0.0"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Arduino.h> // for PSTR, F, __FlashStringHelper
|
||||||
|
#include "Kaleidoscope-FocusSerial.h" // for Focus, FocusSerial
|
||||||
|
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
|
||||||
|
#include "kaleidoscope/plugin.h" // for Plugin
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
class FirmwareVersion : public Plugin {
|
||||||
|
public:
|
||||||
|
EventHandlerResult onFocusEvent(const char *input) {
|
||||||
|
const char *cmd_version = PSTR("version");
|
||||||
|
|
||||||
|
if (::Focus.inputMatchesHelp(input))
|
||||||
|
return ::Focus.printHelp(cmd_version);
|
||||||
|
|
||||||
|
if (!::Focus.inputMatchesCommand(input, cmd_version))
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
#ifdef KALEIDOSCOPE_FIRMWARE_VERSION
|
||||||
|
::Focus.send(F(KALEIDOSCOPE_FIRMWARE_VERSION));
|
||||||
|
#else
|
||||||
|
::Focus.send(F("0.0.0"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
kaleidoscope::plugin::FirmwareVersion FirmwareVersion;
|
@ -0,0 +1,75 @@
|
|||||||
|
# LayerNames
|
||||||
|
|
||||||
|
This plugin provides a [Focus][plugin:focus]-based interface for storing custom
|
||||||
|
layer names, to be used by software such as [Chrysalis][chrysalis]. The firmware
|
||||||
|
itself does nothing with the layer names, it is purely for use by applications
|
||||||
|
on the host side.
|
||||||
|
|
||||||
|
[chrysalis]: https://github.com/keyboardio/Chrysalis
|
||||||
|
|
||||||
|
## Using the plugin
|
||||||
|
|
||||||
|
To use the plugin, we need to include the header, initialize the plugin with
|
||||||
|
`KALEIDOSCOPE_INIT_PLUGINS()`, and reserve storage space for the names. This is
|
||||||
|
best illustrated with an example:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include <Kaleidoscope.h>
|
||||||
|
#include <Kaleidoscope-EEPROMSettings.h>
|
||||||
|
#include <Kaleidoscope-FocusSerial.h>
|
||||||
|
#include <Kaleidoscope-LayerNames.h>
|
||||||
|
|
||||||
|
KALEIDOSCOPE_INIT_PLUGINS(
|
||||||
|
EEPROMSettings,
|
||||||
|
Focus,
|
||||||
|
LayerNames
|
||||||
|
);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Kaleidoscope.setup();
|
||||||
|
|
||||||
|
LayerNames.reserve_storage(128);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Plugin methods
|
||||||
|
|
||||||
|
The plugin provides a `LayerNames` object, with the following method available:
|
||||||
|
|
||||||
|
### `.reserve_storage(size)`
|
||||||
|
|
||||||
|
> Reserves `size` bytes of storage for layer names. This must be called from the
|
||||||
|
> `setup()` method of your sketch.
|
||||||
|
|
||||||
|
## Focus commands
|
||||||
|
|
||||||
|
The plugin provides a single Focus command: `keymap.layerNames`.
|
||||||
|
|
||||||
|
### `keymap.layerNames [name_length name]...`
|
||||||
|
|
||||||
|
> Without arguments, displays all the stored layer names. Each layer is printed
|
||||||
|
> on its own line, preceded by its length. At the end, the plugin will also
|
||||||
|
> print an extra line with a name length of zero, followed by the string
|
||||||
|
> "size=", and then the total size of the storage reserved for layer names.
|
||||||
|
>
|
||||||
|
> To set custom names, a list of length & name pairs must be given. The plugin
|
||||||
|
> stops processing arguments when it encounters a name length of 0.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```
|
||||||
|
> keymap.layerNames
|
||||||
|
< 6 Qwerty
|
||||||
|
< 6 Numpad
|
||||||
|
< 8 Function
|
||||||
|
< 0 size=128
|
||||||
|
< .
|
||||||
|
|
||||||
|
> keymap.layerNames 6 Dvorak 6 Numpad 8 Function 0
|
||||||
|
< .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
* [Kaleidoscope-EEPROM-Settings](Kaleidoscope-EEPROM-Settings.md)
|
||||||
|
* [Kaleidoscope-FocusSerial](Kaleidoscope-FocusSerial.md)
|
@ -0,0 +1,7 @@
|
|||||||
|
name=Kaleidoscope-LayerNames
|
||||||
|
version=0.0.0
|
||||||
|
sentence=Kaleidoscope plugin that lets one set custom layer names
|
||||||
|
maintainer=Kaleidoscope's Developers <jesse@keyboard.io>
|
||||||
|
url=https://github.com/keyboardio/Kaleidoscope
|
||||||
|
author=Keyboardio
|
||||||
|
paragraph=
|
@ -0,0 +1,19 @@
|
|||||||
|
/* Kaleidoscope - Firmware for computer input devices
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kaleidoscope/plugin/LayerNames.h" // IWYU pragma: export
|
@ -0,0 +1,98 @@
|
|||||||
|
/* Kaleidoscope - Firmware for computer input devices
|
||||||
|
* Copyright (C) 2022 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/plugin/LayerNames.h"
|
||||||
|
|
||||||
|
#include <Arduino.h> // for delay, PSTR, F, __FlashStri...
|
||||||
|
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
|
||||||
|
|
||||||
|
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
|
||||||
|
#include "kaleidoscope/plugin/EEPROM-Settings.h" // for EEPROMSettings
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
|
||||||
|
EventHandlerResult LayerNames::onNameQuery() {
|
||||||
|
return ::Focus.sendName(F("LayerNames"));
|
||||||
|
}
|
||||||
|
|
||||||
|
EventHandlerResult LayerNames::onFocusEvent(const char *input) {
|
||||||
|
const char *cmd_layerNames = PSTR("keymap.layerNames");
|
||||||
|
|
||||||
|
if (::Focus.inputMatchesHelp(input))
|
||||||
|
return ::Focus.printHelp(cmd_layerNames);
|
||||||
|
|
||||||
|
if (!::Focus.inputMatchesCommand(input, cmd_layerNames))
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
if (::Focus.isEOL()) {
|
||||||
|
uint16_t pos = 0;
|
||||||
|
while (pos < storage_size_) {
|
||||||
|
uint8_t name_size = Runtime.storage().read(storage_base_ + pos++);
|
||||||
|
|
||||||
|
if (name_size == 0 || name_size == 255) break;
|
||||||
|
|
||||||
|
::Focus.send(name_size);
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < name_size; i++) {
|
||||||
|
uint8_t b = Runtime.storage().read(storage_base_ + pos++);
|
||||||
|
::Focus.sendRaw(static_cast<char>(b));
|
||||||
|
}
|
||||||
|
::Focus.sendRaw(::Focus.NEWLINE);
|
||||||
|
}
|
||||||
|
::Focus.sendRaw(0, ::Focus.SEPARATOR, F("size="), storage_size_);
|
||||||
|
} else {
|
||||||
|
uint16_t pos = 0;
|
||||||
|
|
||||||
|
while (pos < storage_size_) {
|
||||||
|
uint8_t name_size;
|
||||||
|
::Focus.read(name_size);
|
||||||
|
|
||||||
|
// size is followed by a space, ignore that.
|
||||||
|
char spc;
|
||||||
|
::Focus.read(spc);
|
||||||
|
|
||||||
|
Runtime.storage().update(storage_base_ + pos++, name_size);
|
||||||
|
|
||||||
|
if (name_size == 0 ||
|
||||||
|
name_size == ::EEPROMSettings.EEPROM_UNINITIALIZED_BYTE)
|
||||||
|
break;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < name_size; i++) {
|
||||||
|
char c;
|
||||||
|
::Focus.read(c);
|
||||||
|
|
||||||
|
Runtime.storage().update(storage_base_ + pos++, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Runtime.storage().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public
|
||||||
|
void LayerNames::reserve_storage(uint16_t size) {
|
||||||
|
storage_base_ = ::EEPROMSettings.requestSlice(size);
|
||||||
|
storage_size_ = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
kaleidoscope::plugin::LayerNames LayerNames;
|
@ -0,0 +1,42 @@
|
|||||||
|
/* Kaleidoscope - Firmware for computer input devices
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h> // for uint16_t, uint8_t
|
||||||
|
|
||||||
|
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
|
||||||
|
#include "kaleidoscope/plugin.h" // for Plugin
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
class LayerNames : public kaleidoscope::Plugin {
|
||||||
|
public:
|
||||||
|
EventHandlerResult onNameQuery();
|
||||||
|
EventHandlerResult onFocusEvent(const char *input);
|
||||||
|
|
||||||
|
void reserve_storage(uint16_t size);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint16_t storage_base_;
|
||||||
|
uint16_t storage_size_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
extern kaleidoscope::plugin::LayerNames LayerNames;
|
@ -0,0 +1,144 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-MouseKeys -- Mouse keys for Kaleidoscope.
|
||||||
|
* Copyright (C) 2022 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/plugin/MouseKeys.h" // IWYU pragma: associated
|
||||||
|
|
||||||
|
#include <Arduino.h> // for PSTR, strcmp_P, strncmp_P
|
||||||
|
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
|
||||||
|
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
|
||||||
|
#include <stdint.h> // for uint16_t, uint32_t, uint8_t
|
||||||
|
|
||||||
|
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
|
||||||
|
#include "kaleidoscope/device/device.h" // for VirtualProps::Storage, Base<>::Storage
|
||||||
|
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
// =============================================================================
|
||||||
|
// MouseKeys configurator
|
||||||
|
|
||||||
|
EventHandlerResult MouseKeysConfig::onSetup() {
|
||||||
|
settings_addr_ = ::EEPROMSettings.requestSlice(sizeof(MouseKeys::Settings));
|
||||||
|
uint32_t checker;
|
||||||
|
|
||||||
|
Runtime.storage().get(settings_addr_, checker);
|
||||||
|
|
||||||
|
// If the EEPROM is empty, storre the default settings.
|
||||||
|
if (checker == 0xffffffff) {
|
||||||
|
Runtime.storage().put(settings_addr_, ::MouseKeys.settings_);
|
||||||
|
Runtime.storage().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime.storage().get(settings_addr_, ::MouseKeys.settings_);
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
EventHandlerResult MouseKeysConfig::onFocusEvent(const char *command) {
|
||||||
|
// If the focus command is a request for help, provide the list of valid
|
||||||
|
// commands.
|
||||||
|
if (::Focus.handleHelp(command, PSTR("mousekeys.scroll_interval\n"
|
||||||
|
"mousekeys.init_speed\n"
|
||||||
|
"mousekeys.base_speed\n"
|
||||||
|
"mousekeys.accel_duration")))
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
// The length of the string `mousekeys.`:
|
||||||
|
constexpr uint8_t base_cmd_len = 10;
|
||||||
|
|
||||||
|
// If this is not a MouseKeys command, do nothing.
|
||||||
|
if (strncmp_P(command, PSTR("mousekeys."), base_cmd_len) != 0)
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
// Otherwise, advance the pointer to the subcommand.
|
||||||
|
command += base_cmd_len;
|
||||||
|
|
||||||
|
enum Command : uint8_t {
|
||||||
|
SCROLL_INTERVAL,
|
||||||
|
INIT_SPEED,
|
||||||
|
BASE_SPEED,
|
||||||
|
ACCEL_DURATION,
|
||||||
|
};
|
||||||
|
Command cmd;
|
||||||
|
|
||||||
|
// Parse the (sub)command. If it's not a valid command, abort.
|
||||||
|
if (strcmp_P(command, PSTR("scroll_interval")) == 0)
|
||||||
|
cmd = Command::SCROLL_INTERVAL;
|
||||||
|
else if (strcmp_P(command, PSTR("init_speed")) == 0)
|
||||||
|
cmd = Command::INIT_SPEED;
|
||||||
|
else if (strcmp_P(command, PSTR("base_speed")) == 0)
|
||||||
|
cmd = Command::BASE_SPEED;
|
||||||
|
else if (strcmp_P(command, PSTR("accel_duration")) == 0)
|
||||||
|
cmd = Command::ACCEL_DURATION;
|
||||||
|
else
|
||||||
|
return EventHandlerResult::ABORT;
|
||||||
|
|
||||||
|
if (::Focus.isEOL()) {
|
||||||
|
// If there is no argument given, we send back the current value of the
|
||||||
|
// setting that was requested.
|
||||||
|
uint16_t val;
|
||||||
|
switch (cmd) {
|
||||||
|
case Command::SCROLL_INTERVAL:
|
||||||
|
val = ::MouseKeys.getScrollInterval();
|
||||||
|
break;
|
||||||
|
case Command::INIT_SPEED:
|
||||||
|
val = ::MouseKeys.getCursorInitSpeed();
|
||||||
|
break;
|
||||||
|
case Command::BASE_SPEED:
|
||||||
|
val = ::MouseKeys.getCursorBaseSpeed();
|
||||||
|
break;
|
||||||
|
case Command::ACCEL_DURATION:
|
||||||
|
val = ::MouseKeys.getCursorAccelDuration();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return EventHandlerResult::ABORT;
|
||||||
|
}
|
||||||
|
::Focus.send(val);
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
} else {
|
||||||
|
// If there is an argument, we read it, then pass it to the corresponding
|
||||||
|
// setter method of MouseKeys.
|
||||||
|
uint16_t arg;
|
||||||
|
::Focus.read(arg);
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case Command::SCROLL_INTERVAL:
|
||||||
|
::MouseKeys.setScrollInterval(arg);
|
||||||
|
break;
|
||||||
|
case Command::INIT_SPEED:
|
||||||
|
::MouseKeys.setCursorInitSpeed(arg);
|
||||||
|
break;
|
||||||
|
case Command::BASE_SPEED:
|
||||||
|
::MouseKeys.setCursorBaseSpeed(arg);
|
||||||
|
break;
|
||||||
|
case Command::ACCEL_DURATION:
|
||||||
|
::MouseKeys.setCursorAccelDuration(arg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update settings stored in EEPROM, and indicate that this Focus event has
|
||||||
|
// been handled successfully.
|
||||||
|
Runtime.storage().put(settings_addr_, ::MouseKeys.settings_);
|
||||||
|
Runtime.storage().commit();
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
kaleidoscope::plugin::MouseKeysConfig MouseKeysConfig;
|
@ -0,0 +1,98 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-SpaceCadet -- Space Cadet Shift Extended
|
||||||
|
* Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc, Ben Gemperline
|
||||||
|
* Copyright (C) 2019-2021 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 "SpaceCadet.h"
|
||||||
|
#include "kaleidoscope/plugin/SpaceCadet.h"
|
||||||
|
|
||||||
|
#include <Arduino.h> // for PSTR
|
||||||
|
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
|
||||||
|
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
|
||||||
|
#include <stdint.h> // for uint16_t, int8_t, uint8_t
|
||||||
|
|
||||||
|
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
|
||||||
|
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
|
||||||
|
|
||||||
|
namespace kaleidoscope {
|
||||||
|
namespace plugin {
|
||||||
|
|
||||||
|
EventHandlerResult SpaceCadetConfig::onSetup() {
|
||||||
|
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(SpaceCadet::settings_));
|
||||||
|
|
||||||
|
// If our slice is uninitialized, then return early.
|
||||||
|
if (Runtime.storage().isSliceUninitialized(settings_base_, sizeof(SpaceCadet::settings_)))
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
|
||||||
|
Runtime.storage().get(settings_base_, ::SpaceCadet.settings_);
|
||||||
|
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpaceCadetConfig::disableSpaceCadetIfUnconfigured() {
|
||||||
|
if (Runtime.storage().isSliceUninitialized(settings_base_, sizeof(SpaceCadet::settings_)))
|
||||||
|
::SpaceCadet.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
EventHandlerResult SpaceCadetConfig::onFocusEvent(const char *input) {
|
||||||
|
const char *cmd_mode = PSTR("spacecadet.mode");
|
||||||
|
const char *cmd_timeout = PSTR("spacecadet.timeout");
|
||||||
|
|
||||||
|
if (::Focus.inputMatchesHelp(input))
|
||||||
|
return ::Focus.printHelp(cmd_mode, cmd_timeout);
|
||||||
|
|
||||||
|
if (::Focus.inputMatchesCommand(input, cmd_mode)) {
|
||||||
|
if (::Focus.isEOL()) {
|
||||||
|
::Focus.send(::SpaceCadet.settings_.mode);
|
||||||
|
} else {
|
||||||
|
uint8_t mode;
|
||||||
|
::Focus.read(mode);
|
||||||
|
switch (mode) {
|
||||||
|
case SpaceCadet::Mode::ON:
|
||||||
|
::SpaceCadet.settings_.mode = SpaceCadet::Mode::ON;
|
||||||
|
break;
|
||||||
|
case SpaceCadet::Mode::NO_DELAY:
|
||||||
|
::SpaceCadet.settings_.mode = SpaceCadet::Mode::NO_DELAY;
|
||||||
|
break;
|
||||||
|
case SpaceCadet::Mode::OFF:
|
||||||
|
default:
|
||||||
|
::SpaceCadet.settings_.mode = SpaceCadet::Mode::OFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Runtime.storage().put(settings_base_, ::SpaceCadet.settings_);
|
||||||
|
Runtime.storage().commit();
|
||||||
|
}
|
||||||
|
} else if (::Focus.inputMatchesCommand(input, cmd_timeout)) {
|
||||||
|
if (::Focus.isEOL()) {
|
||||||
|
::Focus.send(::SpaceCadet.settings_.timeout);
|
||||||
|
} else {
|
||||||
|
::Focus.read(::SpaceCadet.settings_.timeout);
|
||||||
|
|
||||||
|
Runtime.storage().put(settings_base_, ::SpaceCadet.settings_);
|
||||||
|
Runtime.storage().commit();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return EventHandlerResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EventHandlerResult::EVENT_CONSUMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace plugin
|
||||||
|
} // namespace kaleidoscope
|
||||||
|
|
||||||
|
kaleidoscope::plugin::SpaceCadetConfig SpaceCadetConfig;
|
Loading…
Reference in new issue