Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:40 17 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 : NumberBox MMBasic 5.04.05

     Page 1 of 2    
Author Message
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 12:10am 14 Aug 2017
Copy link to clipboard 
Print this post

Question:

SUB MM.KEYPRESS KREF AS INTEGER, CAPVal$ AS STRING

IF CAPVal$ = "Ent" THEN

IF VAL(CtrlVal(SampleTime)) <> 0 then

LogPeriod = VAL(CtrlVal(SampleTime))

ELSE

CtrlVal(SampleTime) = str$(LogPeriod)

"All happy and control updated" <--------------------

CtrlVal(SampleTime) = LogPeriod

"ERROR: Expecting a string" <---------------------

ENDIF
ENDIF
END SUB



SUB SETUP()

CtrlVal(SampleTime) = STR$(LogPeriod)

"ERROR: Expecting a number" <------------------

CtrlVal(SampleTime) = LogPeriod

"All happy and control updated" <-----------------

END SUB

Why does the same control want a number in one instance and a string in the other?

Mike.Edited by KeepIS 2017-08-15
It's all too hard.
Mike.
 
flip
Senior Member

Joined: 18/07/2016
Location: Australia
Posts: 114
Posted: 01:57am 14 Aug 2017
Copy link to clipboard 
Print this post

Hi Mike,
CtrlVal function/statement can return/set string or number...so can you check whether your SampleTime variable has a different value in the two bits of code
OR if you're sure the value in SampleTime variable is NOT being altered in your code (i.e. is a constant),
check whether you're creating a different type of control (one that is a text-based control rather than numeric or vice-versa) using the SAME control number

EDIT or could it be the value entered (if NOT convertible to a valid number) is returned as a String?

OR it needs to handle setting with exponential format (which may be a string...like 1E23 for example)
Manual MM+ 5.4 page 30 shows NUMBERBOX takes text
  Quote  Similar to the Text Box, the value of the control can set to a literal string with two leading hash characters (eg, "##Hint") and in that case the string (without the leading two characters) will be displayed in the box with reduced brightness

Haven't got one handy to test at the moment I will experiment too.. but I hope above quote will give you a clue...
Regards,
PhilEdited by flip 2017-08-15
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 11:49am 14 Aug 2017
Copy link to clipboard 
Print this post

Hi flip, thanks for replying,

I always have:

Option default none
Option explicit

The Numberbox is a GUI control in MMbasic Plus language.

DIM INTEGER LogPeriod

CONST SampleTime = 33 ' GUI reference

I can set: LogPeriod = 10, this makes sure the number is valid and it is anyway as I placed a Debug print LogPeriod to check for that.

GUI NUMBERBOX SampleTime, MM.HRes/40, MM.VRes/30, MM.HRes/5, M.VRes/4, RGB(WHITE), RGB(BLUE)

In both cases the Value is SET correctly. String or Numeric.

SUB MM.KEYPRESS is defined in MMBasic+ and is Procedure called to interact with any Numberbox control.

It appears to me that the behaviour changes between the GUI control when it is accessed in the service procedure and when it accessed outside of that procedure?

Mike.




Edited by KeepIS 2017-08-15
It's all too hard.
Mike.
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 01:07pm 14 Aug 2017
Copy link to clipboard 
Print this post

On the subject of the NUMBERBOX.

--------------------
CONST RXLED = 28

GUI SETUP 1
GUI LED RXLED,"", MM.VRes / 16, MM.VRes / 1.33, MM.VRes / 28, RGB(GREEN)

PAGE 1
-------------------

If you have, for example, a GUI LED, and instead of just setting it on or off as in:

---------------------
CtrlVal(RXLED) = 1
CtrlVal(RXLED) = 0
---------------------

You decide to read the state of the GUI LED and only turn it OFF if it's actually ON, this stop flickering of the GUI LED that is being reset in the program main loop, Serial input and LED = ON are being handled in an ISR:

