Start Tool for annex -basic Programms

Place your projects here
Post Reply
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Start Tool for annex -basic Programms

Post by RonS »

Hi @all, referring to my idea (see link)
[Local Link Removed for Guests]
the following small project has grown:
this small program reads the bas files from the StartUp folder and lists them for you to start by touch - however, the programs must also include an exit and return code - this way you get a closed system which you can completely control from the screen - I assume that everyone knows that the tool must be started via the 'autorun' entry on the Config page when the module is powered on.
image.png
I intentionally used no LVGL so that it also works on other older systems, for example, ESP32 + ILI9341.

Code: [Local Link Removed for Guests]

option.base 0

' Device initialization
if bas.device=161 then 'remove if you dont need it
  PIN.MODE 2, output ' backlight
  PIN(2) = 1
endif
' Einstellungen
BUTTON_HEIGHT = 64
BUTTON_MARGIN = 15
MIN_BUTTON_WIDTH = 80
CHAR_WIDTH =12
TEXT_PADDING = 30
BUTTONS_PER_ROW = 4
MAX_ROWS = 2
COLOR_BG = tft.rgb(240,240,240)    ' Hellgrau
COLOR_HEADER = tft.rgb(70,70,100)  ' Dunkelblau
COLOR_FOOTER = tft.rgb(90,90,120)  ' Mittelblau
COLOR_TEXT = tft.rgb(70,70,100)    ' dezent
COLOR_BTN = tft.rgb(102, 153, 204)   ' HellgraublauRGB(102, 153, 204)
COLOR_BTNP = tft.rgb(102, 153, 104)  
COLOR_BTN_TEXT = tft.rgb(50,50,50)
COLOR_FR = tft.rgb(0,0,12)
' Variablen
dim dvcnr$(200)
dim prgnr$(200)

' Gerätenamen
dvcnr$(1)="ESP32 devKit":dvcnr$(161)="MOD-8048S070C":dvcnr$(164)="MOD-8048S043C"
wlog "Running on: " + dvcnr$(bas.device)

' Bildschirmmaße
screenWidth = tft.width
screenHeight = tft.height

' GUI initialisieren
GUI.init 15,COLOR_FOOTER

