Commit | Line | Data |
---|---|---|
9ac2ed28 JH |
1 | /* |
2 | This program is free software: you can redistribute it and/or modify | |
3 | it under the terms of the GNU General Public License as published by | |
4 | the Free Software Foundation, either version 2 of the License, or | |
5 | (at your option) any later version. | |
6 | ||
7 | This program is distributed in the hope that it will be useful, | |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | GNU General Public License for more details. | |
11 | ||
12 | You should have received a copy of the GNU General Public License | |
13 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | */ | |
15 | ||
8c4a5961 | 16 | #include "mechmini.h" |
69ab37fc | 17 | #include "rgblight.h" |
69ab37fc | 18 | #include "quantum.h" |
19 | ||
d281cd5c | 20 | #define MAX_BRIGHTNESS 15 |
21 | #define MAX_BRIGHTNESS_IOS 5 // max brightness suitable for iOS devices | |
22 | ||
afcf3a28 | 23 | #define _BL 0 |
24 | #define _FN1 1 | |
25 | #define _FN2 2 | |
26 | #define _FN3 3 | |
27 | #define _____ KC_TRNS | |
9ac2ed28 JH |
28 | |
29 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |
afcf3a28 | 30 | [_BL] = KEYMAP( |
31 | KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, | |
32 | KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENT, | |
33 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, MO(_FN2), | |
34 | KC_LCTL, KC_LGUI, KC_LALT, _____, KC_SPC, _____, MO(_FN1), MO(_FN3) | |
35 | ), | |
36 | [_FN1] = KEYMAP( | |
c7ebb0f9 | 37 | KC_GRAVE, _____, KC_UP, KC_MUTE, KC_VOLD, KC_VOLU, KC_MRWD, KC_MPLY, KC_MFFD, KC_SLCK, KC_PAUS, KC_DEL, |
afcf3a28 | 38 | KC_CAPS, KC_LEFT, KC_DOWN, KC_RIGHT, _____, _____, _____, KC_INS, KC_HOME, KC_PGUP, KC_PSCR, |
6cfb85f3 | 39 | _____, _____, M(0), M(1), M(2), _____, _____, KC_END, KC_PGDN, _____, _____, |
afcf3a28 | 40 | _____, _____, _____, _____, _____, _____, _____, _____ |
41 | ), | |
42 | [_FN2] = KEYMAP( | |
43 | KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, | |
44 | KC_CAPS, _____, _____, _____, _____, KC_LBRC, KC_RBRC, KC_BSLS, KC_MINS, KC_EQL, _____, | |
45 | _____, _____, _____, _____, _____, _____, _____, KC_SCLN, KC_QUOT, KC_SLSH, _____, | |
46 | _____, _____, _____, _____, _____, _____, _____, _____ | |
47 | ), | |
48 | [_FN3] = KEYMAP( | |
49 | KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, | |
6cfb85f3 | 50 | _____, M(3), M(4), M(5), _____, _____, _____, _____, _____, _____, _____, |
51 | _____, M(6), _____, _____, _____, _____, _____, _____, _____, _____, _____, | |
afcf3a28 | 52 | _____, _____, _____, _____, _____, _____, _____, _____ |
53 | ) | |
9ac2ed28 JH |
54 | }; |
55 | ||
afcf3a28 | 56 | /** |
57 | * Blank keymap | |
58 | [0] = KEYMAP( | |
59 | _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____ | |
60 | _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, | |
61 | _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, | |
62 | _____, _____, _____, _____, _____, _____, _____, _____ | |
63 | ) | |
64 | */ | |
65 | ||
25aa4742 | 66 | uint8_t current_level = 4; |
69ab37fc | 67 | int is_on = 0; |
68 | ||
6cfb85f3 | 69 | uint8_t r = 0xFF; |
70 | uint8_t g = 0xFF; | |
71 | uint8_t b = 0xFF; | |
72 | ||
73 | uint8_t max_brightness = MAX_BRIGHTNESS_IOS; | |
74 | ||
69ab37fc | 75 | enum macro_id { |
c7ebb0f9 | 76 | TOGGLE_RGB, |
77 | BRIGHTNESS_DOWN, | |
78 | BRIGHTNESS_UP, | |
79 | COLOR_1, | |
80 | COLOR_2, | |
81 | COLOR_3, | |
82 | ENABLE_MAX_BRIGHTNESS | |
9ac2ed28 | 83 | }; |
69ab37fc | 84 | |
85 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { | |
c7ebb0f9 | 86 | keyevent_t event = record->event; |
87 | ||
88 | switch (id) { | |
89 | case TOGGLE_RGB: | |
90 | if (event.pressed) { | |
91 | if (!is_on) { | |
92 | current_level = 4; | |
93 | is_on = 1; | |
94 | } else { | |
95 | is_on = 0; | |
96 | } | |
97 | } | |
98 | case BRIGHTNESS_DOWN: | |
99 | if (event.pressed && current_level > 0) { | |
100 | current_level--; | |
101 | } | |
102 | break; | |
103 | case BRIGHTNESS_UP: | |
104 | if (event.pressed && current_level < max_brightness) { | |
105 | current_level++; | |
106 | } | |
107 | break; | |
108 | case COLOR_1: // set to pink | |
25aa4742 | 109 | if (event.pressed) { |
110 | r = 0xFF; | |
111 | g = 0x81; | |
112 | b = 0xC2; | |
113 | } | |
c7ebb0f9 | 114 | break; |
115 | case COLOR_2: // set to cyan | |
25aa4742 | 116 | if (event.pressed) { |
117 | r = 0x00; | |
118 | g = 0xE0; | |
119 | b = 0xFF; | |
120 | } | |
c7ebb0f9 | 121 | break; |
122 | case COLOR_3: // set to white | |
25aa4742 | 123 | if (event.pressed) { |
124 | r = 0xFF; | |
125 | g = 0xFF; | |
126 | b = 0xFF; | |
127 | } | |
c7ebb0f9 | 128 | break; |
129 | case ENABLE_MAX_BRIGHTNESS: // enable all 16 brightness steps | |
25aa4742 | 130 | if (event.pressed) { |
131 | max_brightness = MAX_BRIGHTNESS; | |
132 | } | |
c7ebb0f9 | 133 | break; |
134 | } | |
135 | ||
136 | return MACRO_NONE; | |
69ab37fc | 137 | } |
138 | ||
139 | const uint16_t fn_actions[] PROGMEM = { | |
69ab37fc | 140 | }; |
141 | ||
142 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); | |
143 | ||
144 | uint8_t dim(uint8_t color, uint8_t opacity) { | |
145 | return ((uint16_t) color * opacity / 0xFF) & 0xFF; | |
146 | } | |
147 | ||
148 | void user_setrgb(uint8_t r, uint8_t g, uint8_t b) { | |
149 | uint8_t alpha = current_level * 0x11; | |
150 | rgblight_setrgb(dim(r, alpha), dim(g, alpha), dim(b, alpha)); | |
151 | } | |
152 | ||
153 | void matrix_scan_user(void) { | |
0b7df9f2 | 154 | if (!is_on) { |
69ab37fc | 155 | current_level = 0; |
6cfb85f3 | 156 | user_setrgb(r, g, b); |
157 | } else { | |
158 | user_setrgb(r, g, b); | |
69ab37fc | 159 | } |
160 | } |