TFT menu trouble

Recurrent H/W and software problems
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

TFT menu trouble

Post by Zim »

Hi Gents
Pulling my hair out again! I am trying to create a menu on a TFT display. I just want to move a cursor to four selections, but it freezes on the third line. It is certainly possible I am using the wrong approach. Can anyone see a obvious f___up? Annex32 1.43
Thanks
Zim

Code: [Local Link Removed for Guests]

 

CODE: xxxx.bas

--------------------------------------------------------------------------------

'Encoder esp32
tft.init 1
gui.init 20, black
Gui.AutoRefresh 30
txt0 = GUI.Textline(150,0,0,0, "Fuel Injectors", 5)  'x,y,w,h,text,fontsize
txt1 = GUI.Textline(150,70,0,0, "2 Minute Clean", 3)  'x,y,w,h,text,fontsize
txt2 = GUI.Textline(150,100,0,0, "4 Minute Clean", 3)  'x,y,w,h,text,fontsize
txt3 = GUI.Textline(150,130,0,0, "Idle Flow Test", 3)  'x,y,w,h,text,fontsize
txt4 = GUI.Textline(150,160,0,0, "WOT Flow Test", 3)  'x,y,w,h,text,fontsize


count = 3
S1 = 34
S2 = 35
PB = 25

pin.mode S1, input
pin.mode S2, input
pin.mode PB, input
interrupt S2, injector
wait

injector:
if pin(S1) = 0 then return   ' if the pin is high, returns back
if pin(S2) = pin(S1) then count = count - 1 else count = count + 1
if count < 4 then let count = 4 'gives a range of 4 - 7
if count > 7 then let count = 7



cursor4 = GUI.Textline(45,70,0,0, ">>",3,0)  'x,y,w,h,text,fontsize    'erases previous cursors
cursor5 = GUI.Textline(45,100,0,0, ">>",3,0)  'x,y,w,h,text,fontsize
cursor6 = GUI.Textline(45,130,0,0, ">>",3,0)  'x,y,w,h,text,fontsize
cursor7 = GUI.Textline(45,160,0,0, ">>",3,0)  'x,y,w,h,text,fontsize

if count = 4 then let cursor4 = GUI.Textline(45,70,0,0, ">>",3)  'x,y,w,h,text,fontsize  'invokes cursor as per count
if count = 5 then let cursor5 = GUI.Textline(45,100,0,0, ">>",3)  'x,y,w,h,text,fontsize
if count = 6 then let cursor6 = GUI.Textline(45,130,0,0, ">>",3)  'x,y,w,h,text,fontsize
if count = 7 then let cursor7 = GUI.Textline(45,160,0,0, ">>",3)  'x,y,w,h,text,fontsize
wlog count

return


20220913_214913.jpg
You do not have the required permissions to view the files attached to this post.
BeanieBots
Posts: 315
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 168 times
Been thanked: 102 times

Re: TFT menu trouble

Post by BeanieBots »

Hi Zim,
I can't claim to be any sort of export with the gui commands but I tried your code with some minor adjustments to suit my hardware.
The code itself looks like it should do what you expect but it locked up for me too.
I did a "ramfree" check and noticed that the ram drops for every itteration of the interrupt routine.
This suggests a memory leak.
I think (let me be clear, I only think) that it might be because you are re-declaring the gui bits rather than changing their data value.
To help debug, I would suggest cutting the code down to maybe just change some text for each menu, then re-build until the 'bug' re-appears.
Good luck, wish I could be more specific.
Edit: Might also be worth upgrading to 1.44.2 because the GUI bits were new in 1.43
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 119 times
Been thanked: 132 times

Re: TFT menu trouble

Post by AndyGadget »

As BB says, your problem is re-defining the gui elements in the interrupt routine. If you increase the gui.init value it runs for longer until it runs out of the defined space.

Once you've defined the element, you can modify it by the variable reference you've given it, like this :-

Code: [Local Link Removed for Guests]

tft.init 1
gui.init 20, black
Gui.AutoRefresh 30

txt0 = GUI.Textline(150,0,0,0, "Fuel Injectors", 5)  'x,y,w,h,text,fontsize
txt1 = GUI.Textline(150,70,0,0, "2 Minute Clean", 3)  'x,y,w,h,text,fontsize
txt2 = GUI.Textline(150,100,0,0, "4 Minute Clean", 3)  'x,y,w,h,text,fontsize
txt3 = GUI.Textline(150,130,0,0, "Idle Flow Test", 3)  'x,y,w,h,text,fontsize
txt4 = GUI.Textline(150,160,0,0, "WOT Flow Test", 3)  'x,y,w,h,text,fontsize

cursor4 = GUI.Textline(45,70,0,0, ">>",3)  'x,y,w,h,text,fontsize
cursor5 = GUI.Textline(45,100,0,0, ">>",3)  'x,y,w,h,text,fontsize
cursor6 = GUI.Textline(45,130,0,0, ">>",3)  'x,y,w,h,text,fontsize
cursor7 = GUI.Textline(45,160,0,0, ">>",3)  'x,y,w,h,text,fontsize

lc = 0

do
  count = lc+4
  lc = (lc + 1)mod 4
  gosub injector
  pause 2000
loop

wait

injector:

gui.settext cursor4, "  "
gui.settext cursor5, "  "
gui.settext cursor6, "  "
gui.settext cursor7, "  "

if count = 4 then gui.settext cursor4, ">>"
if count = 5 then gui.settext cursor5, ">>"
if count = 6 then gui.settext cursor6, ">>"
if count = 7 then gui.settext cursor7, ">>"

wlog count

return
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

Re: TFT menu trouble

Post by Zim »

Thanks for the quick response Gentlemen!

BB, I upgraded the firmware and check the Ramfree.....Thanks!

AndyGadget, You are spot on! Your example set me on the right path. Thanks so much for your help!!

Thanks
Zim
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 251 times
Been thanked: 128 times

Re: TFT menu trouble

Post by Zim »

AndyGadget
Even your "do loop" is a valuable example to me! Thanks again!


do
count = lc+4
lc = (lc + 1)mod 4
gosub injector
pause 2000
loop
Post Reply