Bug? Program stops using Type Timer in Module

rwblinn

Well-Known Member
Licensed User
Longtime User
When declaring a Timer Type in a Module, the program stops (hangs) at step Timer Initialize. No error during compile, link & upload.
B4X:
Type TLEDControl (PinOut As Pin, PinNr As Byte, Blink As Timer)

Main
B4X:
Private Sub AppStart
    serialLine.Initialize(115200)
    ' Call module
    LEDControl.Initialize(13)
End Sub

Module LEDControl
B4X:
Sub Process_Globals
    Type TLEDControl (PinOut As Pin, PinNr As Byte, Blink As Timer)
    Public LED As TLEDControl   
End Sub

Public Sub Initialize(Pin_Nr As Byte)
    Log("LED Control Initialize Pin: ", Pin_Nr)
    LED.PinOut.Initialize(Pin_Nr, LED.PinOut.MODE_OUTPUT)
    Log("LED Control Initialize Blink Timer")                    '<=== program stops here
    LED.Blink.Initialize("Blink_Tick", 2000)
    Log("LED Control Blink Timer Enabling")
    LED.Blink.Enabled = True
    Log("LED Control Initialize Done")
End Sub

Private Sub Blink_Tick
    Log("LED Control Blink Tick")
    LED.PinOut.DigitalWrite(Not(LED.PinOut.DigitalRead))
End Sub
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Please find attached.
 

Attachments

  • b4rtimertypeexample.zip
    1.3 KB · Views: 249

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code cannot work as LED.Blink and PinOut are just pointers. No memory is allocated to the objects themselves. For it to work you need to do something like:
B4X:
Sub Process_Globals
    Type TLEDControl (PinOut As Pin, PinNr As Byte, Blink As Timer, o As Object)
    Public LED As TLEDControl    
    Private Timer1 As Timer
    Private Pin1 As Pin
End Sub

Public Sub Initialize(Pin_Nr As Byte)
    LED.Pinout = Pin1
    LED.Blink = Timer1
    LED.PinOut.Initialize(Pin_Nr, LED.PinOut.MODE_OUTPUT)
    Log("LED Control Initialize Blink Timer")                    '<=== program stops here
    LED.Blink.Initialize("Blink_Tick", 2000)
    Log("LED Control Blink Timer Enabling")
    LED.Blink.Enabled = True
    Log("LED Control Initialize Done")
End Sub
 
Top