diff options
Diffstat (limited to 'keyboards/rubi/lib/encoder.c')
| -rw-r--r-- | keyboards/rubi/lib/encoder.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/keyboards/rubi/lib/encoder.c b/keyboards/rubi/lib/encoder.c new file mode 100644 index 000000000..06c25ad31 --- /dev/null +++ b/keyboards/rubi/lib/encoder.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2021 gregorio | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "rubi.h" | ||
| 19 | |||
| 20 | void change_encoder_mode(bool reverse) { | ||
| 21 | if (reverse) { | ||
| 22 | if (encoder_mode == 0) { | ||
| 23 | encoder_mode = _NUM_ENCODER_MODES - 1; | ||
| 24 | } else { | ||
| 25 | encoder_mode = encoder_mode - 1; | ||
| 26 | } | ||
| 27 | } else { | ||
| 28 | encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | uint16_t handle_encoder_cw(void) { | ||
| 33 | uint16_t mapped_code = 0; | ||
| 34 | |||
| 35 | if (oled_mode == OLED_MODE_CALC) { | ||
| 36 | layer_on(2); | ||
| 37 | return mapped_code; | ||
| 38 | } | ||
| 39 | |||
| 40 | switch (encoder_mode) { | ||
| 41 | default: | ||
| 42 | case ENC_MODE_VOLUME: | ||
| 43 | mapped_code = KC_VOLU; | ||
| 44 | break; | ||
| 45 | case ENC_MODE_MEDIA: | ||
| 46 | mapped_code = KC_MEDIA_NEXT_TRACK; | ||
| 47 | break; | ||
| 48 | case ENC_MODE_BRIGHTNESS: | ||
| 49 | mapped_code = KC_BRIGHTNESS_UP; | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | |||
| 53 | return mapped_code; | ||
| 54 | } | ||
| 55 | |||
| 56 | uint16_t handle_encoder_ccw(void) { | ||
| 57 | uint16_t mapped_code = 0; | ||
| 58 | |||
| 59 | if (oled_mode == OLED_MODE_CALC) { | ||
| 60 | layer_off(2); | ||
| 61 | return mapped_code; | ||
| 62 | } | ||
| 63 | |||
| 64 | switch (encoder_mode) { | ||
| 65 | default: | ||
| 66 | case ENC_MODE_VOLUME: | ||
| 67 | mapped_code = KC_VOLD; | ||
| 68 | break; | ||
| 69 | case ENC_MODE_MEDIA: | ||
| 70 | mapped_code = KC_MEDIA_PREV_TRACK; | ||
| 71 | break; | ||
| 72 | case ENC_MODE_BRIGHTNESS: | ||
| 73 | mapped_code = KC_BRIGHTNESS_DOWN; | ||
| 74 | break; | ||
| 75 | } | ||
| 76 | |||
| 77 | return mapped_code; | ||
| 78 | } | ||
| 79 | |||
| 80 | uint16_t handle_encoder_press(void) { | ||
| 81 | uint16_t mapped_code = 0; | ||
| 82 | if (get_highest_layer(layer_state) == 1) { | ||
| 83 | if (oled_mode == OLED_MODE_CALC) { | ||
| 84 | layer_on(3); | ||
| 85 | } | ||
| 86 | layer_off(1); | ||
| 87 | return mapped_code; | ||
| 88 | } else if (get_highest_layer(layer_state) == 2) { | ||
| 89 | if (oled_mode == OLED_MODE_CALC) { | ||
| 90 | layer_off(1); | ||
| 91 | layer_on(3); | ||
| 92 | } else { | ||
| 93 | layer_on(1); | ||
| 94 | } | ||
| 95 | layer_off(2); | ||
| 96 | return mapped_code; | ||
| 97 | } else if (get_highest_layer(layer_state) == 3) { | ||
| 98 | if (oled_mode == OLED_MODE_OFF) { | ||
| 99 | layer_off(3); | ||
| 100 | } | ||
| 101 | return mapped_code; | ||
| 102 | } | ||
| 103 | |||
| 104 | switch (encoder_mode) { | ||
| 105 | default: | ||
| 106 | case ENC_MODE_VOLUME: | ||
| 107 | mapped_code = KC_MUTE; | ||
| 108 | break; | ||
| 109 | case ENC_MODE_MEDIA: | ||
| 110 | mapped_code = KC_MEDIA_PLAY_PAUSE; | ||
| 111 | break; | ||
| 112 | } | ||
| 113 | |||
| 114 | return mapped_code; | ||
| 115 | } | ||
