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

hatzisn

Well-Known 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:

B4X:
#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:

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.


B4X:
#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

B4X:
#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:
Top