spleeb.h (4619B)
1 // Copyright 2022 Chris Hoage (@chrishoage) 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #pragma once 5 6 #include "quantum.h" 7 8 #if defined(SPLEEB_ENCODER_MODE_MAP_ENABLE) && !defined(ENCODER_ENABLE) 9 # error "Encoder must be enabled to use encoder mode map" 10 #endif 11 12 #if defined(SPLEEB_ENCODER_MODE_MAP_ENABLE) && defined(ENCODER_MAP_ENABLE) 13 # error "Encoder mode map can not be used with encoder map" 14 #endif 15 16 enum spleeb_keycodes { 17 POINTER_DEFAULT_DPI_FORWARD = QK_KB, 18 POINTER_DEFAULT_DPI_REVERSE, 19 POINTER_SNIPING_DPI_FORWARD, 20 POINTER_SNIPING_DPI_REVERSE, 21 SNIPING_MODE, 22 SNIPING_MODE_TOGGLE, 23 DRAGSCROLL_MODE, 24 DRAGSCROLL_MODE_TOGGLE, 25 ENC_MODE_STEP_LEFT, 26 ENC_MODE_STEP_RIGHT, 27 }; 28 29 #define DF_MOD POINTER_DEFAULT_DPI_FORWARD 30 #define DF_RMOD POINTER_DEFAULT_DPI_REVERSE 31 #define SP_MOD POINTER_SNIPING_DPI_FORWARD 32 #define SP_RMOD POINTER_SNIPING_DPI_REVERSE 33 #define SNIPING SNIPING_MODE 34 #define SNP_TOG SNIPING_MODE_TOGGLE 35 #define DRGSCRL DRAGSCROLL_MODE 36 #define DRG_TOG DRAGSCROLL_MODE_TOGGLE 37 #define ENC_STL ENC_MODE_STEP_LEFT 38 #define ENC_STR ENC_MODE_STEP_RIGHT 39 40 #ifdef POINTING_DEVICE_ENABLE 41 # ifndef SPLEEB_MINIMUM_DEFAULT_DPI 42 # define SPLEEB_MINIMUM_DEFAULT_DPI 300 43 # endif // SPLEEB_MINIMUM_DEFAULT_DPI 44 45 # ifndef SPLEEB_DEFAULT_DPI_CONFIG_STEP 46 # define SPLEEB_DEFAULT_DPI_CONFIG_STEP 100 47 # endif // SPLEEB_DEFAULT_DPI_CONFIG_STEP 48 49 # ifndef SPLEEB_MINIMUM_SNIPING_DPI 50 # define SPLEEB_MINIMUM_SNIPING_DPI 100 51 # endif // SPLEEB_MINIMUM_SNIPING_DPI 52 53 # ifndef SPLEEB_SNIPING_DPI_CONFIG_STEP 54 # define SPLEEB_SNIPING_DPI_CONFIG_STEP 100 55 # endif // SPLEEB_SNIPING_DPI_CONFIG_STEP 56 57 # ifndef SPLEEB_DRAGSCROLL_DIVISOR 58 # define SPLEEB_DRAGSCROLL_DIVISOR 64 59 # endif // !SPLEEB_DRAGSCROLL_DIVISOR 60 #endif // POINTING_DEVICE_ENABLE 61 62 #ifdef SPLEEB_ENCODER_MODE_MAP_ENABLE 63 # ifndef SPLEEB_ENCODER_MODE_COUNT 64 # define SPLEEB_ENCODER_MODE_COUNT 4 65 # endif 66 67 typedef struct { 68 uint8_t mode; 69 // Discriminate between array members which are (un)initialized 70 bool initalized; 71 } const spleeb_enc_mode_t; 72 73 const spleeb_enc_mode_t spleeb_encoder_mode_map[NUM_ENCODERS][SPLEEB_ENCODER_MODE_COUNT]; 74 75 // SPLEEB_ENC_MODE initializes the spleeb_enc_mode_t struct such that 76 // uninitialized mode_map members can be discriminated against when looking up 77 // mapped encoder modes. 78 # define SPLEEB_ENC_MODE(mode) \ 79 { mode, true } 80 #endif // SPLEEB_ENCODER_MODE_MAP_ENABLE 81 82 #ifdef POINTING_DEVICE_ENABLE 83 84 /** \brief Return the current DPI value for the pointer's default mode. */ 85 uint16_t spleeb_get_pointer_default_dpi(void); 86 87 /** 88 * \brief Update the pointer's default DPI to the next or previous step. 89 * 90 * Increases the DPI value if `forward` is `true`, decreases it otherwise. 91 * The increment/decrement steps are equal to SPLEEB_DEFAULT_DPI_CONFIG_STEP. 92 * 93 * The new value is persisted in EEPROM. 94 */ 95 void spleeb_cycle_pointer_default_dpi(bool forward); 96 97 /** 98 * \brief Same as `spleeb_cycle_pointer_default_dpi`, but do not write to 99 * EEPROM. 100 * 101 * This means that reseting the board will revert the value to the last 102 * persisted one. 103 */ 104 void spleeb_cycle_pointer_default_dpi_noeeprom(bool forward); 105 106 /** \brief Return the current DPI value for the pointer's sniper-mode. */ 107 uint16_t spleeb_get_pointer_sniping_dpi(void); 108 109 /** 110 * \brief Update the pointer's sniper-mode DPI to the next or previous step. 111 * 112 * Increases the DPI value if `forward` is `true`, decreases it otherwise. 113 * The increment/decrement steps are equal to SPLEEB_SNIPING_DPI_CONFIG_STEP. 114 * 115 * The new value is persisted in EEPROM. 116 */ 117 void spleeb_cycle_pointer_sniping_dpi(bool forward); 118 119 /** 120 * \brief Same as `spleeb_cycle_pointer_sniping_dpi`, but do not write to 121 * EEPROM. 122 * 123 * This means that reseting the board will revert the value to the last 124 * persisted one. 125 */ 126 void spleeb_cycle_pointer_sniping_dpi_noeeprom(bool forward); 127 128 /** \brief Whether sniper-mode is enabled. */ 129 bool spleeb_get_pointer_sniping_enabled(void); 130 131 /** 132 * \brief Enable/disable sniper mode. 133 * 134 * When sniper mode is enabled the dpi is reduced to slow down the pointer for 135 * more accurate movements. 136 */ 137 void spleeb_set_pointer_sniping_enabled(bool enable); 138 139 /** \brief Whether drag-scroll is enabled. */ 140 bool spleeb_get_pointer_dragscroll_enabled(void); 141 142 /** 143 * \brief Enable/disable drag-scroll mode. 144 * 145 * When drag-scroll mode is enabled, horizontal and vertical pointer movements 146 * are translated into horizontal and vertical scroll movements. 147 */ 148 void spleeb_set_pointer_dragscroll_enabled(bool enable); 149 #endif // POINTING_DEVICE_ENABLE