Skip to content

Commit 024c6ad

Browse files
committed
Minor bug fixes
1 parent 4f99459 commit 024c6ad

File tree

4 files changed

+98
-72
lines changed

4 files changed

+98
-72
lines changed

main/keyboard_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757

5858
//deep sleep parameters, mind that reconnecting after deep sleep might take a minute or two
59-
#define SLEEP_MINS 5 // undefine if you do not need deep sleep, otherwise define number of minutes for deepsleep
59+
#define SLEEP_MINS 2 // undefine if you do not need deep sleep, otherwise define number of minutes for deepsleep
6060

6161
/*
6262
*---------------------------- Everything below here should not be modified for standard usage----------------------

main/keymap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "keyboard_config.h"
66
#include "keymap.h"
77

8-
// A bit different from QMK, default return you to the first layer, LOWER and raise increase/lower layer by order.
8+
// A bit different from QMK, default returns you to the first layer, LOWER and raise increase/lower layer by order.
99
#define DEFAULT 0x100
1010
#define LOWER 0x101
1111
#define RAISE 0x102

main/keypress_handles.c

+89-61
Original file line numberDiff line numberDiff line change
@@ -83,51 +83,77 @@ uint16_t check_led_status( uint16_t key ){
8383
// what to do on a media key press
8484
void media_control_send(uint16_t keycode ){
8585

86-
uint8_t media_state[1]={0};
87-
SET_BIT(media_state[0],(keycode-KC_MEDIA_NEXT_TRACK));
86+
uint8_t media_state[2] = {0};
87+
if(keycode == KC_MEDIA_NEXT_TRACK){
88+
media_state[1] = 10;
89+
}
90+
if(keycode == KC_MEDIA_PREV_TRACK ){
91+
media_state[1] = 111;
92+
}
93+
if(keycode == KC_MEDIA_STOP){
94+
media_state[1] = 12;
95+
}
96+
if(keycode == KC_MEDIA_PLAY_PAUSE){
97+
media_state[1] = 5;
98+
}
99+
if(keycode == KC_AUDIO_MUTE){
100+
media_state[1] = 1;
101+
}
102+
if(keycode == KC_AUDIO_VOL_UP){
103+
SET_BIT(media_state[0],6);
104+
}
105+
if(keycode == KC_AUDIO_VOL_DOWN){
106+
SET_BIT(media_state[0],7);
107+
}
108+
88109
xQueueSend(media_q,(void*)&media_state, (TickType_t) 0);
89-
vTaskDelay(5/portTICK_PERIOD_MS);
90110
}
91111

92112
void media_control_release(uint16_t keycode ){
93-
uint8_t media_state[1]={0};
113+
uint8_t media_state[2] = {0};
94114
xQueueSend(media_q,(void*)&media_state, (TickType_t) 0);
95-
vTaskDelay(5/portTICK_PERIOD_MS);
96115
}
97116

98117

118+
//used for debouncing
119+
static uint32_t millis() {
120+
return esp_timer_get_time() / 1000;
121+
}
99122

123+
uint32_t prev_time = 0;
100124
// adjust current layer
101125
void layer_adjust( uint16_t keycode ){
126+
uint32_t cur_time = millis();
127+
if(cur_time - prev_time > DEBOUNCE){
128+
if(layer_hold_flag == 0){
129+
switch(keycode){
130+
case DEFAULT:
131+
current_layout = 0;
132+
break;
102133

103-
if(layer_hold_flag == 0){
104-
switch(keycode){
105-
case DEFAULT:
106-
current_layout=0;
107-
break;
108-
109-
case LOWER:
110-
if(current_layout==0){
111-
current_layout=MAX_LAYER;
134+
case LOWER:
135+
if(current_layout == 0){
136+
current_layout = MAX_LAYER;
137+
break;
138+
}
139+
current_layout--;
112140
break;
113-
}
114-
current_layout--;
115-
break;
116141

117-
case RAISE:
118-
if(current_layout==MAX_LAYER){
119-
current_layout=0;
142+
case RAISE:
143+
if(current_layout == MAX_LAYER){
144+
current_layout = 0;
145+
break;
146+
}
147+
current_layout++;
120148
break;
121149
}
122-
current_layout++;
123-
break;
150+
#ifdef OLED_ENABLE
151+
xQueueSend(layer_recieve_q,&current_layout, (TickType_t) 0);
152+
#endif
153+
ESP_LOGI(KEY_PRESS_TAG,"Layer modified!, Current layer: %d ",current_layout);
124154
}
125-
#ifdef OLED_ENABLE
126-
xQueueSend(layer_recieve_q,&current_layout, (TickType_t) 0);
127-
#endif
128-
vTaskDelay(300/portTICK_PERIOD_MS);
129-
ESP_LOGI(KEY_PRESS_TAG,"Layer modified!, Current layer: %d ",current_layout);
130155
}
156+
prev_time = cur_time;
131157
}
132158

133159

@@ -140,29 +166,31 @@ uint8_t *check_key_state( uint16_t **keymap){
140166
uint8_t matrix_state[MATRIX_ROWS][MATRIX_COLS]={0};
141167
memcpy(matrix_state,matrix_states[pad], sizeof(matrix_state) );
142168

143-
for(uint8_t col=(MATRIX_COLS*pad); col < ((pad+1)*(MATRIX_COLS)); col++){
169+
for(uint8_t col = (MATRIX_COLS*pad); col < ((pad+1)*(MATRIX_COLS)); col++){
144170
for(uint8_t row=0; row <MATRIX_ROWS; row++){
145171

146-
uint16_t report_index=(2+col+row*KEYMAP_COLS);
172+
uint16_t report_index = (2+col+row*KEYMAP_COLS);
147173
keycode=keymap[row][col];
148174

149175
//checking if the keycode is transparent
150-
if(keycode==KC_TRNS){
151-
if(current_layout==0){
152-
keycode=*default_layouts[MAX_LAYER][row][col];
176+
if(keycode == KC_TRNS){
177+
if(current_layout == 0){
178+
keycode = *default_layouts[MAX_LAYER][row][col];
153179
}else{
154-
keycode=*default_layouts[current_layout-1][row][col];
180+
keycode = *default_layouts[current_layout-1][row][col];
155181
}
156182
}
157183

158-
led_status=check_led_status(keycode);
159-
if(matrix_state[row][col-MATRIX_COLS*pad]==1){
184+
led_status = check_led_status(keycode);
185+
if(matrix_state[row][col - MATRIX_COLS*pad] == 1){
160186

161187
//checking for layer hold
162-
if((keycode >=LAYER_HOLD_BASE_VAL)&&(keycode <= LAYER_HOLD_MAX_VAL)&&(layer_hold_flag == 0)){
188+
if((keycode >= LAYER_HOLD_BASE_VAL)&&(keycode <= LAYER_HOLD_MAX_VAL)&&(layer_hold_flag == 0)){
163189
prev_layout = current_layout;
164-
current_layout = (keycode-LAYER_HOLD_BASE_VAL);
165-
layer_hold_flag = 1;
190+
if(layer_hold_flag == 0){
191+
current_layout = (keycode - LAYER_HOLD_BASE_VAL);
192+
layer_hold_flag = 1;
193+
}
166194
#ifdef OLED_ENABLE
167195
xQueueSend(layer_recieve_q,&current_layout, (TickType_t) 0);
168196
#endif
@@ -172,24 +200,24 @@ uint8_t *check_key_state( uint16_t **keymap){
172200
}
173201

174202
// checking for layer adjust keycodes
175-
if((keycode>=LAYERS_BASE_VAL)&&(keycode<MACRO_BASE_VAL)){
203+
if((keycode >= LAYERS_BASE_VAL) && (keycode < MACRO_BASE_VAL)){
176204
layer_adjust(keycode);
177205
continue;
178206
}
179207

180208
// checking for macros
181-
if((keycode>=MACRO_BASE_VAL)&&(keycode<=LAYER_HOLD_BASE_VAL)){
209+
if((keycode >= MACRO_BASE_VAL) && (keycode<=LAYER_HOLD_BASE_VAL)){
182210
for(uint8_t i=0; i < 3; i++){
183-
uint16_t key=macros[MACRO_BASE_VAL-keycode][i];
184-
current_report[REPORT_LEN-1-i]=key;
185-
modifier|=check_modifier(key);
211+
uint16_t key = macros[MACRO_BASE_VAL - keycode][i];
212+
current_report[REPORT_LEN - 1 - i] = key;
213+
modifier |= check_modifier(key);
186214
printf("\nmodifier:%d",modifier);
187215
}
188216
continue;
189217
}
190218

191219
// checking for media control keycodes
192-
if((keycode>=KC_MEDIA_NEXT_TRACK)&&(keycode<=KC_AUDIO_VOL_DOWN)){
220+
if((keycode >= KC_MEDIA_NEXT_TRACK)&&(keycode <= KC_AUDIO_VOL_DOWN)){
193221
media_control_send(keycode);
194222
}
195223

@@ -199,16 +227,16 @@ uint8_t *check_key_state( uint16_t **keymap){
199227
// continue;
200228
// }
201229

202-
if(current_report[report_index]==0){
203-
modifier|=check_modifier(keycode);
204-
current_report[report_index]=keycode;
230+
if(current_report[report_index] == 0){
231+
modifier |= check_modifier(keycode);
232+
current_report[report_index] = keycode;
205233

206234
}
207235
}
208-
if(matrix_state[row][col-MATRIX_COLS*pad]==0){
236+
if(matrix_state[row][col - MATRIX_COLS*pad] == 0){
209237

210238
//checking for layer hold release
211-
if((layouts[prev_layout][row][col] >=LAYER_HOLD_BASE_VAL)&&(keycode <= LAYER_HOLD_MAX_VAL)&&(layer_hold_flag == 1)){
239+
if((layouts[prev_layout][row][col] >= LAYER_HOLD_BASE_VAL) && (keycode <= LAYER_HOLD_MAX_VAL) && (layer_hold_flag == 1)){
212240
current_layout = 0;
213241
layer_hold_flag = 0;
214242
#ifdef OLED_ENABLE
@@ -218,25 +246,25 @@ uint8_t *check_key_state( uint16_t **keymap){
218246
}
219247

220248
//checking if macro was released
221-
if((keycode>=MACRO_BASE_VAL)&&(keycode<=LAYER_HOLD_BASE_VAL)){
222-
for(uint8_t i=0; i < 3; i++){
223-
uint16_t key=macros[MACRO_BASE_VAL-keycode][i];
224-
current_report[REPORT_LEN-1-i]=0;
225-
modifier&=~check_modifier(key);
249+
if((keycode >= MACRO_BASE_VAL) && (keycode <= LAYER_HOLD_BASE_VAL)){
250+
for(uint8_t i = 0; i < 3; i++){
251+
uint16_t key = macros[MACRO_BASE_VAL-keycode][i];
252+
current_report[REPORT_LEN-1-i] = 0;
253+
modifier &= ~check_modifier(key);
226254
}
227255
}
228256

229-
if(current_report[report_index]!=0){
230-
if(led_status!=0){
231-
led_status=0;
257+
if(current_report[report_index] != 0){
258+
if(led_status != 0){
259+
led_status = 0;
232260
}
233261

234-
modifier&=~check_modifier(keycode);
235-
current_report[KEY_STATE[row][col]]=0;
236-
current_report[report_index]=0;
262+
modifier &= ~check_modifier(keycode);
263+
current_report[KEY_STATE[row][col]] = 0;
264+
current_report[report_index] = 0;
237265

238266
// checking for media control keycodes
239-
if((keycode>=KC_MEDIA_NEXT_TRACK)&&(keycode<=KC_AUDIO_VOL_DOWN)){
267+
if((keycode >= KC_MEDIA_NEXT_TRACK) && (keycode <= KC_AUDIO_VOL_DOWN)){
240268
media_control_release(keycode);
241269
}
242270
}

main/mk32_main.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ extern "C" void slave_scan(void *pvParameters){
172172
if(memcmp(&PAST_MATRIX, &MATRIX_STATE, sizeof MATRIX_STATE)!=0){
173173
DEEP_SLEEP = false;
174174
memcpy(&PAST_MATRIX, &MATRIX_STATE, sizeof MATRIX_STATE );
175-
176175
xQueueSend(espnow_matrix_send_q,(void*)&MATRIX_STATE, (TickType_t) 0);
177-
//vTaskDelay(5/portTICK_PERIOD_MS);
176+
178177
}
179178
}
180179
}
@@ -304,40 +303,39 @@ extern "C" void app_main()
304303
espnow_recieve_q = xQueueCreate(32,REPORT_LEN*sizeof(uint8_t));
305304
espnow_recieve();
306305
xTaskCreatePinnedToCore(espnow_update_matrix, "ESP-NOW slave matrix state", 4096, NULL, configMAX_PRIORITIES, NULL,1);
307-
ESP_LOGE("ESPNOW","initializezd");
306+
ESP_LOGI("ESPNOW","initializezd");
308307

309308
#endif
310309

311310

312311
//activate encoder functions
313312
#ifdef R_ENCODER
314-
ESP_LOGE("ENCODER","Encoder initializezd");
315313
r_encoder_setup();
316314
xTaskCreatePinnedToCore(encoder_report, "encoder report", 4096, NULL, configMAX_PRIORITIES, NULL,1);
317-
ESP_LOGE("encoder task","initializezd");
315+
ESP_LOGI("Encoder","initializezd");
318316
#endif
319317

320318
// Start the keyboard Tasks
321319
// Create the key scanning task on core 1 (otherwise it will crash)
322320
#ifdef MASTER
323321
xTaskCreatePinnedToCore(key_reports, "key report task", 4096, xKeyreportTask, configMAX_PRIORITIES, NULL,1);
324-
ESP_LOGE("Keyboard task","initializezd");
322+
ESP_LOGI("Keyboard task","initializezd");
325323
#endif
326324
//activate oled
327325
#ifdef OLED_ENABLE
328326
init_oled();
329327
xTaskCreatePinnedToCore(oled_task, "oled task", 4096, NULL, configMAX_PRIORITIES, &xOledTask,1);
330-
ESP_LOGE("Oled task","initializezd");
328+
ESP_LOGI("Oled","initializezd");
331329
#endif
332330

333331
#ifdef BATT_STAT
334332
init_batt_monitor();
335-
ESP_LOGE("Battery monitor","initializezd");
333+
ESP_LOGI("Battery monitor","initializezd");
336334
#endif
337335

338336
#ifdef SLEEP_MINS
339337
xTaskCreatePinnedToCore(deep_sleep, "deep sleep task", 4096, NULL, configMAX_PRIORITIES, NULL,1);
340-
ESP_LOGE("Sleep","initializezd");
338+
ESP_LOGI("Sleep","initializezd");
341339
#endif
342340

343341

0 commit comments

Comments
 (0)