Skip to content

Commit 7aa747e

Browse files
committed
hide profile title when printing legend
1 parent a8adadf commit 7aa747e

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

firmware/code/Inc/parser.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#ifdef __cplusplus
55
extern "C" {
6-
#endif
6+
#endif
77

88
#include "stm32f0xx_hal.h"
99
#include "buttons.h"
@@ -61,9 +61,12 @@ void change_profile(uint8_t dir);
6161
void handle_keypress(uint8_t keynum, but_status* b_status, ds3_exe_result* exe);
6262
void scan_profiles(void);
6363
uint8_t get_last_profile(void);
64+
uint32_t ms_since_last_profile_change(void);
65+
6466
void restore_profile(uint8_t profile_id);
6567
void keypress_wrapper(uint8_t keynum, ds3_exe_result* exe);
66-
void print_legend(void);
68+
void print_title(void);
69+
void print_legend(uint8_t hide_title);
6770
void save_settings(void);
6871
void load_settings(void);
6972
void save_last_profile(uint8_t profile_id);

firmware/code/Src/ds3_vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void execute_instruction(uint16_t curr_pc, ds3_exe_result* exe, uint8_t keynum)
283283
uint16_t op_data = make_uint16(byte0, byte1);
284284
current_key = keynum;
285285
// printf("PC: %04d | Opcode: %02d | 0x%02x 0x%02x | 0x%04x\n", curr_pc, this_opcode, byte0, byte1, op_data);
286-
286+
287287
exe->result = EXE_OK;
288288
exe->next_pc = curr_pc + INSTRUCTION_SIZE_BYTES;
289289
exe->data = 0;
@@ -524,7 +524,7 @@ void execute_instruction(uint16_t curr_pc, ds3_exe_result* exe, uint8_t keynum)
524524
}
525525
else if(this_opcode == OP_OLR)
526526
{
527-
print_legend();
527+
print_legend(0);
528528
}
529529
else if(this_opcode == OP_BCLR)
530530
{

firmware/code/Src/my_tasks.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ void keypress_task_start(void const * argument)
824824
if(is_pressed(0))
825825
{
826826
select_keymap();
827-
print_legend();
827+
print_legend(0);
828828
}
829829

830830
is_busy = 0;
@@ -850,7 +850,9 @@ void keypress_task_start(void const * argument)
850850
goto key_task_end;
851851
}
852852
if(i == KEY_BUTTON1 || i == KEY_BUTTON2)
853+
{
853854
handle_tactile_button_press(i);
855+
}
854856
if(hold_cache[i].type != KEY_TYPE_UNKNOWN && hold_cache[i].code != 0)
855857
{
856858
press_key(hold_cache[i].code, hold_cache[i].type);
@@ -903,7 +905,7 @@ void keypress_task_start(void const * argument)
903905
}
904906
if (this_exe.epilogue_actions & NEED_OLED_REFRESH)
905907
{
906-
print_legend();
908+
print_legend(0);
907909
}
908910
}
909911
}

firmware/code/Src/parser.c

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ static const uint8_t col_lookup[7][3] = {
2222
{0, 42, 85}
2323
};
2424

25+
uint32_t last_profile_change;
26+
2527
FRESULT sd_fresult;
2628
FATFS sd_fs;
2729
FIL sd_file;
@@ -379,6 +381,11 @@ uint8_t load_persistent_state(void)
379381
return 0;
380382
}
381383

384+
uint32_t ms_since_last_profile_change(void)
385+
{
386+
return HAL_GetTick() - last_profile_change;
387+
}
388+
382389
void load_profile(uint8_t pid)
383390
{
384391
char* profile_name = find_profile(pid);
@@ -391,6 +398,33 @@ void load_profile(uint8_t pid)
391398
if(load_persistent_state() != 0)
392399
redraw_bg();
393400
p_cache.current_profile = pid;
401+
last_profile_change = HAL_GetTick();
402+
}
403+
404+
#define TITLE_ROW 5
405+
#define NUM_OLED_ROWS 6
406+
#define TEXT_HEIGHT 12
407+
#define MARGIN_TOP 5
408+
409+
void print_title()
410+
{
411+
memset(temp_buf, 0, PATH_SIZE);
412+
sprintf(temp_buf, "profile%d_", p_cache.current_profile);
413+
char* pf_name = p_cache.profile_fn + strlen(temp_buf);
414+
415+
memset(temp_buf, 0, PATH_SIZE);
416+
sprintf(temp_buf, "=== P%d: %s ===", p_cache.current_profile, pf_name);
417+
418+
if(strlen(temp_buf) > 21)
419+
temp_buf[21] = 0;
420+
421+
int8_t y_start = TITLE_ROW * 10 + 2;
422+
int8_t x_start = (21 - strlen(temp_buf)) * 3;
423+
if(x_start < 0)
424+
x_start = 0;
425+
426+
ssd1306_SetCursor((uint8_t)x_start, y_start);
427+
ssd1306_WriteString(temp_buf, Font_6x10,White);
394428
}
395429

396430
void print_keyname(char* keyname, uint8_t keynum)
@@ -401,35 +435,31 @@ void print_keyname(char* keyname, uint8_t keynum)
401435
temp_buf[0] = '-';
402436
if(strlen(temp_buf) > 7)
403437
temp_buf[7] = 0;
438+
404439
uint8_t row = keynum / 3;
405440
uint8_t col = keynum - row * 3;
441+
406442
int8_t x_start = col_lookup[strlen(temp_buf) - 1][col];
407-
int8_t y_start = (row + 1) * 10 + 2;
443+
int8_t y_start = (row) * TEXT_HEIGHT + MARGIN_TOP;
408444
if(x_start < 0)
409445
x_start = 0;
410446
if(y_start < 0)
411447
y_start = 0;
448+
412449
ssd1306_SetCursor((uint8_t)x_start, (uint8_t)y_start);
413450
ssd1306_WriteString(temp_buf, Font_6x10,White);
414451
}
415452

416-
void print_legend(void)
453+
void print_legend(uint8_t hide_title)
417454
{
418455
ssd1306_Fill(Black);
419-
memset(temp_buf, 0, PATH_SIZE);
420-
sprintf(temp_buf, "profile%d_", p_cache.current_profile);
421-
char* pf_name = p_cache.profile_fn + strlen(temp_buf);
422-
memset(temp_buf, 0, PATH_SIZE);
423-
sprintf(temp_buf, "=== P%d: %s ===", p_cache.current_profile, pf_name);
424-
if(strlen(temp_buf) > 21)
425-
temp_buf[21] = 0;
426-
int8_t x_start = (21 - strlen(temp_buf)) * 3;
427-
if(x_start < 0)
428-
x_start = 0;
429-
ssd1306_SetCursor((uint8_t)x_start, 0);
430-
ssd1306_WriteString(temp_buf, Font_6x10,White);
456+
457+
// if(!hide_title)
458+
// print_title();
459+
431460
for (int i = 0; i < MAPPABLE_KEY_COUNT; ++i)
432461
print_keyname(p_cache.key_fn[i], i);
462+
433463
ssd1306_UpdateScreen();
434464
}
435465

@@ -511,7 +541,7 @@ void reset_hold_cache(void)
511541
void restore_profile(uint8_t profile_id)
512542
{
513543
load_profile(profile_id);
514-
print_legend();
544+
print_legend(0);
515545
save_last_profile(profile_id);
516546
reset_hold_cache();
517547
}

0 commit comments

Comments
 (0)