summaryrefslogtreecommitdiffstats
path: root/keyboards/uno/keymaps/default/keymap.c
blob: bb19ea7ddb9d763ec1d1013a0bf39522130620d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* Copyright 2020 Snipeye
 *
 * 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

enum uno_keycode
{
  UNO = SAFE_RANGE
};

static uint16_t pressTimer = 0xFFFF;
#define CUSTOM_LONGPRESS 150
#define CUSTOM_LONGERPRESS 750
#define CUSTOM_STRING "I can put a whole buncha text in here and type it all with a single keypress."
#define RESET_LENGTH 3000
const uint8_t PROGMEM RGBLED_RAINBOW_MOOD_INTERVALS[] = { 10, 25, 50 };

char stringToSend[2] = "a";
char maxLetter = 'z';

uint8_t presetCounter = 0;

#define COUNTER X_A


const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
      [0] = LAYOUT(
            UNO
          )
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
	switch (keycode) {
		case UNO:
            if (record->event.pressed) {
                pressTimer = timer_read();
            } else {
                uint16_t timeElapsed = timer_elapsed(pressTimer);
                switch (presetCounter) {
                    case 0:
                        SEND_STRING(SS_LCMD("n"));
                    break;
                    case 1:
                        SEND_STRING("Hello!");
                    break;
                    case 2:
                        SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"I am uno!");
                    break;
                    case 3:
                        SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"I can do all sorts of useless things!");
                    break;
                    case 4:
                        SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"And I have a built-in RGB LED!"SS_TAP(X_ENTER)SS_TAP(X_ENTER)SS_TAP(X_ENTER));
                        rgblight_sethsv_noeeprom(255, 255, 255);
                        rgblight_mode_noeeprom(RGBLIGHT_MODE_RAINBOW_MOOD);
                    break;
                    default:
                        if (timeElapsed < CUSTOM_LONGPRESS) {
                            // Normal press.  We're going to send the current letter and increment the counter.
                            SEND_STRING(SS_TAP(X_BSPACE));
                            send_string(stringToSend);
                            stringToSend[0]++;
                            if (stringToSend[0] > maxLetter) {
                                stringToSend[0] = 'a';
                            }
                        } else if (timeElapsed < CUSTOM_LONGERPRESS) {
                            // Long press, confirm the current letter, reset counter
                            stringToSend[0] = 'a';
                            send_string(stringToSend);
                        } else if (timeElapsed < RESET_LENGTH) {
                            // Longer press, display macro.
                            SEND_STRING(CUSTOM_STRING);
                        } else {
                            reset_keyboard();
                        }
                        presetCounter--;
                    break;
                }
                presetCounter++;
            }
        break;
    }
    return false;
}

void keyboard_post_init_user(void) {
    rgblight_enable_noeeprom();
    rgblight_sethsv_noeeprom(0, 0, 0);
    rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
}