Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 08:35 20 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Question about Touch

     Page 1 of 3    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:56am 26 Aug 2017
Copy link to clipboard 
Print this post

I've got 3 buttons on my SSD1963 display and what I want them to IDEALLY do is
interrupt a program once touched
and display completely different values in GUI Numberboxes

An example of the what I'm trying to do
[code]
ctrlval(4)=humidity
ctrlval(5)=temp[/code]

I call this in a loop in the main program
What I want is stop this loop and change the values to other values
Its the weather display and the 3 switches are Tomorrow, Day2 and Day3
The Numberboxes will display the values for the relevant day and stay on the screen for a set period of time say 10 or 20 seconds and then the program go back to normal
Displaying and doing what it was done before the switch was touched.


I haven't set touch up yet I'll do that once I know if this can be done

It will involve interupts which I know nothing about yet, but the main bit is can the main program do/loop be interrupted and the ctrlvals be changed temporarily while the forcast is displaying?


Ideally i'd love the time on the display to carry on updating but I guess this isn't possible while the main program is interrupted - IF it can be interrupted!

Program below2017-08-26_195645_weather2-test.zip
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 05:36pm 26 Aug 2017
Copy link to clipboard 
Print this post

I'm short of time but all the things you want are easily done.

Geoff has made these interrupts easy in MMBasic, only a few thing to consider and they are mentioned in the manual.

Mike.

EDIT: Had a quick look at the code, you have a timer ISR so I'm unsure about the time update question, Looks like you have everything there to add touch interrupt.

The loop will stall while you service the touch interrupt, but the trick with any interrupt is to process things really fast and set a flag and hand off any longer processing back to the main loop for the loop to process when flagged. The Timer interrupt should keep the time display updated. Looks really neat so far.

You mentioned you haven't set up Touch as yet - I assume the controller itself? Once touch is set, touching a GUI Numberbox will open an on screen keypad. Perhaps I've missed or misunderstood something in my haste, apology of so.
Edited by KeepIS 2017-08-28
It's all too hard.
Mike.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 09:51pm 26 Aug 2017
Copy link to clipboard 
Print this post

EXIT DO is useful for dealing with changing GUI stuff DEPENDING on exactly how you want to handle your loop(s)....

In one of my GUI programs, I use GUI touch buttons to set a flag only(as touch interrupts should be as short as possible), and detect that touch as part of the main loop via the use of said flag.

For example, take this slice of code:

  Quote   '---------------
'MESSAGING MENU:
'---------------
MESSAGING:
If DEBUG then Print "Messaging menu."
CtrlVal(SM_TXT)="##ENTER MESSAGE HERE..."
PAGE 20,4 'Messaging and EXIT/OK buttons
If PROMPTING then
CHDIR "\SYSTEM"
PLAY WAV
"STAFF.NSF"
Endif
GUI Interrupt EXIT_OK
Timer=0:Y=0
Do
If LCD_EXIT then
LCD_EXIT=
0 'Clear flag
If DEBUG then Print "EXIT button touched.(send a message)"
Y=
1
Endif
If LCD_OK then
LCD_OK=
0 'Clear flag
If DEBUG then Print "OK button touched.(send a message)"
MSG$=
CtrlVal(SM_TXT)
SEND_PAGE(
"",MSG$,"[MANUAL MESSAGE]")
Y=
1
Endif
If Timer>=SSDELAY*2 then Y=1 'Auto-abort if no button touched.
If Y then EXIT Do
LOOP
ON Y GOTO START


In this example, the DO/LOOP waits for a timeout, or a touch of either the OK or EXIT buttons setup elsewhere in the code. As the GUI INTERRUPT sets or clears these flags, all the DO/LOOP has to do, is wait for one of those flags to be true or a timeout to occur to exit. IE: Start the loop running, and then the GUI INTERRUPT will set the flags OUTSIDE of the running loop, which the loop will then detect and act upon. It is rather confusing for a start, until you get your head around how the GUI and GUI interrupts actually work.

Back to the example above, assuming OK is touched, then the touch flag LCD_OK is set via the gui interrupt, and the IF/THEN picks up on that, LCD_OK is cleared for the next time, the CTRLVAL is changed for the GUI control in question, the data is sent away to be paged via the SEND_PAGE sub, then Y is set to one - this is the important bit.

Setting Y allows for a clean-exit from the DO/LOOP, so that you won't have any loop/stack overflows, which can happen surprisingly quickly if you don't exit cleanly from loops when dealing with GUI stuff. Same thing applies to other loops like FOR/NEXT.

Anyhoo, with Y set to one, the last line of the DO/LOOP checks this flag, and if it is set, it exits from the loop, and moves on to the next thing.

