Grogster
 Admin Group
 Joined: 31/12/2012 Location: New ZealandPosts: 9745 |
| Posted: 02:42am 07 Mar 2017 |
Copy link to clipboard |
 Print this post |
|
There is simply not enough nested depth within MMBASIC to do all I have to do inside the select case, so it won't work when you have about ten different GUI menus under each one of those GOTO's, as you would end up with about 50 or more deep nested loops - about the only way I could deal with it was with GOTO....
Here is the complete code for that section, and I am now getting results from all the labels that should not be executed unless the timer was greater then or equal to 20000
Yes, OPTION EXPLICIT used at the top of the code - has saved my bacon many times when I get variable names wrong etc.
[Quote=matherp]If not probably a typo somewhere e.g. the setting of SSDELAY which you don't show[/Quote] Yes I do. It is in the console output part of the image above "? ssdelay", which returns 20000.
'---------- 'MAIN LOOP: '---------- START: DO If DEBUG then PRINT "Main menu." 'Tempr START PSU_BAT 'Begin background process to read battery backup temperature 'Tempr START PSU_TEMP 'Begin background process to read PSU temperature 'Tempr START NSP_TEMP 'Begin background process to read system temperature CHECK_SETTINGS KEY=0:LCD_EXIT=0:LCD_OK=0:TEST_PASSWORD=0 'Clear flags BUILD_DATE DATE_REF=VAL(MID$(DATE$,1,2)) PAGE 1,6 'Main menu and buttons GUI INTERRUPT MENU 'This interrupt will be called when there is an LCD touch Timer=0 'Reset timer DO 'This loop detects any activity or other events while waiting for an LCD touch If Val(MID$(DATE$,1,2))>DATE_REF then goto START 'If new day, then update the clock If LOC(#2)<>0 then goto MSG_RXD 'Some kind of message was received. If PIN(PSU_MFD)=1 And MFDFLAG=0 Then Goto MAINSFAIL 'MCT6 opto pulls this line LOW if power is OK If PIN(PSU_MFD)=0 And MFDFLAG=1 Then Goto MAINSOK 'MCT6 opto says power is back now If Pin(NSP_FUSE)=0 then goto FUSEFAIL 'MCT6 opto pulls this line LOW if receiver fuse is OK If Pin(NSP_FAN_RPM)<25 then goto FANFAIL 'Count fansink RPM, and if too slow, inform users If TIMER>=SSDELAY then goto SCREENSAVER 'Call screensaver as nothing touched and no messages to process. LOOP until KEY<>0 Select Case KEY CASE 1 'DATABASE - Get password before access Goto GET_PASSWORD Case 2 Goto OTHER_OPTIONS Case 3 Goto MESSAGING End Select Loop
Print "Should never get here."
'-------------------- 'MAINS FAIL DETECTED: '-------------------- MAINSFAIL: MFDFLAG=1 Print "Should never get here.(MAINSFAIL)"
'----------------------- 'MAIN POWER OK DETECTED: '----------------------- MAINSOK: MFDFLAG=0 Print "Should never get here.(MAINSOK)"
'------------------------------ 'RECEIVER POWER FUSE HAS BLOWN: '------------------------------ FUSEFAIL: Print "Should never get here.(FUSEFAIL)"
'---------------------------------- 'SYSTEM FANSINK FAN RPM IS TOO LOW: '---------------------------------- FANFAIL: Print "Should never get here.(FANFAIL)"
'-------------------- 'DISPLAY SCREENSAVER: '-------------------- SCREENSAVER: Do If DEBUG Then Print "Screensaver called." CLS 'Clear screen. This also HIDES all GUI controls!!! For NBR=1 To 250 'Number of lines to draw before clearing the screen X1=Rnd*MM.HRES Y1=Rnd*MM.VRES X2=Rnd*MM.HRES Y2=Rnd*MM.VRES R=Cint(Rnd)*255 'Ensure 'r' is one or zero only G=Cint(Rnd)*255 'Ensure 'g' is one or zero only B=Cint(Rnd)*255 'Ensure 'b' is one or zero only Line X1,Y1,X2,Y2,1,RGB(R,G,B) 'Draw the line Line X1+1,Y1+1,X2+1,Y2+1,1,RGB(R,G,B) 'Draw the line Line X1+2,Y1+2,X2+2,Y2+2,1,RGB(R,G,B) 'Draw the line Line X1+3,Y1+3,X2+3,Y2+3,1,RGB(R,G,B) 'Draw the line Pause 100 'Delay between lines(increase to slow down) If Touch(DOWN) or LOC(#2)<>0 then 'If LCD touched or message received, stop screensaver CLS 'Clear screen. GUI SHOW ALL 'Re-enable all GUI elements GOTO START Endif Next LOOP

So what's odd about this one, is that the code should never get out of that first loop, but it is, and I don't see how.Edited by Grogster 2017-03-08 Smoke makes things work. When the smoke gets out, it stops! |
Grogster
 Admin Group
 Joined: 31/12/2012 Location: New ZealandPosts: 9745 |
| Posted: 03:12am 07 Mar 2017 |
Copy link to clipboard |
 Print this post |
|
I think I am on to something here as to what is causing it. Standby......
EDIT: Yep, I know what is causing it now.
Schoolboy mistake, really - should not write code at 2AM.
The routine that was tripping it up was actually MAINSFAIL. This is 100% correct too - the code looks at the opto-coupler, and as there is no connection to that just yet, the on-board 4k7 was pulling the pin high, the code sees that, and hops on over to MAINSFAIL.
.....and because I had not written those routines just yet, I just put in the labels to keep the interpreter happy, so it was jumping over each one('Nothing to see here! Move along!'), then it runs smack into the SCREENSAVER code, so executes it.
Bah!
Sleepy time now, will fix this up tomorrow.Edited by Grogster 2017-03-08 Smoke makes things work. When the smoke gets out, it stops! |
Grogster
 Admin Group
 Joined: 31/12/2012 Location: New ZealandPosts: 9745 |
| Posted: 02:09pm 07 Mar 2017 |
Copy link to clipboard |
 Print this post |
|
Good advise. I don't really like GOTO's - this has been talked about before, and I understand the reasons. But when you have a multi-page GUI program, if you try to put EVERYTHING inside one master loop, it would get VERY deep VERY quickly, and besides being hard to read with about 20 indents to the deeper loops, MMBASIC can't handle it. 
Having said that, yes, I agree - I will change all these loops so that they set flags and EXIT DO rather then GOTO from within the loop - much cleaner as you say.
Last night's problem also stemmed from the fact that I was trying to add three or four new test IF/THEN lines and routines to the main loop, and had not written them yet, so just put in the labels. As I say - probably not a good idea to try to write code at 2AM when you brain is half asleep...... Smoke makes things work. When the smoke gets out, it stops! |