@@ -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+
2527FRESULT sd_fresult ;
2628FATFS sd_fs ;
2729FIL 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+
382389void 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
396430void 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)
511541void 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