mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-12-29 12:48:52 +06:00
df8a538489
* Userspace: muppetjones (#1) Add and update lily58 to work with userspace Add and update kyria keymap to work with userspace Add and update planck keymap with userspace Add etchamouse code and docs to userpace Add userspace Update mouse encoder for smoother movement. Encoder + mouse Added casemodes by andrewjrae * Rollback lily58 state reader and add missing GPL * Apply suggestions from code review Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Joel Challis <git@zvecr.com> * fix lily58 keymap * Updates to user and lily for muppetjones. Updated parameters for etchamouse for smoother mouse movement. Updated lily keymap and userspace to actually work together. * Update keyboards/lily58/keymaps/muppetjones/config.h Co-authored-by: Drashna Jaelre <drashna@live.com> * Updated keymaps and userspace * Little more cleanup. * Update keyboards/lily58/keymaps/muppetjones/rules.mk Co-authored-by: Ryan <fauxpark@gmail.com> * Rollback accidental libchibios update * Apply suggestions from code review Co-authored-by: Drashna Jaelre <drashna@live.com> * Update kyria keymap * Move kyria keymap to splitkb/kyria * Update planck keymap * Remove all changes to keyboards/lily58/lib/layer_state_reader.c * Update lily58 keymap * Recommended change * Update keymap readme * Update kyria keymap and userspace * Apply suggestions from code review Co-authored-by: Drashna Jaelre <drashna@live.com> * Renamed users/muppetjones/README.md to lc * Update keyboards/lily58/keymaps/muppetjones/config.h Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Ryan <fauxpark@gmail.com>
102 lines
3.5 KiB
C
102 lines
3.5 KiB
C
/* Copyright 2020 Stephen J. Bush
|
|
*
|
|
* 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, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 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 QMK_KEYBOARD_H
|
|
#include "etchamouse.h"
|
|
#include "pointing_device.h"
|
|
|
|
#if defined(POINTING_DEVICE_ENABLE) && defined(ENCODER_ENABLE)
|
|
|
|
/** Track movement separately in both directions. This will allow us to
|
|
* smooth out the movement along diagonals
|
|
*/
|
|
typedef struct {
|
|
bool clockwise : 1;
|
|
uint8_t count : 7;
|
|
uint16_t timer : 16;
|
|
uint16_t elapsed : 16;
|
|
} key_tracker_t;
|
|
|
|
static key_tracker_t tracker_x = {false, 0, 0, 0};
|
|
static key_tracker_t tracker_y = {false, 0, 0, 0};
|
|
|
|
/**
|
|
* @brief Calculate the mouse move units for the given tracker.
|
|
*
|
|
* By using a key tracker rederence, we can minimize the amount of space
|
|
* required on the stack. As we will have the tracker object, we will also
|
|
* take the clockwise direction into account, which completely internalizes
|
|
* the movement unit logic within this single function.
|
|
*
|
|
* @param tracker: Pointer to a key tracker object.
|
|
* @return A integer from -127 to 127
|
|
*/
|
|
static int8_t move_unit(key_tracker_t *tracker) {
|
|
if (0 == tracker->count) return 0;
|
|
|
|
const uint16_t modifier = TAPPING_TERM_MOUSE_ENCODER < tracker->elapsed ? 1 : (TAPPING_TERM_MOUSE_ENCODER - tracker->elapsed) >> 1;
|
|
uint16_t speed = MOUSEKEY_INITIAL_SPEED + MOUSEKEY_MOVE_DELTA * modifier * (tracker->count >> 1);
|
|
|
|
/* convert speed to USB mouse speed 1 to 127 */
|
|
speed = (uint8_t)(speed / (1000.0f / MOUSEKEY_INTERVAL));
|
|
speed = speed < 1 ? 1 : speed;
|
|
|
|
return (tracker->clockwise ? 1 : -1) * (speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed);
|
|
}
|
|
|
|
/**
|
|
* @brief Update key press tracker
|
|
*
|
|
* Update the time elapsed since the last keypress.
|
|
* If the key has not been pressed since the tapping term, then reset the count to zero.
|
|
* If the key was pressed, update the timer and increment the count.
|
|
* Number of keypresses will degrade based on tapping term and zero out based
|
|
* on the persistenc term.
|
|
*
|
|
* @param tracker: The object to update
|
|
* @param pressed: A boolean indicating whether or not the key was pressed
|
|
* @return None.
|
|
*/
|
|
static void update_tracker(key_tracker_t *tracker, bool pressed, bool clockwise) {
|
|
tracker->elapsed = timer_elapsed(tracker->timer);
|
|
if (pressed) {
|
|
tracker->timer = timer_read();
|
|
tracker->count += 1;
|
|
tracker->clockwise = clockwise;
|
|
} else if (TAPPING_TERM_PERSISTENCE < tracker->elapsed) {
|
|
tracker->count = 0;
|
|
} else if (TAPPING_TERM_MOUSE_ENCODER < tracker->elapsed) {
|
|
tracker->count >>= 1;
|
|
}
|
|
}
|
|
|
|
bool encoder_update_mouse(uint8_t index, bool clockwise) {
|
|
report_mouse_t curr_report = pointing_device_get_report();
|
|
|
|
update_tracker(&tracker_x, 0 == index, clockwise);
|
|
update_tracker(&tracker_y, 1 == index, clockwise);
|
|
|
|
curr_report.x += move_unit(&tracker_x);
|
|
curr_report.y += move_unit(&tracker_y);
|
|
|
|
pointing_device_set_report(curr_report);
|
|
pointing_device_send();
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif
|