@@ -88,6 +88,7 @@ void bmp_action_exec(keyevent_t event)
8888}
8989
9090static int sleep_enter_counter = -1 ;
91+ int reset_counter = -1 ;
9192
9293/** \brief Keyboard task: Do keyboard routine jobs
9394 *
@@ -229,6 +230,16 @@ void bmp_keyboard_task(void)
229230 BMPAPI -> app .enter_sleep_mode ();
230231 }
231232 }
233+
234+ // reset flag check
235+ if (reset_counter > 0 )
236+ {
237+ reset_counter -- ;
238+ if (reset_counter == 0 )
239+ {
240+ BMPAPI -> app .reset ();
241+ }
242+ }
232243}
233244
234245bmp_error_t nus_rcv_callback (const uint8_t * dat , uint32_t len )
@@ -277,6 +288,20 @@ char *strnstr(const char *haystack, const char *needle, size_t len) {
277288 return NULL ;
278289}
279290
291+ const char * strnchr (const char * haystack , char needle , size_t len ) {
292+ int i ;
293+ for (i = 0 ; i < len ; i ++ )
294+ {
295+ if (haystack [i ] == needle ) {
296+ return & haystack [i ];
297+ }
298+ else if (haystack [i ] == '\0' ) {
299+ return NULL ;
300+ }
301+ }
302+ return NULL ;
303+ }
304+
280305void parse_and_save_config (void )
281306{
282307 bmp_api_config_t config ;
@@ -315,7 +340,8 @@ void parse_and_save_keymap(void)
315340 {
316341 xprintf ("Update keymap. length:%d\r\n" , inst .keymap_idx );
317342 xprintf ("%d extended keycodes are found\r\n" , inst .ek_num );
318- BMPAPI -> app .set_keymap (keymap , inst .keymap_idx );
343+ xprintf ("keyboard:%s\r\n" , inst .layout_name );
344+ BMPAPI -> app .set_keymap (keymap , inst .keymap_idx , inst .layout_name );
319345 bmp_ex_keycode_num = inst .ek_num ;
320346 BMPAPI -> app .save_file (1 );
321347
@@ -460,9 +486,36 @@ static inline void update_keymap_string(bmp_api_config_t const * config,
460486 keymap_conv_inst .use_ascii = config -> keymap .use_ascii ;
461487 keymap_conv_inst .bmp_ek = bmp_ex_keycodes ;
462488
463- strcpy (str , "{\"layers\":\r\n" );
464- keymap_to_json_conv_layout (& keymap_conv_inst , str + 12 ,
465- len - 12 , config -> matrix .layout );
489+ char keyboard_name [32 ] = {0 };
490+ char layout_name [32 ] = {0 };
491+ const char * delimiter = strnchr (keymap_info -> layout_name , ':' , 32 );
492+
493+ if (delimiter != NULL )
494+ {
495+ memcpy (keyboard_name , keymap_info -> layout_name ,
496+ delimiter - keymap_info -> layout_name );
497+
498+ strncpy (layout_name , delimiter + 1 , sizeof (layout_name ));
499+ }
500+ else
501+ {
502+ strcpy (keyboard_name , config -> device_info .name );
503+ strcpy (layout_name , keymap_info -> layout_name );
504+ }
505+
506+
507+ strcpy (str , "{\"keyboard\":\"" );
508+ strcat (str , keyboard_name );
509+
510+ strcat (str , "\",\r\n\"keymap\":\"" );
511+ strcat (str , "\",\r\n\"layout\":\"" );
512+ strcat (str , layout_name );
513+
514+ strcat (str , "\",\r\n\"layers\":\r\n" );
515+ uint32_t header_len = strlen (str );
516+
517+ keymap_to_json_conv_layout (& keymap_conv_inst , str + header_len ,
518+ len - header_len , config -> matrix .layout );
466519 strcat (str , "}" );
467520 BMPAPI -> usb .create_file ("KEYMAP JSN" , (uint8_t * )str , strlen (str ));
468521}
@@ -567,7 +620,7 @@ void bmp_init()
567620 BMPAPI -> app .get_keymap_info (& keymap_info );
568621 if (keymap_info .len == 0 )
569622 {
570- BMPAPI -> app .set_keymap ((uint16_t * )keymaps , keymaps_len ()); // load default keymap
623+ BMPAPI -> app .set_keymap ((uint16_t * )keymaps , keymaps_len (), keymap_info . layout_name ); // load default keymap
571624 BMPAPI -> app .get_keymap_info (& keymap_info );
572625 }
573626
0 commit comments