Loops are amazingly useful, and without the EXIT command, loops in MMBASIC would probably NOT be as amazingly useful as they are now.

Smoke makes things work. When the smoke gets out, it stops!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 10:37pm 26 Aug 2017
Copy link to clipboard 
Print this post

Thanks both of you
I'll have a go at it later today
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 04:24pm 27 Aug 2017
Copy link to clipboard 
Print this post

Here is the GUI interrupt routine, just so you can see how it works in relation to the example above.

  Quote  SUB EXIT_OK 'Touch interrupt for EXIT and OK buttons on any page
LCD_EXIT=0:LCD_OK=0 'Clear flags
Select Case Touch(REF)
Case BU_EXIT 'EXIT button touched
LCD_EXIT=1
Case BU_OK 'OK button touched
LCD_OK=1
End Select
End SUB


Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 05:23pm 27 Aug 2017
Copy link to clipboard 
Print this post

Lew,
your program has many places where you have mixed single line IFs with multiple line IF's

This is one example:
  Quote  SUB SERIAL1
N = GetFieldArray(B$)
IF LEFT$(B$,4) = "STXG" THEN PRINT "Searching for gps lock"
IF LEFT$(B$,4) = "STXT" THEN TIME1
END IF
END IF
IF LEFT$(B$,4) = "STXW" THEN WEATHER
END IF
END SUB



It should be:
  Quote  SUB SERIAL1
N = GetFieldArray(B$)
IF LEFT$(B$,4) = "STXG" THEN PRINT "Searching for gps lock"
IF LEFT$(B$,4) = "STXT" THEN TIME1
IF LEFT$(B$,4) = "STXW" THEN WEATHER
END SUB

if you want single line IFs or

  Quote  SUB SERIAL1
N = GetFieldArray(B$)
IF LEFT$(B$,4) = "STXG" THEN
PRINT "Searching for gps lock"
ENDIF
IF LEFT$(B$,4) = "STXT" THEN
TIME1
ENDIF
IF LEFT$(B$,4) = "STXW" THEN
WEATHER
ENDIF
END SUB

for multiple line IFs

There are other places where you have the same error.

Jim
Jim
VK7JH
MMedit   MMBasic Help
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:19pm 27 Aug 2017
Copy link to clipboard 
Print this post

Thanks I'll have a go at the touch later in the week and get it working :)
  Grogster said   Here is the GUI interrupt routine, just so you can see how it works in relation to the example above.

  Quote  SUB EXIT_OK 'Touch interrupt for EXIT and OK buttons on any page
LCD_EXIT=0:LCD_OK=0 'Clear flags
Select Case Touch(REF)
Case BU_EXIT 'EXIT button touched
LCD_EXIT=1
Case BU_OK 'OK button touched
LCD_OK=1
End Select
End SUB

 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:23pm 27 Aug 2017
Copy link to clipboard 
Print this post

  TassyJim said   Lew,
your program has many places where you have mixed single line IFs with multiple line IF's

This is one example:
  Quote  SUB
It should be:
[QUOTE>SUB SERIAL1
N = GetFieldArray(B$)
IF LEFT$(B$,4) = "STXG" THEN PRINT "Searching for gps lock"
IF LEFT$(B$,4) = "STXT" THEN TIME1
IF LEFT$(B$,4) = "STXW" THEN WEATHER
END SUB

Jim


Do I not need ENDIF doing it this way?

And yes this looks much better than the way I have it at the moment. and I did intend to "clean up" the code once it's all working.
However it might be better to do it now before I do any more work on it
Apart from looking much cleaner. It will also make it easier to read what each bit is doing
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 09:43pm 27 Aug 2017
Copy link to clipboard 
Print this post

I can't get my head round one thing

How does the micromite know that the touch is an interrupt?
In the manual it says they work the same as an input from a digital pin and to use the SETPIN function to set it up

I have 3 "interrupts" I want to use (boxes on the screen with the following writing in them

1 "Tomorrow"
2 "Day 2"
3 "Day 3"

When one of the buttons is pressed I need a set of commands the program is doing ... displaying various readings from the external weather board to then "drop those readings" and display new values
There are a max of 10 values that need changing
Then
EITHER after say 10 seconds the display goes back to normal
OR another button is touched it then displays those values and again after the set time goes back to the normal running programs display



 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 10:06pm 27 Aug 2017
Copy link to clipboard 
Print this post

Hi Lewis,

The reason the day is still not updating is that the variables day, month, year are being used as global variables (They are not explicitly declared with
DIM day,month, year
but you can used them on the fly because you don't use
Option Explicit)
In the Sub UpdateTime they are declared as Local Variables, so the line
Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2))
which updates them is updating them within the Sub only. The Global year,month,day are not updated, hence when used in the TEXT statement are not changing as you expect.