' Header und Footer
rem Txt1 =GUI.Textline(x, y, width, height, "text" [,font] [,color_text] [,color_back] [,color_frame] [,alignment] [,margin] )
txt_Title = GUI.textline(0,0,screenWidth,30,"Start",4,COLOR_TEXT,COLOR_BG,COLOR_FR,4)
txt_Footer = GUI.textline(0,screenHeight-30,screenWidth,30,"Footer",4,COLOR_TEXT,COLOR_BG,COLOR_FR,4)
Gui.SetText txt_Title, "annex-RDS-WB V1 @ "+dvcnr$(bas.device)+" @ "+ WORD$(IP$,1)
Gui.SetText txt_Footer, "Memory Free @ Flash: "+str$(flashfree)+" @ Ram: "+str$(ramfree)
rem btn_close = gui.button(screenWidth-30,0,30,30,"x",4)
btn_close = gui.button(screenWidth-30,0,28,28,"x",2,5,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
' Programmnamen laden
cntr=0
d$ = FILE.DIR$("/StartUp/*.bas")
While D$ <> ""
  cntr=cntr+1
  prgnr$(cntr)=d$
  d$ = FILE.DIR$
Wend
 ' Button-Berechnung
rowY = screenHeight - 400
buttonSpacing = (screenWidth - (2 * BUTTON_MARGIN)) / BUTTONS_PER_ROW

' Erste Reihe (Buttons 1-4)
btnX = BUTTON_MARGIN
for col = 0 to BUTTONS_PER_ROW-1
  btnIndex = col + 1
  if btnIndex <= cntr then
 ' REPLACE$(expression$, find$, replacewith$)
    btnText$ =replace$( prgnr$(btnIndex),".bas","")
  else
    btnText$ = "Empty"
  endif
  
  btnWidth = len(btnText$) * CHAR_WIDTH + TEXT_PADDING
  if btnWidth < MIN_BUTTON_WIDTH then btnWidth = MIN_BUTTON_WIDTH
  
  ' Button 1-4 erstellen
 rem  But1 = GUI.Button(x, y, width, height, "text" [,font] [,radius] [,toggle] [,group] [,color_text] [,color_pressed] [,color_released] [,color_frame] )
  if col = 0 then
  
    btn_0_0 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_0_0, 1, ButtonEvent1
  elseif col = 1 then
    btn_0_1 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_0_1, 1, ButtonEvent2
  elseif col = 2 then
    btn_0_2 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_0_2, 1, ButtonEvent3
  elseif col = 3 then
    btn_0_3 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_0_3, 1, ButtonEvent4
  endif
  
  wlog "Button 0_" + str$(col) + " at " + str$(btnX) + " Text: " + btnText$
  btnX = btnX + buttonSpacing
next col

' Zweite Reihe (Buttons 5-8)
rowY = rowY + BUTTON_HEIGHT + BUTTON_MARGIN
btnX = BUTTON_MARGIN
for col = 0 to BUTTONS_PER_ROW-1
  btnIndex = BUTTONS_PER_ROW + col + 1
  if btnIndex <= cntr then
    btnText$ = prgnr$(btnIndex)
  else
    btnText$ = "Empty"
  endif
  
  btnWidth = len(btnText$) * CHAR_WIDTH + TEXT_PADDING
  if btnWidth < MIN_BUTTON_WIDTH then btnWidth = MIN_BUTTON_WIDTH
  
  ' Button 5-8 erstellen
  if col = 0 then
    btn_1_0 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_1_0, 1, ButtonEvent5
  elseif col = 1 then
    btn_1_1 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_1_1, 1, ButtonEvent6
  elseif col = 2 then
    btn_1_2 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
    if btnIndex <= cntr then gui.setevent btn_1_2, 1, ButtonEvent7
  elseif col = 3 then
    btn_1_3 = gui.button(btnX, rowY, btnWidth, BUTTON_HEIGHT, btnText$, 3, 15,,,COLOR_BTN_TEXT,COLOR_BTN,COLOR_BTNP,COLOR_FR)
   if btnIndex <= cntr then  gui.setevent btn_1_3, 1, ButtonEvent8
  endif
  
  wlog "Button 1_" + str$(col) + " at " + str$(btnX) + " Text: " + btnText$
  btnX = btnX + buttonSpacing
next col

gui.autorefresh 30, 1
wait 

ButtonEvent1:
  
  pause 100
  id=gui.target
 rem wlog  id
  pause 100
  wlog "Button pressed: " + str$(id)
  wlog "Button pressed: " + prgnr$(1)
  fname$= "/StartUp/" + prgnr$(1)
  wlog  bas.load  fname$
return

ButtonEvent2:
  
  pause 100
  id=gui.target
 rem wlog  id
  pause 100
  wlog "Button pressed: " + str$(id)
  wlog "Button pressed: " + prgnr$(2)
  fname$= "/StartUp/" + prgnr$(2)
  wlog  bas.load  fname$
return
ButtonEvent3:
  
  pause 100
  id=gui.target
 rem wlog  id
  pause 100
  wlog "Button pressed: " + str$(id)
  wlog "Button pressed: " + prgnr$(3)
  fname$= "/StartUp/" + prgnr$(3)
  wlog  bas.load  fname$
return
ButtonEvent4:
  pause 100
  id=gui.target
 rem wlog  id
  pause 100
  wlog "Button pressed: " + str$(id)
  fname$= "/StartUp/" + prgnr$(4)
  wlog  bas.load  fname$
return
ButtonEvent5:
  
  pause 100
  wlog "Button pressed: " + prgnr$(5)
  fname$= "/StartUp/" + prgnr$(5)
  wlog  bas.load  fname$
return
ButtonEvent6:
  
  pause 100
  wlog "Button pressed: " + prgnr$(6)
  fname$= "/StartUp/" + prgnr$(6)
  wlog  bas.load  fname$
return
ButtonEvent7:
  
  pause 100
  wlog "Button pressed: " + prgnr$(7)
  fname$= "/StartUp/" + prgnr$(7)
  wlog  bas.load  fname$
return
ButtonEvent8:
  
  pause 100
  wlog "Button pressed: " + prgnr$(8)
  fname$= "/StartUp/" + prgnr$(8)
  wlog  bas.load  fname$
  tft.save "/screendump.bmp"
return
if you want, you can also shorten the code by using the function
[Local Link Removed for Guests]
I did not do this because this function outputs relative values and not static ones - meaning a change in the code has significant effects.
try it out yourself I did not delete this parts
To end the started program, you can or must also add a button at the top right - Windows like.

Code: [Local Link Removed for Guests]

btn_close = gui.button(tft.Width-30,0,28,28,"x",2,5)
gui.setevent btn_close, 1, endtouch
LVGL Example:

Code: [Local Link Removed for Guests]

' End-Button 
  end_btn = lvgl.button "CLOSE"
  lvgl.set_font end_btn, 18
  lvgl.set_pos end_btn, 10, 15
  lvgl.set_size end_btn, 60, 40
  lvgl.add_event end_btn, 1, endtouch
with jump to:

Code: [Local Link Removed for Guests]

endtouch:
tft.fill white
wlog "closing"
rem play.stop 'for  radio
wlog bas.load "/annexWB.bas"
END
Code related:
Rows and columns and colors can be easily adjusted - you could also create entire complete color themes and upload them.
Of course, you can also use "image.button" - I just haven't found any suitable image sets yet.
I hope you enjoy trying it out, it works very well.

Ron
You do not have the required permissions to view the files attached to this post.
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
Starraker
Posts: 116
Joined: Tue Sep 03, 2024 1:53 am
Location: Canberra Australia
Been thanked: 29 times
Contact:

Re: Start Tool for annex -basic Programms

Post by Starraker »

Ron,

Nice!

I am still working on our problem. There are many others on GitHub also working on it.
Post Reply