Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:59 13 Nov 2025 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 : Port MM Code to MM+

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 04:23am 20 Apr 2020
Copy link to clipboard 
Print this post

Hi All,

Just began porting my Spa Controller code from a 28 Pin BackPack to an E100.

Step 1 was to comment out all the pin assignments to deal with later.
Step 2 was to comment out the subs that relate to sensor etc referenced above.

I just want to see the screen layout at this stage & work on getting that modified for the bigger screen.

My plan was to just get the E100 running & move to GUI controls later

Ran the modified code & it appeared to run ok, given the screen placement needs updating.

Touched the screen to bring up the menu to change variables, that worked fine.

It uses @Geoffg 's parking meter code to draw the keyboard & enter variables.
The keypad came up ok; scaled to the bigger screen & behaved as expected as I entered numbers.

But when I touch "Enter" to finish the entry it crashes out.
The error message is contradictory.
btn is a valid variable, VAR I assume so too & Val is valid as well.

[868] If btn = 16 And s <> "" Then VAR = Val(s)
Error: Unknown command


Not sure which way to look next.

This is my modified version of @Geoffg 's original code, which is fine on the 28 pin backpack.

Line 868 in my real code translates to line 69 below.

Thanks

Phil.

  Quote    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' the next two subroutines are responsible for drawing the keypad,
 ' animating the key presses and returning the entered value as a float.
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Get a number
 ' when the user touches ENT (enter) the value is saved into the variable var
 ' which is parsed as reference as the second argument
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GetFloat caption As String, var As Float
 
Const bw = MM.HRes\4, bh = MM.VRes\5
 
' these are the captions on each key
 Local String cap(15) = ("7","8","9","","4","5","6","","1","2","3","Can",".","0","Del","ENT")
 
Local Integer key, keydwn
 
Local Integer x, y, xt, yellowt, btn
 
Local String s
 
 
CLS 0
 
' draw the title
 Text 0, 8, caption + ": ", , 2, 1, RGB(yellow), 0
 
 
' draw the entire keypad (99 means draw them all)
 DrawKeypad 99
 
 
Do
   
If Touch(x) <> -1 And Not keydwn Then
     
' if the panel is touched
     keydwn = 1
     xt =
Touch(x)
     yellowt =
Touch(y)
     btn =
1
     
For y = bh To MM.VRes - bh Step bh
       
For x = 0 To MM.HRes - bw Step bw
         
If cap(btn-1) <> "" And xt > x And xt < x+bw And yellowt > y And yellowt < y+bh Then
           x =
1000 : y = 1000     ' exit both loops
         Else
           btn = btn +
1
         
EndIf
       
Next x
     
Next y
     
' continue looping if the touch was not on a key
     If btn > 16 Then Continue do
     
     
' special handling for the +, - and . keys
     If (btn = 4 Or btn = 8) And s <> "" Then Continue do
     
If btn = 13 And Instr(s, ".") > 0 Then Continue do
     
     
' draw the key as pressed
     DrawKeypad btn
     
     
' special processing for Can (cancel), Del and Ent (enter)
     If btn = 12 Or btn = 16 Then Continue do
     
If btn = 15 Then
       
If s <> "" Then s = Left$(s, Len(s) - 1)
     
Else
       s = s + cap(btn -
1)    ' add the key to our entered string
     EndIf
     
Text Len(caption + ": ") * 16, 8, s + " ", , 2, 1, RGB(yellow), 0
   
EndIf
   
   
' if a key is currently down check if it has been released
   If Touch(x) = -1 And keydwn Then
     
' yes, the key has been released
     ' draw the key as normal (ie, not pressed)
     keydwn = 0
     DrawKeypad -btn
     
' if ENT return the value
     If btn = 16 And s <> "" Then var = Val(s)
     
' if Can just return
     If btn = 12 Or btn = 16 Then Exit Sub
   
EndIf
 
Loop
End Sub
 
 
' this draws the keypad
 ' if the argument is 99 all keys will be drawn
 ' if it is negative the particular key will be drawn as normal
 ' if it is positive the key will be drawn as depressed
Sub DrawKeypad btndwn As Integer
 
Const bw = MM.HRes\4, bh = MM.VRes\5
 
Local String cap(15) = ("7","8","9","","4","5","6","","1","2","3","Can",".","0","Del","ENT")
 
Local Integer x, y, btn
 btn =
1
 
For y = bh To MM.VRes - bh Step bh
   
For x = 0 To MM.HRes - bw Step bw
     
If cap(btn - 1) <> "" Then
       
If btn = btndwn Then
         
' draw the key as touched (ie, reverse video)
         RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), RGB(cyan)
         
Text x + bw/2 + 4, y + bh/2 + 6, cap(btn - 1), CM, 2, 1, 0, RGB(cyan)
       
ElseIf -btn = btndwn Or btndwn = 99 Then
         
' draw the key as normal
         RBox x + 5, y + 5, bw - 5, bh - 5, , RGB(cyan), 0
         
Text x + bw/2, y + bh/2 + 2, cap(btn - 1), CM, 2, 1, RGB(cyan), 0
       
EndIf
     
EndIf
     btn = btn +
1
   
Next x
 
Next y
End Sub
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 04:41am 20 Apr 2020
Copy link to clipboard 
Print this post

Further more,

If I don't enter a value & just touch enter, it exits out as expected.
That would give the case where s="" so the If condition would be false.

And the code below would not be executed.

  Quote        If btn = 16 And s <> "" Then var = Val(s)


Edit,

I should have said in the first post that when I touch a value to bring up the keypad to enter a number it works fine.

But then that line errors on touching the Enter on the keypad display.
Entering numbers of cancelling works perfectly.
Edited 2020-04-20 14:45 by Phil23
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 04:54am 20 Apr 2020
Copy link to clipboard 
Print this post

The only other thing that comes to mind is that maybe the firmware on the E100 (5.0501) is considering that line of code as illegal usage of the VAR Save/Restore/Clear command, where as the MMII firmware on the existing controller (5.02) is happy with VAR being a variable name.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 09:48am 20 Apr 2020
Copy link to clipboard 
Print this post

Issue solved.

Turned to be related to the above post.
Either the MM2 firmware or the older revision seems to be forgiving or the variable name VAR, where as 5.05 Plus firmware is not.

Interesting that the VAR command has been around forever, yet there are obviously firmware versions where that reserved word can be used as a variable name.

Both

  Quote  Sub GetFloat caption As String, VAR As Float
 
Const bw = MM.HRes\4, bh = MM.VRes\5


And are both executed as valid on the MM+

  Quote  Sub GetFloat caption As String, Fred As Float
 
Const bw = MM.HRes\4, bh = MM.VRes\5


yet it is only the line

  Quote        If btn = 16 And s <> "" Then VAR = Val(s)
     
' if Can just return


that triggered an error.

Cheers

Phil
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 11:27pm 20 Apr 2020
Copy link to clipboard 
Print this post

  Phil23 said  Interesting that the VAR command has been around forever, yet there are obviously firmware versions where that reserved word can be used as a variable name.


I think it was WhiteWizzard who had an issue with some Silicon Chip software that used SUB as a variable name which caused an error with a later version of MMBasic.

Using a keyword as a variable name is a no no.

Bill
Keep safe. Live long and prosper.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025