Sub UpDateTime ' called by 1 second interrupt from SetTick

Local hrs,mins,secs,day,month,year
....
....
Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2))



A fix is to change the Local declaration to not include them.i.e
Local hrs,mins,secs
and add
DIM year,month,day
at the top of the program.

Using
Option Explicit
is really a good idea to help catch these things as you go.

Regards
Gerry
Latest F4 Latest H7
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 10:13pm 27 Aug 2017
Copy link to clipboard 
Print this post

  lew247 said   I can't get my head round one thing

How does the micromite know that the touch is an interrupt?
In the manual it says they work the same as an input from a digital pin and to use the SETPIN function to set it up


On an MM+ the command below is used to tell it touch is an interrupt. The SETPIN to define the interrupt is used for the MM

' Touch is interrupt driven
GUI INTERRUPT PenDown
Latest F4 Latest H7
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 05:47pm 28 Aug 2017
Copy link to clipboard 
Print this post

[Quote=lew247]I can't get my head round one thing

How does the micromite know that the touch is an interrupt?
In the manual it says they work the same as an input from a digital pin and to use the SETPIN function to set it up[/Quote]

Yes, disco4now is right, and expanding on his post:

The standard 28-pin Micromite uses an I/O pin connected to the INT line from the touch-controller, and you set that pin up as an interrupt. When the display is touched, THE TOUCH CONTROLLER signals on the INT line - which is connected to the 28-pin Micromite interrupt input, so the Micromite knows that the touch controller wants attention.

On the MM+(E64 or E100 etc), this is handled a little more elegantly via the GUI INTERRUPT command - no need to specify a pin, as this is pre-defined when you setup the GUI on the plus or extreme series.

In my example above, EXIT_OK is the interrupt sub that the MM+ jumps to whenever a GUI control is touched. We home in on only specific controls to pay attention to, by setting up different GUI interrupts to look at different buttons, at different times within the code.

So, again with my example above, EXIT_OK is the interrupt, and we point to THAT interrupt with the line in the main code just above the loop - GUI INTERRUPT EXIT_OK

That done, ANY TOUCH on the LCD will result in the MM+/MMX hopping on over to the EXIT_OK interrupt(sub) to find out which button it is. Now, if you touch a control not listed within the interrupt, the MM essentially just ignores it - this is why having multiple interrupts for the GUI is so useful - you don't need to check ALL the GUI controls, only the ones you know are going to be relevant at any given time.

GUI stuff IS very confusing for a start. I lost quite a lot of hair in the beginning, but once you get it clear in your head how the code kinda 'Jumps around' so to speak, they are a great thing to have.
Smoke makes things work. When the smoke gets out, it stops!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 12:40am 31 Aug 2017
Copy link to clipboard 
Print this post

I'm trying this a step at a time

I have 3 boxes drawn on the screen and I have the program set at the moment (in theory) to just print which box I touched

What is happening at the moment is the clock stops so I can see touch is working - but its when I touch anywhere on the screen and not just in the boxes and nothing is printed

[code] GUI DISPLAYBOX #25, 560 ,295,170,50,RGB(BLACK),RGB(RED) 'displaybox "Tomorrow"
GUI DISPLAYBOX #26, 560 ,355,170,50,RGB(BLACK),RGB(GREEN) 'displaybox "Day 2"
GUI DISPLAYBOX #27, 560 ,415,170,50,RGB(BLACK),RGB(BLUE) 'displaybox "Day 3"
ctrlval(25)="Tomorrow"
ctrlval(26)="Day 2"
ctrlval(27)="Day 3"

GUI INTERRUPT PenDown

'Main program

'end of main program


SUB PenDown

IF Touch(X)=560 AND Touch(X)<730 AND Touch(Y)=296 AND Touch(Y)<345 THEN 'If Touch pressed
PRINT "TOMORROW TOUCHED"
IF Touch(X)=560 AND Touch(X)<730 AND Touch(Y)=355 AND Touch(Y)<405 THEN 'If Touch pressed
PRINT "DAY 2 TOUCHED"
IF Touch(X)=560 AND Touch(X)<730 AND Touch(Y)=415 AND Touch(Y)<465 THEN 'If Touch pressed
PRINT "DAY 3 TOUCHED"
END IF

end sub[/code]Edited by lew247 2017-09-01
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 04:36am 31 Aug 2017
Copy link to clipboard 
Print this post

Displayboxes are just for on-screen information - they do not respond to touch.

So, your displayboxes tell the user some useful information of some sort, but you need to define some BUTTONS before any touch will result in any result.

Have a closer look at the GUI BUTTON command and syntax.

You should NOT try to detect a touch, on top of a DISPLAYBOX or any other GUI control.

