- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
ESP printf support #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            phillipjohnston
  wants to merge
  5
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
pj/esp8266
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      64523cd
              
                Update ArduinoLogger to address usage on ESP8266, which defines printf
              
              
                phillipjohnston 5431f6e
              
                Add notes mentioning support for ESP8266 with native printf support
              
              
                phillipjohnston 989d096
              
                Generalize support beyond ESP8266
              
              
                phillipjohnston 8d847a3
              
                Resolve compilation failure in CircularBufferLogger.h with ESP8266
              
              
                phillipjohnston 6892dc7
              
                Address compilation error in non-ESP8266 case
              
              
                phillipjohnston File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #ifndef LAMBDA_HELPERS_H_ | ||
| #define LAMBDA_HELPERS_H_ | ||
| 
     | 
||
| /** Lambda Helper: Decay to Function Pointer | ||
| * | ||
| * When you need to convert a lambda with captures to a C pointer, | ||
| * such as when a callback interface doesn't provide a variable for private data | ||
| * which can store a `this` pointer, use this helper. | ||
| * | ||
| * @code | ||
| * int a = 100; | ||
| * auto b = [&](void*) {return ++a;}; | ||
| * | ||
| * // Converting lambda with captures to a C pointer | ||
| * void (*f1)(void*) = Lambda::ptr(b); | ||
| * f1(nullptr); | ||
| * printf("%d\n", a); // 101 | ||
| * | ||
| * // In case return value should be used | ||
| * int (*f3)(void*) = Lambda::ptr<int>(b); | ||
| * printf("%d\n", f3(nullptr)); // 103 | ||
| * | ||
| * // In case data is used | ||
| * auto b2 = [&](void* data) {return *(int*)(data) + a;}; | ||
| * int (*f4)(void*) = Lambda::ptr<int>(b2); | ||
| * int data = 5; | ||
| * printf("%d\n", f4(&data)); // 108 | ||
| * @endcode | ||
| * | ||
| * Source: https://stackoverflow.com/questions/7852101/c-lambda-with-captures-as-a-function-pointer | ||
| */ | ||
| struct Lambda | ||
| { | ||
| template<typename Tret, typename T> | ||
| static Tret lambda_ptr_exec(char data) | ||
| { | ||
| return (Tret)(*(T*)fn<T>())(data); | ||
| } | ||
| 
     | 
||
| template<typename Tret = void, typename Tfp = Tret (*)(char), typename T> | ||
| static Tfp ptr(T& t) | ||
| { | ||
| fn<T>(&t); | ||
| return (Tfp)lambda_ptr_exec<Tret, T>; | ||
| } | ||
| 
     | 
||
| template<typename T> | ||
| static void* fn(void* new_fn = nullptr) | ||
| { | ||
| static void* fn; | ||
| if(new_fn != nullptr) | ||
| { | ||
| fn = new_fn; | ||
| } | ||
| return fn; | ||
| } | ||
| }; | ||
| 
     | 
||
| #endif // LAMBDA_HELPERS_H_ | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line would cause compilation error if in ets_sys.h function declaration is as follows:
int ets_vprintf(int (*print_function)(int), const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));and this is the case for ArduCAM ESP8266 UNO
error:
arduino-logger/src/ArduinoLogger.h:293:35: error: invalid conversion from 'void (*)(char)' to 'int (*)(int)' [-fpermissive] ets_vprintf(callback, format, va); ^