B4R Question rTFT_eSPI: problem with getTouch

kkaminski

Member
Licensed User
Longtime User
hello,
I'm trying to use rTFT_eSPI wrapper to support ILI9488+ESP8266 with touch. My jobs works good, when I compile the code under ArduinoIDE, simple attempts under B4R fail.

The problem is using the TFT.GetTouch command.
The program calibrates correctly, saves data, and uses it after restarting, but when I use the getTouch function, it crashes.

logs:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (29):
epc1=0x40208d55 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffda0 end: 3fffffd0 offset: 0150
3ffffef0:  009500e3 3ffe8a4c 3ffee7ac 00000000
3fffff00:  00000000 000001f4 3ffee7ac 4020b9ac
3fffff10:  402169b8 3ffef94c 3ffee95c 00000000
3fffff20:  3fffff60 3ffef94c 3ffee95c 402060e5
3fffff30:  000000d7 0000013a 00000172 000001d5
3fffff40:  01000c00 00000d00 00000100 0000001f
3fffff50:  00000064 00000064 3ffee7ac 40207db7
3fffff60:  3fffff68 00000002 00000000 3ffeeb18
3fffff70:  40206070 4020600d 00000020 40100abc
3fffff80:  00000000 00000302 0000000c 3ffeeb18
3fffff90:  3fffdad0 3ffef94c 3ffee780 40205f84
3fffffa0:  00000000 00000000 3ffeeaec 40206a3f
3fffffb0:  3fffdad0 00000000 3ffeeaec 4020c304
3fffffc0:  feefeffe feefeffe 3fffdab0 40100e41
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v00059160
~ld
����n�r��n|�l�l`b��|r�l�n��n�l`��r�l�l� �AppStart
When the result is negative ("0"), everything is OK. However, when I touch the screen, i.e. TFT.GetTouch should be equal to "1", exception 29 occurs and the program is reset. (exccausel)

code:
testing code:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src


Sub Process_Globals
    Public Serial1 As Serial
'    Private wifi As ESP8266WiFi
    Private raf As RandomAccessFile
    Private LFS As LittleFS
    Private Calibration_File As String = "/TouchCalData1"
    Private Repeat_Cal As bool = False
    Public TFT As TFT_eSPI
    Public TFTid As Long
       
    Private clBkg As UInt = TFT.TFT_BLACK
    Private clButton As UInt = TFT.TFT_BLUE
    Private clText As UInt = TFT.TFT_YELLOW
   
    Public kwota(6) As Int = Array As Int(5,10,20,50,100,200)
'    Public Btn(9) As ButtonWidget

    Public div As ULong = 0
    Public scantime As ULong = 0
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
   
'    If wifi.Connect2("N_EXT", "Q7JT5FLVVMRM") Then
'        Log("Connected to network")
'    Else
'        Log("Failed to connect to network")
'    End If
   
    TFTid = TFT.Initialize(-1,-1)
    TFT.begin(0xFF)
    TFT.fillScreen(clBkg)
   
    touch_calibrate

    LCDStartScreen

    AddLooper("LocalLooper")
   
End Sub


Public Sub LocalLooper

    TFT.setCursor(10,10)
    TFT.setTextColor1(clText,clBkg,False)
    TFT.setTextSize(2)
   
    TFT.println(Millis/1000)    'visualization of a running loop
    Dim xy(2) As UInt
    Dim pressed As Byte = TFT.getTouch(xy,500)
   
    If pressed=1 Then
        Log(pressed,": ",xy(0)," / ",xy(1)," / ",TFT.getTouchRawZ)
    End If

   
End Sub



Public Sub LCDStartScreen
   
    TFT.fillScreen(clBkg)
    TFT.setTextColor(clText)
    TFT.setTextSize(1)
    For x=0 To 2
        For y=0 To 2
            TFT.fillRect(x*105+5,y*105+160,100,100,clButton)
        Next
    Next


End Sub

Sub touch_calibrate
    Dim calDatab(14) As Byte
    Dim calData(7) As UInt
    Dim calDataOK As bool = False
 
    '// check file system exists
    If (Not(LFS.Initialize)) Then
        Log("Formating file system")
        LFS.format
        If Not(LFS.Initialize) Then
            Do While True : Delay(100) : Loop
            End If
        End If
       
        '// check If calibration file exists And size is correct
        If (LFS.exists(Calibration_File)) Then
'            Log("sprawdzanie kalibracji")
            If (Repeat_Cal) Then
                '// Delete If we want To re-calibrate
                LFS.remove(Calibration_File)
            Else
                Dim f As bool = LFS.OpenRead(Calibration_File)
                If (f=True) Then
                    If (LFS.Stream.ReadBytes(calDatab,0, 14) = 14) Then
                        setUInt(calDatab,calData)
                        calDataOK = True
                    End If
                    LFS.close
                End If
            End If
        End If

        If calDataOK And Not(Repeat_Cal) Then
            '// calibration data valid
            TFT.setTouch(calData)
        Else
            '// data Not valid so recalibrate
            TFT.fillScreen(TFT.TFT_BLACK)
            TFT.setCursor(20, 0)
            TFT.setTextFont(2)
            TFT.setTextSize(1)
            TFT.setTextColor1(TFT.TFT_WHITE, TFT.TFT_BLACK,False)  '????

            TFT.println("Touch corners as indicated")

            TFT.setTextFont(1)
            TFT.println("")

            If (Repeat_Cal) Then
                TFT.setTextColor1(TFT.TFT_RED, TFT.TFT_BLACK,False)
                TFT.println("Set REPEAT_CAL to false to stop this running again!")
            End If

            TFT.calibrateTouch(calData, TFT.TFT_MAGENTA, TFT.TFT_BLACK, 15)

            TFT.setTextColor1(TFT.TFT_GREEN, TFT.TFT_BLACK,False)
            TFT.println("Calibration complete!")

            '// store data
            Dim f As bool = LFS.OpenReadWrite(Calibration_File)
            If (f=True) Then
                '      f.write((const unsigned char *)calData, 14)
                setByte(calData,calDatab)
                LFS.stream.WriteBytes(calDatab,0, 14)
                LFS.close()
            End If
        End If
    End Sub
   
Sub setByte(in() As UInt, out() As Byte)
    For i = 0 To 6
        out(i*2) = Bit.HighByte(in(i))
        out(i*2+1) = Bit.LowByte(in(i))
    Next
End Sub

Sub setUInt(in() As Byte, out() As UInt)
    Dim b(2) As Byte
    raf.Initialize(b,False)
    For i = 0 To 6
        raf.WriteByte(in(i*2),0)
        raf.WriteByte(in(i*2+1),8)
        out(i)=raf.ReadUInt16(0)
    Next
End Sub

Do you have any ideas?

Regards,
Krzysztof
 
Top