Lets say you have your three displayboxes to tell the user things, but the buttons to touch should be defined separately - six controls in total. Three displayboxes, and three buttons.

I'm not saying you CAN'T detect touch on top of a displaybox as you are trying to do, but I don't think the MMBASIC GUI is designed to deal with that - others will know.
Smoke makes things work. When the smoke gets out, it stops!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 04:59am 31 Aug 2017
Copy link to clipboard 
Print this post

Could I use GUI SWITCH ?
If I'm reading the manual correctly I won't need the "GUI INTERRUPT PenDown"

If the switch is touched then the ctrlval for that switch would = 1

Could I do something like this in the main loop?


[code]

GUI SWITCH #25, 560 ,295,170,50,RGB(BLACK),RGB(RED) 'displaybox "Tomorrow"
GUI SWITCH #26, 560 ,355,170,50,RGB(BLACK),RGB(GREEN) 'displaybox "Day 2"
GUI SWITCH #27, 560 ,415,170,50,RGB(BLACK),RGB(BLUE) 'displaybox "DAY 3"
do
'main program
IF ctrlval(25)=1 THEN TOMORROW
IF ctrlval(26)=1 THEN DAY 2
IF ctrlval(27)=1 THEN DAY 3
ENDif
loop
end


**not sure if I need the ENDIF**

Would that make the program jump to those subroutines if the switch is touched?

Edit I'm getting no errors but the sub isn't working
Edited by lew247 2017-09-01
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 11:27am 31 Aug 2017
Copy link to clipboard 
Print this post

With three items to choose from, I would use radio buttons. That way only one can appear active at any time.
Replace the switches and use the same ctrval numbers as you used for the switches.
You still have to check to see which one was pressed, but it is easier and looks better with radio buttons.

Jim
VK7JH
MMedit   MMBasic Help
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 11:56am 31 Aug 2017
Copy link to clipboard 
Print this post

I get the feeling you are making this more complicated than it needs to be.

In the Pendown() procedure use Touch(REF) to see which GUI control was touched.




CONST GUI_TOMORROW = 25
CONST GUI_DAY2 = 26
CONST GUI_DAY3 = 27

GUI SWITCH GUI_TOMORROW,560,295,170,50,RGB(BLACK),RGB(RED)
GUI SWITCH GUI_DAY2,560,355,170,50,RGB(BLACK),RGB(GREEN)
GUI SWITCH GUI_DAY3,560,415,170,50,RGB(BLACK),RGB(BLUE)

Sub PenDown()

Select CASE Touch(REF)
CASE GUI_TOMORROW
TOMORROW
CASE GUI_DAY2
DAY2
CASE GUI_DAY3
DAY3
END SELECT

END SUB


Or use your If then statements instead of a CASE.

No you don't put an END IF with a one line IF THEN statement.

If you want to CALL TOMORROW, DAY2, DAY3 from your LOOP then set a FLAG in the PenDown ISR to tell you which control to service in the LOOP


DIM ThisControl as integer

Sub PenDown()

Select CASE Touch(REF)
CASE GUI_TOMORROW
ThisControl = 1
CASE GUI_DAY2
ThisControl = 2
CASE GUI_DAY3
ThisControl = 3
END SELECT

END SUB

DO
IF ThisControl = 1 then TOMORROW
IF ThisControl = 2 then DAY2
IF ThisControl = 3 then DAY3

ThisControl = 0

LOOP



You can also define a GUI Area under a Display BOX for Touch.

Mike.
Edited by KeepIS 2017-09-01
It's all too hard.
Mike.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 08:40pm 31 Aug 2017
Copy link to clipboard 
Print this post

This is so frustrating
no matter which way I try and do it touching the screen only stops the clock it does not do anything else
All I'm doing at the moment is printing "button # pressed"
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1401
Posted: 10:10pm 31 Aug 2017
Copy link to clipboard 
Print this post

Have you included the following at the start of the program. This will help with a lot of errors. Also make sure you don't have Local and global variables with the same name.

Option default none
Option explicit

Have you written a simple very short program that does nothing but respond correctly to a GUI screen touch in the way you expect?



It's all too hard.
Mike.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1676
Posted: 10:43pm 31 Aug 2017
Copy link to clipboard 
Print this post

Yes

[code]Option default none
Option explicit
CLS
GUI radio #25, "Tomorrow", 560 ,320,30,RGB(GREEN) 'displaybox "Tomorrow"
ctrlval(99)="Forecast"
Do
If ctrlval(25)=1 then test1
Loop

SUB test1
print "Tomorrow touched"
end sub

END[/code]

It shows the radio button and text on the screen but nothing happens when the button is touched

 
     Page 1 of 3    
Print this page
© JAQ Software 2024