Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:15 30 Apr 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 : Code is erasing array....

     Page 1 of 2    
Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 08:37pm 05 Jan 2016
Copy link to clipboard 
Print this post

Hi folks.

EDIT: MM+ Explore64 Beta 37, 7" 1963 LCD with touch.

I need some help from the members, to work out why the hell DOW$ is being totally cleared by this code:


Option Explicit
'Option Autorun On
'Option LCDPANEL SSD1963_7,L
'Option TOUCH 22,21,45
'Option SDCARD 12,14,18
BackLight 50

'=========================
'DECLARE SYSTEM VARIABLES:
'=========================

Dim As INTEGER A,B,G,M,R,X,Y,Y1,M1,D1
Dim As INTEGER Year,Month,Day

Dim MTH$(12) LENGTH 3
MTH$(1)="JAN":MTH$(2)="FEB":MTH$(3)="MAR":MTH$(4)="APR":MTH$(5)="MAY"
MTH$(6)="JUN":MTH$(7)="JUL":MTH$(8)="AUG":MTH$(9)="SEP":MTH$(10)="OCT"
MTH$(11)="NOV":MTH$(12)="DEC"
Dim DOW$(6) LENGTH 9
DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)="Wednesday"
DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday"
DIM SW%(31)=(8,9,10,12,13,14,14,15,15,15,14,14,13,12,10,9,7,6,5,4,2,1,1,0,0,0,1,1,2,3,5,6)

'=================
'CONFIGURE SYSTEM:
'=================

SetPin 8,INTL,FUSE 'Fuse failure interrupt
'SetPin 30,INTH,MAINS 'Mains power failure interrupt
SetPin 33,INTL,RST 'Soft reset interrupt

SetPin 54,DIN 'Keyswitch admin
SetPin 55,DIN 'Keyswitch start network

SetTick 250,DAT,1


'============
'MAIN SCREEN:
'============

START:
CLS
MenuBox (0,0,255)
Font 4
Text 100,25,"M A I N M E N U :",L,7,2,RGB(green)
Line 100,60,700,60,3,RGB(green)
Text 50,100,"Please touch one of the following buttons",,4,1,RGB(white)
Text 80,125,"to access the main system components:",,4,1,RGB(white)
GUI button #1,"DATABASE",50,200,200,100,RGB(red),RGB(gray)
GUI button #2,"OPTIONS",300,200,200,100,RGB(red),RGB(gray)
GUI button #3,"MESSAGING",550,200,200,100,RGB(red),RGB(gray)