NOTE: Not shown is the code for an incremental counter to only reset the LED every X ms

------------------
DO

IF GotData = TRUE then ProcessData()

IF CtrlVal(RXLED) = 1 then CtrlVal(RXLED) = 0

LOOP
---------------------

Now IF you use a NUMBEBOX GUI and the associated GUI KEYPAD opens, an error is
raised.

IF CtrlVal(RXLED) = 1

Error: Incompatible type in expression.

It's easy to fix in code but something to watch for.


EDIT: Going back to my first post:
Something flip mentioned (I'm not doing it) but looking at the manual:

QUOTE:
The value of the control can set to a literal string (not an expression) starting with two hash characters. For example: CtrlVal(nnn) = "##Enter Number"


Is this behaviour being invoked in MMbasic when it passes the ref# and caption$ by calling the MM.KEYPRESS subroutine?

Edited by KeepIS 2017-08-15
It's all too hard.
Mike.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 01:48pm 14 Aug 2017
Copy link to clipboard 
Print this post

Back in January TassyJim said in answer to my question about GUI controls
  Quote  I have avoided using the new command MM.KEYPRESS because it seems to have a problem.

Don't know if that is still relevant or not, or whether it applies to your problem.
Paul.

"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 01:57pm 14 Aug 2017
Copy link to clipboard 
Print this post

Thanks for that info, it could be, in my case that subroutine is working perfectly once I understood what was happening and allowed for it. I have two GUI controls working through it and both now behave correctly.

Edited by KeepIS 2017-08-15
It's all too hard.
Mike.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 04:07pm 14 Aug 2017
Copy link to clipboard 
Print this post

Not sure if this is related, but there appears to be a crossover effect between NumberBox and other GUIs, in this case GUI LED

I can't see what I am doing wrong (quite possible) but interaction with the NumberBox appears to kill the GUI LED action.


>print mm.ver
5.0405
> print mm.device$
Micromite eXtreme
> list
GUI numberbox #1,1,1,100,20,RGB(white),RGB(blue)
GUI led #2,"Heartbeat",100,100,10,RGB(red)

Do
Pause 500
If CtrlVal(#2)=0 Then
CtrlVal(#2) = 1
Else
CtrlVal(#2) = 0
EndIf
Loop
> run ' heartbeat LED pulsing OK, so switching on and off
' must work OK.
' NumberBox displayed on screen OK -
' at this point I touch the NumberBox and the keypad appears
' I touch 0 then Ent and the program crashes with the following
' error message
[6] If CtrlVal(#2)=0 Then
Error: Incompatible types in expression
> run
' same again but this time touching 0 then Ent
[6] If CtrlVal(#2)=0 Then
Error: Incompatible types in expression
>


Doug.

Edit: Even though the program has crashed - see error message above, the NumberBox is still active. ie. even though I have a command prompt after the error message, touching the NumberBox brings up the keypad and entering numbers show up in the NumberBox.
Question: Why is NumberBox still running in the background?

Edit2: Added a GUI switch line to the above as #3 which works fine but continues to work after the crash so it appears that the touch handling code is still active even though the program has crashed. This not a real world problem as if the program has stopped, there is little point in touching any controls still on the screen but I would think that for tidyness sake, the touch handling interrupt should be paused while in command mode? Maybe not? Might be a usefull debug tool?

This is independent of the crashing detailed at the top.
D.

Edited by panky 2017-08-16
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 04:42pm 14 Aug 2017
Copy link to clipboard 
Print this post

Hi Doug,

That is one of the problems I described, if you don't read the LED state then you won't have a problem, just set the GUI led and it's ok, LED=1, pause 500, LED=0.

It's reading the state that is causing the error.

IMHO, the KEYPAD life time is an independent of your code crashing, it's code is still running waiting until you press Ent.

EDIT: I think you answered your own question about keypad still running so ignore the last part.

Mike.

EDIT 2: I still read the GUI LED state in my code, however I set a flag before using a numberbox, that tells the GUI LED control code not to run until the "Ent" key is pressed for Numberbox that is open, at that point I reset the flag and everything is happy.
Edited by KeepIS 2017-08-16
It's all too hard.
Mike.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 05:14pm 14 Aug 2017
Copy link to clipboard 
Print this post

The interesting thing is Mike, that without NumberBox active (ie. rem'ed out), the code to read the value and flip the led works fine - it seems to be it's interaction with NumberBox that causes the crash.

I replaced the flip on/off code with a line
CTRLVAL(#2) = 500 to do a 500mS on/off as per the manual and this works fine and is impervious to any NumberBox action.

Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 06:02pm 14 Aug 2017
Copy link to clipboard 
Print this post

Yes I think I understand what you are getting at - However, it's not the Numberbox being active (AS IN DEFINED) but rather the action of touching the Numberbox which runs the MMBasic Keypad function. It's the keypad that's causing the problem in my case.

When you assign a time-cycle value to the GUI LED, you are also removing the code you had to read the state of the GUI LED, that is the problem, comment out those Read lines and your original code should work - it did in mine, but as I said above I am using them again as I cant' assign a time value as a Radio RX led is totally random and I need to see when it's receiving, I could hard wire a LED but I want to use the 5" LCD to display it, and it does perfectly and in sync with the miniature radio transceiver physical LED, even the duration.

Mike.Edited by KeepIS 2017-08-16
It's all too hard.
Mike.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 07:42pm 14 Aug 2017
Copy link to clipboard 
Print this post

You are right on the button Mike (no pun intended).

If you use a TEXTBOX command, the result is the same with the same error message.

Running a GUI SWITCH (which reacts to touch also) together with GUI LED instead of NUMBERBOX or TEXTBOX works fine with no error. The LED toggles and the switch reacts to touches as it should.

If you have a GUI SWITCH in a loop toggling on and off with a GUI TEXTBOX enabled, that also crashes as soon as the TEXTBOX is touched bring up the keypad.

Somewhere in the NUMBERBOX or TEXTBOX code, the ctrlval variable gets screwed up such that if you try to set the ctrlval of any other graphic entity such as the LED or SWITCH, they fail with the error message above in previous posts.

Doug.



... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 08:05pm 14 Aug 2017
Copy link to clipboard 
Print this post

Yes that's what I'm thinking, I didn't test it with a TEXTBOX as I assumed it would be the same, it also brings up a virtual keyboard and it calls same service procedure, but great to have it confirmed. I though for a while it was my code, I've got a over 1,500 lines and around 30 Procedures and Functions, properly considered small compared to some I've seen on the forum, but I've seen strange things happen from a totally unrelated (seemingly) hidden error in the code, especially with a few ISR's running and data coming in at very high rate.

Hopefully Geoff can shine a light on it when he gets a chance.

Mike.
Edited by KeepIS 2017-08-16
It's all too hard.
Mike.
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 08:48pm 14 Aug 2017
Copy link to clipboard 
Print this post

On thing I wanted to add: I have this code in the RX ISR:

If ATN_ON = 0 Then ' Meter or Graph screen?

CtrlVal(RXLED) = 1

Else

CtrlVal(RXLED2) = 1

End If

They are being switched off in the main DO loop, so not on and off in the same procedure or loop, so that is a difference I will try.

The code is running continuously in the RX ISR, the only difference is that I have a few pages of different GUI screens, so the screens with the GUI LEDS are switched out and another page, either my Setup page or Graph select page is in focus, both use a Numberbox and both are being updated with data even when the Keypad is open, but data is written by a NON GUI TEXT procedure - because it's a lot faster than using a GUI TEXT Caption.

That code turning RXLED2 on is always running (verified) and causes no problems, but if I were to read it's state before setting it (as I was before) the read of the GUI LED would crash the program.

This seems to be different to what you are seeing as I can turn them on or off at any time, I just can't read the status.

Mike.


UPDATE: I can confirm that I can switch a GUI LED on and off in the same procedure and everything is perfect. In my case, the only problem I have is reading a GUI LED state "when" a NUMBERBOX or TEXTBOX opens - that is the only instance where it crashes.

________________________________

UPDATE2: IF you read a GUI LED state in MM.KEYPRESS subroutine it crashes with the same error, Error: Incompatible types in expression.

Now this brings me FULL CIRCLE - If you change the code to:

IF CTRLVAL(RXLED2) = "1" then
do something
ENDIF

NO ERROR NO CRASH when changing it to a string value - BUT ONLY WHEN THE KEYPAD IS OPEN, otherwise it has to be numeric or it will again crash.

Again, when MM.KEYPRESS is invoked when a KEYPAD opens, the GUI LED changes from a NUMERIC input to a STRING. As does the GUI NUMBER BOX - see first and previous posts.

__________________________________

UPDATE 3:
Finally the last on this:

IF you set a flag when the KEYPAD opens, and this flag changes the GUI LED check value to a string, everything is happy.

When you reset the flag after the KEYPAD close, and the GUI LED check value is changed to numeric, everything is happy.

That's all the testing I'm going to do on it.

Cheers.

Mike.
Edited by KeepIS 2017-08-16
It's all too hard.
Mike.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 01:41pm 15 Aug 2017
Copy link to clipboard 
Print this post

@KeepIS

Mike,

I'm pretty sure this is a bug so it's one for Geoff and Peter I think. Nice work on figuring out a work around.

Cheers,
Doug
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:56pm 15 Aug 2017
Copy link to clipboard 
Print this post


Mike,
It's a lot easier to look at posted code if in your post you use the little CODE box above the POST REPLY window. Clicking on it inserts (CODE)(/CODE) in your post, but actually with those four round brackets being square, not round. Those four square brackets signal the forum software to insert a 'code box' and anything you type or paste between the two sets of square brackets will not have its formatting changed by the forum software, for instance indents etc. are maintained. You can copy and paste your code between the brackets or just type between them. To go back to your 'normal' post just start typing after the closing square bracket. E.g the first bit of code in your top post will come out looking like:

If ATN_ON = 0 Then ' Meter or Graph screen?

CtrlVal(RXLED) = 1

Else

CtrlVal(RXLED2) = 1

End If


IMHO it's also more readable with single spacing like:
If ATN_ON = 0 Then ' Meter or Graph screen?
CtrlVal(RXLED) = 1
Else
CtrlVal(RXLED2) = 1
End If


Greg
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 04:05pm 15 Aug 2017
Copy link to clipboard 
Print this post

Thanks Greg, I was wondering about that but did not have the time to search for it.

Another round to it that I could have ticked of the list - has I actually got a Roundtoit.

Mike.
It's all too hard.
Mike.
 
lew247

Guru

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

I've started "playing" with the GUI NUMBERBOX command but im not sure of something

Can I make the box a specific size then write a number inside the box the number varying depending on the program
for example wind speed
so one minute it might display 0 and the next 37?

Or is there a better way to do this?
Edited by lew247 2017-08-18
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1099
Posted: 12:46am 17 Aug 2017
Copy link to clipboard 
Print this post

Lew,

It is as simple as using the control defined for the NUMBERBOX a value - I use ref below

eg. ctrlval(ref) = 200

Doug.



... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
lew247

Guru

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

Thanks Doug, what if I have more than one box? is that the (ref) ? - the number of the box?
 
KeepIS

Guru

Joined: 13/10/2014
Location: Australia
Posts: 1399
Posted: 02:56pm 17 Aug 2017
Copy link to clipboard 
Print this post

I see Geoff has chimed on this on the second newer thread, so it will be good to have it sorted, like I said before, it's no big deal as my workaround is simple and effective, but down the track I know it will come back to bite someone new to programming.

Mike.
It's all too hard.
Mike.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024