ESP8266 Developer Zone The Official ESP8266 Forum 2019-04-17T01:51:26+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=27735 2019-04-17T01:51:26+08:00 2019-04-17T01:51:26+08:00 https://bbs.espressif.com:443/viewtopic.php?t=27735&p=39650#p39650 <![CDATA[ets_putc and VAlist with PrintF]]> 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:

void * 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:

void 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.

Statistics: Posted by AgentSmithers — Wed Apr 17, 2019 1:51 am


]]>