Do
If CtrlVal(#1)=1 Then 'DATABASE button press
CLS
GUI delete all
Text 65,50,"DATABASE MENU:",,7,3,RGB(red),RGB(white)
Text 100,175,"Access to the database is restricted.",,4,1,RGB(yellow)
Text 85,250,"Please insert key and turn one position",,4,1,RGB(cyan)
Text 85,275,"to the right, or touch CANCEL button...",,4,1,RGB(cyan)
Font 4,2
GUI button #1,"CANCEL",275,375,250,75,RGB(blue),RGB(gray)
Timer=0
Do
If Pin(54)=0 Then GoTo DATABASE
Loop Until CtrlVal(#1)=1 Or Timer>20000
GUI delete all
GoTo START
End
EndIf
If CtrlVal(#2)=1 Then
CLS
GUI delete all
Text 100,250,"Options button pressed."
Pause 2500
GoTo START
EndIf
If CtrlVal(#3)=1 Then
CLS
GUI delete all
Text 100,250,"Messaging button pressed."
Pause 2500
GoTo START
EndIf
Loop

FUSE:


MAINS:


RST:


DATABASE:


End

'======================
'TICK TIMER INTERRUPTS:
'======================

DAT:
Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2))
Text 25,450,DOW$(DayOfWeek(Year,Month,Day)) + " " + Date$
Text 650,450,Time$
IReturn


'====================
'GENERAL SUBROUTINES:
'====================

'-------------------------------------------------
Sub MenuBox (R,G,B)
For X=1 To 3
RBox x,x,MM.HRes-x*2,MM.VRes-x*2,20,RGB(R,G,B)
Next
End Sub
'-------------------------------------------------


'==================
'GENERAL FUNCTIONS:
'==================

'-------------------------------------------------
Function DayOfWeek(Y1,M1,D1)
A=Int((14-M1)/12)
M=M1+12*A-2
Y=Y1-A
DayOfWeek=(D1+Y+Int(Y/4)-Int(Y/100)+Int(Y/400)+Int(31*M/12)) Mod 7
End Function


When run, the display shows the day of the week in the bottom-left of the LCD, and when you initially run this code, it work, but as soon as you touch the DATABASE button, DOW$ is erased - ALL elements of the string are now "".

It does not happen if you touch the OPTIONS or MESSAGING buttons, so therefore, seems to be something in the DATABASE routine, but I cannot see anything in there that would be wiping out DOW$.....

Can anyone show me the error of my ways?

ANOTHER EDIT: I have DELETED the library, and now the Cfunctions are in the main code, but I have not copied them to this thread. Full power-off reset followed clearing out the library and main code, before replacing power and loading the new code into main program memory. The point being, that with no library now, that can't be the source of some odd bug.Edited by Grogster 2016-01-07
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 10:42pm 05 Jan 2016
Copy link to clipboard 
Print this post

UPDATE:

Here is an image I get on the terminal, which shows the results of DOW$ after two run cycles.

The extra testing code is:


test:
For X=0 To 6
Print DOW$(X)
Next
End


...and the results are:





First time 'test' is run, I have stopped the code before pressing any GUI button.
Second time 'test is run, I have pressed the DATABASE button.

Note that DOW$(0) now seems to contain text from GUI button #2......
(that being OPTIONS without the O at the start)
Smoke makes things work. When the smoke gets out, it stops!
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3659
Posted: 11:46pm 05 Jan 2016
Copy link to clipboard 
Print this post

Looks like GUI is corrupting memory.

John
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 203
Posted: 12:54am 06 Jan 2016
Copy link to clipboard 
Print this post

Either:
'OPTION BASE 1' to index your arrays starting at 1
instead of default 0 which makes MTH$ ok & change
DOW$ index 1 to 7 to reflect this also.
OR
Change MTH$ index from 0 to 11
Try this
rgds
led

Edit:
Noticed the two different methods of array indexing used
Edited by led-bloon 2016-01-07
Miss you George
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 02:18am 06 Jan 2016
Copy link to clipboard 
Print this post

I have had a play with this but not quite got to the bottom, but I think its around redefining/deleting the GUI whilst actually still processing the control.
The Do loop that checks Ctrlval(#1) ie.

Do
If CtrlVal(#1)=1 Then 'DATABASE button press
CLS
GUI delete all



will find the value =1, but the actual control is in the down position. It still needs to do its UP thing, but GUI DELETE ALL happens so its lost.

You may need to make it interrupt driven with
GUI INTERRUPT TouchDown,TouchUp

and do stuff in the TouchDown and TouchUp subroutines, being mindful not to destroy controls within the touchdown routine.
I think the DOW$ is just a symptom of the above.

Regards
Gerry
Latest F4 Latest H7
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:30am 06 Jan 2016
Copy link to clipboard 
Print this post

I've just tried to define two strings - T1$ and T2$ so I can use these in the GUI caption command, and am having EXACTLY the same issue, in that T1$ and T2$ are blank when you try to call them, so this is a totally different routine to what you mention disco4now, but they could still be related in some weird way.

The code I am trying to use in another screen is:


DateAndTime:
CLS
GUI delete all
Font 7,3
GUI caption #10,"DATE & TIME:",100,25,,RGB(yellow)
'Line 100,75,650,75,3,RGB(yellow)
Font 4,1
T1$="Touch numberboxes to enter data, and then"
T2$="touch the OK button or the << button to exit."
GUI caption #11,T1$,50,100,,RGB(green)
GUI caption #12,T2$,50,125,,RGB(green)
'Text 50,100,"Touch numberboxes to enter data, and then",,4,1,RGB(green)
'Text 50,125,"touch the OK button or << button to exit.",,4,1,RGB(green)


As soon as you try to draw the caption, T1$ and T2$ are blank with a length of zero, despite just being defined. If I put an END command between the T1$= and T2$= lines and the GUI caption commands, then ask the console to print them, they print.

Caption #10 works fine, as I am defing the text as part of the command itself, but captions #11 and #12 make the line too long for the editor, so I put them in strings first.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:42am 06 Jan 2016
Copy link to clipboard 
Print this post

UPDATE:

Yep, something very odd going on here.

New quick test code:


Font 4,1
T1$="Touch numberboxes to enter data, and then"
T2$="touch the OK button or the << button to exit."
Print T1$,Len(T1$):Print T2$,Len(T2$)
GUI caption #11,T1$,50,100,,RGB(green)
GUI caption #12,T2$,50,125,,RGB(green)
Print T1$,Len(T1$):Print T2$,Len(T2$)


Result on the terminal:





I'll wait and see what Geoff says about all this before I get too carried away posting any more stuff about this.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:01am 06 Jan 2016
Copy link to clipboard 
Print this post

It looks like you have got a great demo of the issue. I will run it up on my MM+ test rig in the morning and report back.
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 04:57pm 06 Jan 2016
Copy link to clipboard 
Print this post

UPDATE:

The caption issue WORKS the first time through the code(as does the DOW$ issue), when you first power-up the MM+. Any subsequent attempts to run the code generate the problem.

So, physically remove power, run the code and it should work on the first run.
Re-run the code without cycling power, and the code will show the problem.

I just discovered that when I fired up the unit again today for more tinkering.

EDIT: This is with respect to the caption code above, not the original DOW$ issue, although that still remains an issue.Edited by Grogster 2016-01-08
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 11:45pm 06 Jan 2016
Copy link to clipboard 
Print this post

This is very frustrating Grogs, your code works perfectly for me. Something very strange is going on here.

I am using a close to finished version of V5.1 for the MX470. Give me a day or two so that I can clean it up for testing and I will send you a copy.

I know that this sounds suspiciously like the answer I gave to drkl for his problem. I don't believe in coincidences like this, it is a worry.

Geoff
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 12:10am 07 Jan 2016
Copy link to clipboard 
Print this post

I am currently on 4.7 beta 37, which I think is the most recent public beta, yes?
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 12:55am 07 Jan 2016
Copy link to clipboard 
Print this post

Yes it is, but wait for a few days and I will send you a near final version.
Geoff Graham - http://geoffg.net
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 01:29am 07 Jan 2016
Copy link to clipboard 
Print this post

Grogs/Geoff,

I only have the SSD1289 320*240 screen so have adjusted the positions a bit. I converted to interrupt driven but could still see your issue of the DOW$() array being corrupted.
I have managed to make it work now. I think the issue happens after
GUI DELETE ALL is used, especially a second time or if there are no controls.

I had to use GUI DELETE 1,2,3 etc and keep track of what controls where there, but when I don't use GUI DELETE ALL it seems to behave.


Hope this is of some help.
Regards
Gerry


sub mm.startup
LOCAL CFuncAddr%
CFuncAddr%=PEEK(CFUNADDR SSD1289_plus64)
SSD1289_plus64(CFuncAddr%, 1) 'Address of the CFunction, orientation
end sub



'=========================
'DECLARE SYSTEM VARIABLES:
'=========================

Dim As INTEGER A,B,G,M,R,X,Y,Y1,M1,D1
Dim As INTEGER Year,Month,Day

Dim MTH$(13) LENGTH 3
MTH$(1)="JAN":MTH$(2)="FEB":MTH$(3)="MAR":MTH$(4)="APR":MTH$(5)="MAY"
MTH$(6)="JUN":MTH$(7)="JUL":MTH$(8)="AUG":MTH$(9)="SEP":MTH$(10)="OCT"
MTH$(11)="NOV":MTH$(12)="DEC"
'Dim DOW$(6) LENGTH 9
DIM DOW$(6)
DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)="Wednesday"
DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday"
DIM SW%(31)=(8,9,10,12,13,14,14,15,15,15,14,14,13,12,10,9,7,6,5,4,2,1,1,0,0,0,1,1,2,3,5,6)
DIM AS INTEGER SelectedMenu
'=================
'CONFIGURE SYSTEM:
'=================

SetPin 8,INTL,FUSE 'Fuse failure interrupt
'SetPin 30,INTH,MAINS 'Mains power failure interrupt
SetPin 33,INTL,RST 'Soft reset interrupt

SetPin 54,DIN 'Keyswitch admin
SetPin 55,DIN 'Keyswitch start network

SetTick 250,DAT,1


'============
'MAIN SCREEN:
'============

START:
CLS
GUI delete all
MenuBox (0,0,255)
Font 1,1
SelectedMenu=0
SETTICK 200,ActionMenu,4


do

LOOP
SUB ActionMenu
SETTICK 0,,4
GUI INTERRUPT 0
Select Case SelectedMenu
Case 0
CLS

' GUI delete all

Text 25,5,"M A I N M E N U :",L,4,1,RGB(green)
Line 25,30,300,25,3,RGB(green)
Text 10,50,"Please touch one of the following buttons",,1,1,RGB(white)
Text 10,75,"to access the main system components:",,1,1,RGB(white)
GUI button #1,"DATABASE",10,100,80,50,RGB(red),RGB(gray)
GUI button #2,"OPTIONS",100,100,80,50,RGB(red),RGB(gray)
GUI button #3,"MESSAGING",190,100,80,50,RGB(red),RGB(gray)
GUI INTERRUPT TouchDown,TouchUp
Case 1

CLS
GUI delete 1,2,3
Text 65,50,"DATABASE MENU:",,4,1,RGB(red),RGB(white)
Text 10,100,"Access to the database is restricted.",,1,1,RGB(yellow)
Text 10,150,"Please insert key and turn one position",,1,1,RGB(cyan)
Text 10,200,"to the right, or touch CANCEL button...",,1,1,RGB(cyan)

GUI button #1,"CANCEL",25,180,40,50,RGB(blue),RGB(gray)
Timer=0
Do
If Pin(54)=0 Then GoTo DATABASE
Loop Until CtrlVal(#1)=1 Or Timer>20000
pause 2500
gui delete 1
SelectedMenu=0
SETTICK 200,ActionMenu,4
CASE 2
CLS
GUI delete 1,2,3
Text 10,200,"Options button pressed."
Pause 2500
SelectedMenu=0
SETTICK 200,ActionMenu,4
CASE 3
CLS
GUI delete 1,2,3
Text 100,200,"Messaging button pressed."
Pause 2500
SelectedMenu=0
SETTICK 200,ActionMenu,4

Case Else

END SELECT
End SUB


SUB TouchUp


End Sub

SUB TouchDown
SELECT CASE Touch(REF)
CASE 1 'DATABASE button press
SelectedMenu=1
SETTICK 200,ActionMenu,4
CASE 2
SelectedMenu=2
SETTICK 200,ActionMenu,4
'GoTo START

CASE 3
SelectedMenu=3
SETTICK 200,ActionMenu,4
'GoTo START
CASE ELSE
? "not one of them"

END SELECT
end sub

FUSE:


MAINS:


RST:


DATABASE:
test

End

'======================
'TICK TIMER INTERRUPTS:
'======================

DAT:
Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2))
'Text 10,220,DOW$(DayOfWeek(Year,Month,Day)) + " " + Date$
Text 10,220,DOW$(6) + " " + Date$
Text 240,220,Time$
IReturn


'====================
'GENERAL SUBROUTINES:
'====================

'-------------------------------------------------
Sub MenuBox (R%,G%,B%)
For X=1 To 3
RBox x,x,MM.HRes-x*2,MM.VRes-x*2,20,RGB(R%,G%,B%)
Next
End Sub
'-------------------------------------------------
sub test
For X=0 To 6
Print DOW$(X)
Next
end sub

'==================
'GENERAL FUNCTIONS:
'==================

'-------------------------------------------------
Function DayOfWeek(Y1,M1,D1)
A=Int((14-M1)/12)
M=M1+12*A-2
Y=Y1-A
DayOfWeek=(D1+Y+Int(Y/4)-Int(Y/100)+Int(Y/400)+Int(31*M/12)) Mod 7
End Function




Latest F4 Latest H7
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:33am 07 Jan 2016
Copy link to clipboard 
Print this post

Hi Gerry.

Thanks for your time tinkering. I would have thought that you could just delete all the GUI controls each time you draw a new screen.

However, your example gives me something to play with, so I will load an try out your code tomorrow.

Where are you setting GUI INTERRUPT? I note you are clearing it at the start of ActionMenu, but I don't see where you are setting that interrupt?

I'll wait for Geoff to release 5.1 in the next few days before I get too carried away with workarounds, but it is nice to know there is a way that you have found.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 02:39am 07 Jan 2016
Copy link to clipboard 
Print this post

UPDATE

I have found an even faster way around this issue, thanks to disco4now giving me an idea.

The problem seems to be related to the LENGTH option on the DIM command.

If I replace:


Dim MTH$(12) LENGTH 3
Dim DOW$(6) LENGTH 9


...with:


Dim MTH$(12)
Dim DOW$(6)


Then EVERYTHING works just fine - day references, captions - all that was not working before.

I think we may have stumbled on the cause - the LENGTH spec?

Output from terminal with many cycles through the code:





...everything perfect.
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 06:40pm 07 Jan 2016
Copy link to clipboard 
Print this post

UPDATE

We're still getting corruption within arrays:





Note that DOW$ elements 5 and 6 are now more then 100 bytes long, when they should only be single words...





For the above image, I copied the rogue element into another string first during playing at the cosole.

I will wait and see what happens when v5 comes out soon.

EDIT: ...and yet more corruption...



Edited by Grogster 2016-01-09
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 10:53pm 07 Jan 2016
Copy link to clipboard 
Print this post

Here is more of this error, this time when I tried to use spinbox values to set the internal RTC:


'------------------
'SET DATE AND TIME:
'------------------
DateAndTime:
CLS
GUI delete all
Font 7,3
Text 100,25,"DATE & TIME:",,7,3,RGB(yellow)
Line 100,75,675,75,3,RGB(yellow)
Font 4,1
T1$="Touch numberbox arrows to change data, and"
T2$="then touch OK or the EXIT button to exit."
Text 60,100,T1$,,4,1,RGB(white)
Text 70,125,T2$,,4,1,RGB(white)
Font 7,2
Text 20,175," DAY:",,7,2,RGB(cyan)
GUI spinbox #1,200,170,200,50,RGB(green),RGB(black),,1,31
Text 20,250,"MONTH:",,7,2,RGB(cyan)
GUI spinbox #2,200,245,200,50,RGB(green),RGB(black),,1,12
Text 20,325," YEAR:",,7,2,RGB(cyan)
GUI spinbox #3,200,320,200,50,RGB(green),RGB(black),,2010,2050
Text 425,175,"HOUR:",,7,2,RGB(cyan)
GUI spinbox #4,575,170,200,50,RGB(green),RGB(black),,0,24
Text 425,250,"MINS:",,7,2,RGB(cyan)
GUI spinbox #5,575,245,200,50,RGB(green),RGB(black),,1,60
Text 425,325,"SECS:",,7,2,RGB(cyan)
GUI spinbox #6,575,320,200,50,RGB(green),RGB(black),,1,60
GUI button #7,"EXIT",75,400,200,50,RGB(blue),RGB(gray)
GUI button #8,"OK",525,400,200,50,RGB(red),RGB(gray)
Do
If CtrlVal(#7)=1 Then GoTo START
If CtrlVal(#8)=1 Then Exit Do
Loop
T1$=Str$(CtrlVal(1))+"-"+Str$(CtrlVal(2))+"-"+Str$(CtrlVal(3))
T2$=Str$(CtrlVal(4))+":"+Str$(CtrlVal(5))+":"+Str$(CtrlVal(6))
'Date$=T1$ 'GUI corruption issues
'Time$=T2$
'GoTo START

End


If I try to run this the string generated for T1$ is corrupted.

It is NOT corrupted, if I manually issue the exact same code at the command prompt.




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

Guru

Joined: 18/12/2014
Location: Australia
Posts: 844
Posted: 03:44pm 08 Jan 2016
Copy link to clipboard 
Print this post

Grogs/Geoff,

I think the GUI DELETE ALL is the root cause of all Grog's corruption issues.
The code below seems to behave if I keep an array of the active controls and use
SUB GUIDeleteAll in lieu of GUI DELETE ALL.
Each time you set a GUI control, then set the corresponding array variable.e.g
GUI button #1,"CANCEL",25,180,80,50,RGB(blue),RGB(gray):IsGUIUsed(1)=1

Regards
Gerry




'Option Explicit
'Option Autorun On
'Option LCDPANEL SSD1963_7,L
'Option TOUCH 22,21,45
'Option SDCARD 12,14,18
'BackLight 50

dim as integer i
DIM IsGUIUsed(51)
for i=1 to 50
IsGUIUsed(51)=0
next i

SUB GUIDeleteAll
IF IsGUIUsed(1)=1 THEN GUI DELETE 1:IsGUIUsed(1)=0
IF IsGUIUsed(2)=1 THEN GUI DELETE 2:IsGUIUsed(2)=0
IF IsGUIUsed(3)=1 THEN GUI DELETE 3:IsGUIUsed(3)=0
IF IsGUIUsed(4)=1 THEN GUI DELETE 4:IsGUIUsed(4)=0
IF IsGUIUsed(5)=1 THEN GUI DELETE 5:IsGUIUsed(5)=0
IF IsGUIUsed(6)=1 THEN GUI DELETE 6:IsGUIUsed(6)=0
IF IsGUIUsed(7)=1 THEN GUI DELETE 7:IsGUIUsed(7)=0
IF IsGUIUsed(8)=1 THEN GUI DELETE 8:IsGUIUsed(8)=0
IF IsGUIUsed(9)=1 THEN GUI DELETE 9:IsGUIUsed(9)=0
end sub
'=========================
'DECLARE SYSTEM VARIABLES:
'=========================

Dim As INTEGER A,B,G,M,R,X,Y,Y1,M1,D1
Dim As INTEGER Year,Month,Day

Dim MTH$(13) LENGTH 3
MTH$(1)="JAN":MTH$(2)="FEB":MTH$(3)="MAR":MTH$(4)="APR":MTH$(5)="MAY"
MTH$(6)="JUN":MTH$(7)="JUL":MTH$(8)="AUG":MTH$(9)="SEP":MTH$(10)="OCT"
MTH$(11)="NOV":MTH$(12)="DEC"
Dim DOW$(6) LENGTH 9
DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)="Wednesday"
DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday"
DIM SW%(31)=(8,9,10,12,13,14,14,15,15,15,14,14,13,12,10,9,7,6,5,4,2,1,1,0,0,0,1,1,2,3,5,6)

'=================
'CONFIGURE SYSTEM:
'=================

SetPin 8,INTL,FUSE 'Fuse failure interrupt
'SetPin 30,INTH,MAINS 'Mains power failure interrupt
SetPin 33,INTL,RST 'Soft reset interrupt

SetPin 54,DIN 'Keyswitch admin
SetPin 55,DIN 'Keyswitch start network

SetTick 250,DAT,1


'============
'MAIN SCREEN:
'============

START:
CLS
MenuBox (0,0,255)
Font 1


'GUI delete all
GUIDeleteAll
Text 25,5,"M A I N M E N U :",L,4,1,RGB(green)
Line 25,30,300,25,3,RGB(green)
Text 10,50,"Please touch one of the following buttons",,1,1,RGB(white)
Text 10,75,"to access the main system components:",,1,1,RGB(white)
GUI button #1,"DATABASE",10,100,80,50,RGB(red),RGB(gray):IsGUIUsed(1)=1
GUI button #2,"OPTIONS",100,100,80,50,RGB(red),RGB(gray):IsGUIUsed(2)=1
GUI button #3,"MESSAGING",190,100,80,50,RGB(red),RGB(gray):IsGUIUsed(3)=1


Do
If CtrlVal(#1)=1 Then 'DATABASE button press
CLS
'GUI delete all
GUIDeleteAll
Text 25,5,"DATABASE MENU:",,4,1,RGB(red),RGB(white)
Text 10,50,"Access to the database is restricted.",,1,1,RGB(yellow)
Text 10,75,"Please insert key and turn one position",,1,1,RGB(cyan)
Text 10,100,"to the right, or touch CANCEL button...",,1,1,RGB(cyan)
GUI button #1,"CANCEL",25,180,80,50,RGB(blue),RGB(gray):IsGUIUsed(1)=1
Timer=0
Do
If Pin(54)=0 Then GoTo DATABASE
Loop Until CtrlVal(#1)=1 Or Timer>20000
'GUI delete all
GUIDeleteAll
GoTo START
End
EndIf
If CtrlVal(#2)=1 Then
CLS
'GUI delete all
GUIDeleteAll
Text 100,200,"Options button pressed."
'Pause 2500
GoTo Dateandtime
EndIf
If CtrlVal(#3)=1 Then
CLS
'GUI delete all
GUIDeleteAll
Text 100,200,"Messaging button pressed."
Pause 2500
GoTo START
EndIf
Loop

FUSE:


MAINS:


RST:


DATABASE:


End

'======================
'TICK TIMER INTERRUPTS:
'======================
DAT:
Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2))
'x%=DayOfWeek(Year,Month,Day)
Text 10,220,DOW$(DayOfWeek(Year,Month,Day)) + " " + Date$
'Text 10,220,DOW$(x%) + " " + Date$
Text 240,220,Time$
IReturn


'====================
'GENERAL SUBROUTINES:
'====================

'-------------------------------------------------
Sub MenuBox (R,G,B)
For X=1 To 3
RBox x,x,MM.HRes-x*2,MM.VRes-x*2,20,RGB(R,G,B)
Next
End Sub
'-------------------------------------------------


'==================
'GENERAL FUNCTIONS:
'==================

'-------------------------------------------------
Function DayOfWeek(Y1,M1,D1)
A=Int((14-M1)/12)
M=M1+12*A-2
Y=Y1-A
DayOfWeek=(D1+Y+Int(Y/4)-Int(Y/100)+Int(Y/400)+Int(31*M/12)) Mod 7
End Function
'------------------
'SET DATE AND TIME:
'------------------






DateAndTime:
CLS
'GUI delete all
GuiDeleteAll
Font 1,1
Text 1,1,"DATE & TIME:",,1,1,RGB(yellow)
'Line 100,75,675,75,3,RGB(yellow)
Font 1,1
T1$="Touch numberbox arrows to change data, and"
T2$="then touch OK or the EXIT button to exit."
Text 10,11,T1$,,1,1,RGB(white)
Text 10,21,T2$,,1,1,RGB(white)
Font 1,1
Text 1,40," DAY:",,1,1,RGB(cyan)
GUI spinbox #1,50,40,80,30,RGB(green),RGB(black),,1,31:IsGUIUsed(1)=1
Text 1,100,"MONTH:",,1,1,RGB(cyan)
GUI spinbox #2,50,100,80,30,RGB(green),RGB(black),,1,12:IsGUIUsed(2)=1
Text 1,160," YEAR:",,1,1,RGB(cyan)
GUI spinbox #3,50,160,80,30,RGB(green),RGB(black),,2010,2050:IsGUIUsed(3)=1
Text 175,40,"HOUR:",,1,1,RGB(cyan)
GUI spinbox #4,175,40,80,30,RGB(green),RGB(black),,0,24:IsGUIUsed(4)=1
Text 175,100,"MINS:",,1,1,RGB(cyan)
GUI spinbox #5,175,100,80,30,RGB(green),RGB(black),,1,60:IsGUIUsed(5)=1
Text 175,160,"SECS:",,1,1,RGB(cyan)
GUI spinbox #6,175,160,80,30,RGB(green),RGB(black),,1,60:IsGUIUsed(6)=1
GUI button #7,"EXIT",15,190,80,30,RGB(blue),RGB(gray):IsGUIUsed(7)=1
GUI button #8,"OK",140,190,80,30,RGB(red),RGB(gray):IsGUIUsed(8)=1
Do
If CtrlVal(#7)=1 Then GoTo START
If CtrlVal(#8)=1 Then Exit Do
Loop
T1$=Str$(CtrlVal(1))+"-"+Str$(CtrlVal(2))+"-"+Str$(CtrlVal(3))
T2$=Str$(CtrlVal(4))+":"+Str$(CtrlVal(5))+":"+Str$(CtrlVal(6))
? T1$
? T2$
'Date$=T1$ 'GUI corruption issues
'Time$=T2$
GoTo START
END
Edited by disco4now 2016-01-10
Latest F4 Latest H7
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9063
Posted: 07:57pm 08 Jan 2016
Copy link to clipboard 
Print this post

Thanks for all the extra work disco4now - I appreciate your efforts to help.

I will wait just a tad longer for Geoff to release version 5 of MMBASIC, and if the problem still persists, I will use your fix as posted above. Using a sub to keep track of the controls seems like quite a nice way to get around the issue.
Smoke makes things work. When the smoke gets out, it stops!
 
frwainscott
Newbie

Joined: 04/01/2016
Location: United States
Posts: 3
Posted: 06:57pm 09 Jan 2016
Copy link to clipboard 
Print this post

I may be wrong but i dont see a reset for day of week. first run through everything is ok,second run you are going beyond parameters for day and confusing the cpu. Again,I could be wrong,wouldnt be the first time. :)
 
     Page 1 of 2    
Print this page
© JAQ Software 2024