@@ -84,34 +84,36 @@ char const *string_desc_arr[STRING_DESC_ARR_SIZE] =
8484 *   0x1234:0xABCD:productName 
8585 *   ^^^^^^ ^^^^^^ ^^^^^^^^^^^ 
8686 *    VID    PID      Name 
87-  *   - IDs' prefix should be `0x`, should NOT be `0X` 
8887 *   - Length of productName should be less than or equal 32 bytes 
8988 * and any other letter must not be included in the file. 
9089 */ 
91- #define  PRK_CONF_LENGTH  (7 + 7 + 32 )
90+ #define  PRK_CONF_MAX_LENGTH  (7 + 7 + 33 + 2 )
9291static  void 
9392configure_prk (void )
9493{
94+   static  char  prk_conf [PRK_CONF_MAX_LENGTH ] =  {0 };
9595  DirEnt  entry ;
96-   uint8_t  buf [PRK_CONF_LENGTH  +  1 ] =  {0 };
97-   uint8_t  vid [7 ] =  {0 };
98-   uint8_t  pid [7 ] =  {0 };
99-   static  char  name [PRK_CONF_LENGTH  -  14 ] =  {0 };
10096  msc_findDirEnt ("PRK-CONFTXT" , & entry );
10197  if  (entry .Name [0 ] !=  '\0' ) {
102-     if  (entry .FileSize  >  PRK_CONF_LENGTH ) return ;
103-     msc_loadFile (buf , & entry );
104-     if  (strncmp ("0x" , buf , 2 ) ||  strncmp (":0x" , buf  +  6 , 3 )) return ;
105-     memcpy (vid ,  buf      , 6 );
106-     memcpy (pid ,  buf  +   7 , 6 );
107-     memcpy (name , buf  +  14 , strlen (buf ) -  14 );
108-     for  (int  i  =  0 ; ; i ++ ) {
109-       if  (name [i ] ==  '\r'  ||  name [i ] ==  '\n' ) name [i ] =  '\0' ;
110-       if  (name [i ] ==  '\0' ) break ;
98+     if  (entry .FileSize  >  PRK_CONF_MAX_LENGTH ) return ;
99+     msc_loadFile (prk_conf , & entry );
100+     char  * tok  =  strtok (prk_conf , ":" );
101+     for  (int  i  =  0 ; i  <  3 ; i ++ ) {
102+       if  (tok  ==  NULL ) break ;
103+       switch  (i ) {
104+         case  0 :
105+           desc_device .idVendor   =  (uint16_t )strtol (tok , NULL , 16 );
106+           tok  =  strtok (NULL , ":" );
107+           break ;
108+         case  1 :
109+           desc_device .idProduct  =  (uint16_t )strtol (tok , NULL , 16 );
110+           tok  =  strtok (NULL , ": \t\n\r" );
111+           break ;
112+         case  2 :
113+           string_desc_arr [2 ] =  (const  char  * )tok ;
114+           break ;
115+       }
111116    }
112-     desc_device .idVendor   =  (uint16_t )strtol (vid , NULL , 16 );
113-     desc_device .idProduct  =  (uint16_t )strtol (pid , NULL , 16 );
114-     string_desc_arr [2 ] =  (const  char  * )name ;
115117  }
116118}
117119
@@ -210,7 +212,7 @@ create_keymap_task(mrbc_tcb *tcb)
210212  if  (entry .Name [0 ] !=  '\0' ) {
211213    RotaryEncoder_reset ();
212214    uint32_t  fileSize  =  entry .FileSize ;
213-     console_printf ("Size of  keymap.rb: %u\n" , fileSize );
215+     console_printf ("keymap.rb size : %u\n" , fileSize );
214216    if  (fileSize  <  MAX_KEYMAP_SIZE ) {
215217      keymap_rb  =  malloc (KEYMAP_PREFIX_SIZE  +  fileSize  +  1 );
216218      keymap_rb [KEYMAP_PREFIX_SIZE  +  fileSize ] =  '\0' ;
@@ -222,7 +224,7 @@ create_keymap_task(mrbc_tcb *tcb)
222224      si  =  StreamInterface_new (NULL , SUSPEND_TASK , STREAM_TYPE_MEMORY );
223225    }
224226  } else  {
225-     console_printf ("No keymap.rb found. \n" );
227+     console_printf ("No keymap.rb found! \n" );
226228    si  =  StreamInterface_new (NULL , SUSPEND_TASK , STREAM_TYPE_MEMORY );
227229  }
228230  if  (!Compiler_compile (p , si , NULL )) {
0 commit comments