B4R Tutorial Correct this misconseption - "Call B4R subs from InLine c code" - see post #2

Discussion in 'B4R Tutorials' started by hatzisn, Sep 29, 2019.

  1. hatzisn

    hatzisn Active Member Licensed User

    Having had my work flow cut down in the middle by vicious "circumstances" I decided to let it all go and "go fishing" as mr. Miyaghi (Karate kid) would say. So I did some things I couldn't do while being on the run and today I remembered to deal again (just for fun) with a problem that bugged me in the past and I couldn't find a solution until today.

    The problem was how to combine the UTFT and URTouch libraries (http://rinkydinkelectronics.com/) to create interface in a TFT screen that can interact with B4R code. It was a firewall that you just couldn't go through so I figured out that I should go around it. All you have to do is call from your c code on tft clicks the voids firstbutton, secondbutton. There is also the possibility to activate the timer manually in the voids but my c knowledge to do this is limited and further more I do not know if the Timer Object in the B4R universe is a wrapper or not. Here is the solution:

    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region


    Sub Process_Globals
       
    Public Serial1 As Serial
       
    Private iSel As Int
       
    Dim tim As Timer
     
    End Sub

    Private Sub AppStart
       Serial1.Initialize(
    115200)
       
    Log("AppStart")
       iSel = -
    1
       tim.Initialize(
    "tim_Tick",200)
       tim.Enabled = 
    True
    End Sub


    Private Sub tim_Tick
        
    Select Case iSel
            
    Case -1
                
    '
            Case 1
                FirstCallThis
            
    Case 2
                ThenCallThis
        
    End Select
        iSel = -
    1
    End Sub

    Private Sub FirstCallThis
       
    End Sub

    Private Sub ThenCallThis
       
    End Sub


    #if C
    void firstbutton (B4R::Object* o) {
       b4r_main::_isel=1;
    }

    void secondbutton (B4R::Object* o) {
       b4r_main::_isel=2;
    }
    #End if
     
    Last edited: Sep 29, 2019
  2. thetahsk

    thetahsk Active Member Licensed User

    You can direkt call the members from the b4r_main class. There are the same calling conventions as by calling variables.

    Please rewrite your tutorial.


    Code:
    #ifndef b4r_main_h
    #define b4r_main_h

    class b4r_main {
    public:

    static void initializeProcessGlobals();
    static void _appstart();
    static void _firstcallthis();
    static void _process_globals();
    static B4R::
    Serial* _serial1;
    static Int _isel;
    static void _thencallthis();
    };

    #endif
    and a sample for demonstration

    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private iSel As Int

    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
      
        RunNative(
    "firstbutton",Null)
        
    Log("iSel=",iSel)
        RunNative(
    "secondbutton",Null)
        
    Log("iSel=",iSel)
        
    Log("That's it")
    End Sub


    Private Sub FirstCallThis
       iSel=
    1
    End Sub

    Private Sub ThenCallThis
        iSel=
    2
    End Sub


    #if C
    void firstbutton  (B4R::Object* o) {  b4r_main::_firstcallthis();}
    void secondbutton (B4R::Object* o) {  b4r_main:: _thencallthis();}
    #End if
     
    Last edited: Sep 30, 2019
    hatzisn likes this.
  3. hatzisn

    hatzisn Active Member Licensed User

    Hi @thetahsk. Can you please explain better the first piece of code? What is this? Do I have to do that in in line C or change the code generated by B4R using "static" ?
     
  4. hatzisn

    hatzisn Active Member Licensed User

    Never mind I've got it. It is the b4r_main.h. Thanks a lot. As long as for the tutorial I suppose it has to be moved to the B4R questions sub forum to correct this possible misconception of others also.
     
    thetahsk likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice