You can chat about native SDK questions and issues here.

User avatar
By Agentsmithers
#81704 Anyone know how to get vasprintF to operate?
I am trying to hook os_printf() to allow it to pass through multiple functions however I can't seem to get the VA list to render correctly via passing as arg to a nested function..

For my function below I keep getting undefined but when I replace it with something else I get Invalid Reach. Anyone get this little sniplet to work?


Code: Select allvoid * user_printfHook[2] = {NULL, NULL};
void * ICACHE_FLASH_ATTR user_printf(const char *s, ...)
{
   /*
   os_printf("[%s]\n", __func__);
   int i=0;
   os_printf("a");
   for (i=0; i<(sizeof(user_printfHook)/4); i++)
   {
   os_printf("b");
      if (user_printfHook[i] != NULL)
      {
         os_printf("c");
         ((void (*)(const char *))user_printfHook[i])(s);
      }
   }
   */
   os_printf("1");
   va_list args;
   os_printf("2");
   va_start(args, s);
   os_printf("3");
   ets_vprintf(ets_putc, s, args);
   os_printf("4");
   va_end(args);
   os_printf("5");
}



*Update*
This works fine...
Code: Select allvoid write_mychar(char ch)
{
   os_printf("%c", ch);
}

void * ICACHE_FLASH_ATTR user_printf(const char *s, ...)
{
   int i=0;
   for (i=0; i<(sizeof(user_printfHook)/4); i++)
   {
      if (user_printfHook[i] != NULL)
      {
         ((void (*)(const char *))user_printfHook[i])(s);
      }
   }
   va_list args;
   va_start(args, s);
   ets_vprintf(write_mychar, s, args);
   va_end(args);
}


I think this ultimately needs to point to ets_putc or something but it appears undefined.
User avatar
By Agentsmithers
#81840 I got it :)
Much faster
Code: Select allextern int  ets_putc(int);
void * ICACHE_FLASH_ATTR user_printf(const char *s, ...)
{
   int i=0;
   for (i=0; i<(sizeof(user_printfHook)/4); i++)
   {
      if (user_printfHook[i] != NULL)
      {
         ((void (*)(const char *))user_printfHook[i])(s);
      }
   }
   va_list args;
   va_start(args, s);
   //ets_vprintf(write_mychar, s, args);
   ets_vprintf(ets_putc, s, args);
   va_end(args);
}