Compare commits
34 Commits
f/handleHe
...
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 |
@ -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;
|
Loading…
Reference in new issue