Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:44 27 Nov 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 : PicoMite GUI TEXTBOX control

Author Message
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 06:33am 10 Oct 2023
Copy link to clipboard 
Print this post

Hi All,
I'm trying to learn the GUI TEXTBOX control (Manual page 59).

The following works - but with a twist:
- it correctly shows the prompt "Tap Here~For Keyboard" on two lines and the keyboard.
- when you tap it to bring up the keyboard SUB PenDown prints the prompt (not surprising because that was the value of CtrlVal).
- when you enter text and tap "Ent", the box displays the entered text but PenDown only prints the entered text when you tap the box again - ready for the next text entry, NOT when you tap the "Ent".

1) is that expected?
2) how does one capture the entered text?
3) does anyone have any sample code?

Cheers,

Andrew


'GUI TextBox.BAS
 ' Playing with the onscreen keyboard
 ' Needs:
 '  PicoMite 5.0707
 '  OPTION GUI CONTROLS 10   'or more - from the CONSOLE (only uing 1 now)
 '
 OPTION EXPLICIT
 OPTION DEFAULT NONE  
 cls
 GUI INTERRUPT PenDown
 
 font #3, 1          'Sets the default font
 GUI Textbox #1, 10, 10, mm.hres-20, 100, rgb(Black), RGB(Cyan)
 CtrlVal(#1) = "##Tap Here~For Keyboard"
 
 'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
 'Start of the main loop
 DO
 
 Loop
 'end of the main loop
 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
SUB PenDown
 print "TOUCH(REF) =";TOUCH(REF)
 SELECT CASE TOUCH(REF)  
   CASE 1
     print CtrlVal(#1)
   CASE Else
     Print "Not expected"
 END SELECT
END SUB
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 07:31am 10 Oct 2023
Copy link to clipboard 
Print this post

You need a Touch Up Interrupt (page 70 in the manual).  That interrupt is fired when the keyboard is closing and CtrVal will be correct.

BTW you should avoid doing to much processing in the interrupt.  See page 33.

Geoff
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 07:37am 10 Oct 2023
Copy link to clipboard 
Print this post

Thanks Geoff.
Do any of your projects use the keyboard?
{Edit: Not being too lazy but I DO find your code instructive - eg the Watering System}

Andrew
Edited 2023-10-10 17:52 by Andrew_G
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 08:08am 10 Oct 2023
Copy link to clipboard 
Print this post

No, I don't.  Actually I have built very few practical projects using the Maximite/Micromite/Picomite/etc.  I seem to spend most of my time developing the firmware and hardware, not building.

If you are looking for example software using the GUI controls then the demo program on page 48 of the Micromite Plus Manual is a good place to start.  This should run unchanged on the Picomite (untested).

Geoff
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 08:12am 10 Oct 2023
Copy link to clipboard 
Print this post

Thanks Geoff.
I'll play with it tonight.

Regards,

Andrew
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 10:06am 10 Oct 2023
Copy link to clipboard 
Print this post

Hi Geoff,
A great video and the code will be very useful.
I'm using a 4" 480x320 LCD so there are lots of errors as it is written for a higher res screen (as noted at the bottom of page 48) - but the code is there as good examples as to what to do.

If I succeed in fitting it into my screen (should be easy) I'll let you know.

Regards,

Andrew
Edited 2023-10-10 20:30 by Andrew_G
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 01:37pm 10 Oct 2023
Copy link to clipboard 
Print this post

I got the gui numeric pad to work with no interrupt. It's a stepper motor controller for a mate, input pulse width and count.

 OPTION EXPLICIT
 OPTION DEFAULT NONE
 OPTION AUTORUN ON
 CONST outpin = 7
 dim pulsewidth%,pulsecount%,count%
 pulsewidth%=10
 Font 5:cls
 GUI NUMBERBOX #1, 0, 100, 240, 64, rgb(blue), rgb(yellow)
 do  
   CtrlVal(#1) = "##STEPS?"
   do
     pulsecount%=CtrlVal(#1)
   loop while pulsecount%=0
   'text 0,200, "Counting"
   for count%=1 to pulsecount%
     'text 200,200, str$(count%)'+"  "
     pin(outpin)=1:pause pulsewidth%:pin(outpin)=0:pause pulsewidth%
   next count%
   pause 2000
   text 0,200,"        "  
 loop
 end

 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 11:23pm 10 Oct 2023
Copy link to clipboard 
Print this post

Thanks Stan.
Yes that approach is fine for one item to control but if the main loop was busy doing other things there might be a timing issue?
(And I like the challenge of fitting Geoff's demo code to a smaller screen).

Cheers,

Andrew
Edited 2023-10-11 09:25 by Andrew_G
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 12:19am 11 Oct 2023
Copy link to clipboard 
Print this post

As Geoff says, you should not do anything in the interrupt other then setting flags, really, and have your main look check the flags and act accordingly.

Some snippets from one of my codes that uses the textbox:


GUI SETUP 2 'Database Access Process
 FONT 4,2
 GUI DISPLAYBOX DB_ACCESS,0,0,MM.HRES,75,RGB(RED),RGB(BLACK)
 CTRLVAL(DB_ACCESS)="RESTRICTED ACCESS!"
 FONT 4,1
 GUI TEXTBOX PASSWORD,275,150,250,50,RGB(WHITE),RGB(BLACK)
 GUI CAPTION CAP_DB_PWD,"Enter the correct password, then touch OK.",75,275,LT,RGB(CYAN)
 
GUI SETUP 4 'EXIT and OK buttons for any page
 FONT 7,2
 GUI BUTTON BU_EXIT,"EXIT",75,400,200,50,RGB(BLUE),RGB(GRAY)
 GUI BUTTON BU_OK,"OK",525,400,200,50,RGB(RED),RGB(GRAY)
 
 
'Blah, blah, blah - main code etc here....


'=============================
'DATABASE MANAGEMENT ROUTINES:
'=============================
'-------------------
'OBTAIN ACCESS CODE:
'-------------------
GET_PASSWORD:
 KEY=0:LCD_EXIT=0:LCD_OK=0 'Clear flags
 IF DEBUG THEN PRINT "Get Password."
 PAGE 2,4
 CTRLVAL(PASSWORD)="##PASSWORD"
 GUI INTERRUPT EXIT_OK
 DO
   IF LCD_EXIT=1 THEN
     LCD_EXIT=0 'Clear flag
     IF DEBUG THEN PRINT "EXIT button touched.(get password)"
     GOTO START
   ENDIF
   IF LCD_OK=1 THEN
     LCD_OK=0 'Clear flag
     IF DEBUG THEN PRINT "OK button touched.(get password)"
     IF CTRLVAL(PASSWORD)=STDPWD$ THEN
       IF DEBUG THEN PRINT "Password correct."
       GOTO DATABASE_EDITOR
     ELSE
     SYSMSG$="Password incorrect.(database access)"
     IF DEBUG THEN PRINT SYSMSG$
     IF SYSLOG THEN WRITE_SYSLOG(SYSMSG$)
     CTRLVAL(CAP_DB_ADW)="DENIED."
     PAGE 3 'Access denied
     GUI Beep 1000
     PAUSE 2500
     GOTO START
     ENDIF
   ENDIF
 LOOP
 
 
 
'=============================
'GUI TOUCH INTERRUPT ROUTINES:
'=============================

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


This example is just how I am doing textboxes, but it has always worked.  I am in no way professing that this is "The best" way to do anything, this is just an example.    Note I am using a few GOTO's to jump around inside the main loop, which is technically a no-no, and I should be using ENDIF's for a more "Clean" code, but this is code from 2016....

These are only the relevant code snippets, not the entire code which is thousands of lines.  The first thing I do at the top of the code, is setup all the GUI pages.
"Page 2" is where I setup the textbox, and "Page 4" is used in many screens - anywhere I need a screen with an OK and EXIT button.

Next, in the PASSWORD routine - which is part of the main loop, but a loop within itself - we call the textbox to be shown so you can enter some text into it(with the command PAGE 2,4), and WHILE THIS IS HAPPENING, the code just sits inside the loop in the password routine, waiting for either the LCD_EXIT or LCD_OK flags to become true(equal to one).

Inside this loop, you could - if you wanted - have a timeout so that the code is forced back to the main menu etc, but I am just not doing that, but THERE is where you would allow for that if you wanted or needed it.

Now, look at the interrupt routine - all I do is find out which control is being touched(one of two buttons in this case), and set a flag, and exit the interrupt immediately - "Thou shalt not hang around in interrupts."

While the textbox is displayed, you can enter in anything you like, and MMBASIC takes care of saving that in the background for you.  When you touch the OK button, that sets the flag, then returns to the password routine - where the loop detects that the OK flag is now true, so it processes that part of the loop to find out if the password entered is correct or not, by sucking the entered text out of the textbox control, and comparing it with the actual password.

What's really lovely about the GUI pages, is that only the active pages are detected by the TOUCH(REF) function, which means inactive pages of GUI controls that you might be able to see in the background, are totally ignored.  

An example of use of the textbox only - no warranty or guarantee implied!
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 12:37am 11 Oct 2023
Copy link to clipboard 
Print this post

Thanks Grogs,

Very helpful - it will take me some time to digest . . .
I'm 80% through converting Geoff's 'page 48 +' demo program to run on lower res screens.

(Have you seen the discussion re HC-12 antennae?)

Cheers,

Andrew
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 01:03am 11 Oct 2023
Copy link to clipboard 
Print this post

Yes, GUI controls can be quite confusing at first, but hang in there!
Once you get your head around how the interrupts work, and just finding out what you need to do inside your loops(and not inside the interrupts), it starts to make sense.  

Yes, saw the HC12 thread - I'm heading over there shortly to read that one.
Smoke makes things work. When the smoke gets out, it stops!
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 02:00am 11 Oct 2023
Copy link to clipboard 
Print this post

Hi all,
I've butchered Geoff's code (from pages 49-50 of the MicroMite Plus manual - see Geoff's link above). It runs on my 480x320 LCD on a PicoMite.
There were a couple of scaling tweaks required as noted within the code.
I've left Geoff's code in, commented out where required, so it is not as messy as it looks.

Geoff's code really demonstrates how simple it is to use the GUI functions.


Andrew



 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Demonstration program for the Micromite+
 ' It does not do anything useful except demo the various controls
 '
 ' Geoff Graham, October 2015
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Edited by Andrew_G to enable display on a 480 x 320 LCD as well as Geoff's 800 x 480.
 '
 ' '+A_G and '-A_G annotate changes in Geoff's code (ie + and -)
 ' Most of the changes are made by XF and YF below but there are a few manual tweaks.
 ' These are annotated "Looks better".
 ' It runs on a 480x320 LCD and should run on others - albeit with some easthetic tweaking.
 ' There have been some manual tweaks due to:
 '   changes in FONT sizes
 '   non-scalability of the thickness of radio buttons, LEDs and checkboxes.
 ' The effort has gone into making it work as intended, not into making it look
 ' as good as Geoff has it on the larger format.
 ' All acolades (and complaints) to Geoff . . .
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Option Explicit
 Dim ledsY
 Colour RGB(white), RGB(black)
 
 '+A_G all lines of code between '+A_G and '+a_g have been added ('-A_G  '-a_g have been commented out)
 Const XF = mm.HRES/800  'Factor to convert x distances to current display
 Const YF = mm.VRES/480  'Factor to convert y distances to current display
 CONST True = 1
 CONST False = 0
 CONST BeepOK = False    'Set to 'True' if Touch Beep has been set etc (not in A_G's case)
 '+a_g
 
 ' reference numbers for the controls are defined as constants
 Const c_head = 1, c_pmp = 2, sw_pmp = 3, c_flow = 4, tb_flow = 5
 Const led_run = 6, led_alarm = 7
 Const frm_alarm = 20, nbr_hi = 21, nbr_lo = 22, pb_test =23
 Const c_hi = 24, c_lo = 25
 Const frm_pump = 30, r_econ = 31, r_norm = 32, r_hi = 33
 Const frm_log = 40, cb_enabled = 41, c_fname = 42, tb_fname = 43
 Const c_log = 44, cb_flow = 45, cb_pwr = 46, cb_warn = 47
 Const cb_alarm = 48, c_bright = 49, sb_bright = 50
 ' now draw the "Pump Control" display
 CLS
 GUI Interrupt TouchDown, TouchUp
 ' display the heading
 'Font 2,2 : GUI Caption c_head, "Pump Control", 10, 0     '-A_G
 Font 3,1 : GUI Caption c_head, "Pump Control", XF*10, 0   '+A_G (note: no YF)
 
 'Font 3 : GUI Caption c_pmp, "Pump", 20, 60, , RGB(brown)         '-A_G
 Font 2,1 : GUI Caption c_pmp, "Pump", XF*20, YF*60, , RGB(brown)  '+A_G
 ' now, define and display the controls
 ' first display the switch
 Font 4
 GUI Switch sw_pmp, "ON|OFF", XF*20, YF*90, XF*150, YF*50, RGB(white),RGB(brown)
 CtrlVal(sw_pmp) = 1
 ' the flow rate display box
 'Font 3 : GUI Caption c_flow, "Flow Rate", XF*20, YF*170,, RGB(brown),0   '-A_G
 Font 4,1 : GUI Caption c_flow, "Flow Rate", XF*20, YF*170,, RGB(brown),0  '+A_G
 Font 4 : GUI Displaybox tb_flow, XF*20, YF*200, XF*150, YF*45
 CtrlVal(tb_flow) = "20.1"
 ' the radio buttons and their frame
 'Font 3 : GUI Frame frm_pump, "Power", XF*20, YF*290, XF*170, YF*163, RGB(200,20,255)   '-A_G
 Font 4,1 : GUI Frame frm_pump, "Power", XF*20, YF*290, XF*170, YF*163, RGB(200,20,255)  '+A_G
 
 'GUI Radio r_econ, "Economy", XF*43, YF*328, 12, RGB(230, 230, 255)     '-A_G
 'GUI Radio r_econ, "Economy", XF*43, YF*328, XF*12, RGB(230, 230, 255)  '+A_G tweaked below
 GUI Radio r_econ, "Economy", XF*43, YF*328, 10, RGB(230, 230, 255)      '+A_G XF*12 replaced by '10'
 
 'GUI Radio r_norm, "Normal", 43, 374      '-A_G
 'GUI Radio r_hi, "High", 43, 418          '-A_G
 GUI Radio r_norm, "Normal", XF*43, YF*374 '+A_G
 GUI Radio r_hi, "High", XF*43, YF*418     '+A_G
 CtrlVal(r_norm) = 1 ' start with the "normal" button selected
 
 ' the alarm frame with two number boxes and a push button switch
 
 'Font 3 : GUI Frame frm_alarm, "Alarm", 220, 220, 200, 233,RGB(green)               '-A_G
 Font 4,1 : GUI Frame frm_alarm, "Alarm", XF*220, YF*220, XF*200, YF*233,RGB(green)  '+A_G
 
 '-A_G
 'GUI Caption c_hi, "High:", 232, 260, "LT", RGB(yellow)
 'GUI Numberbox nbr_hi, 318,MM.VPos-6,90,MM.FontHeight+12,RGB(yellow),RGB(64,64,64)
 'GUI Caption c_lo, "Low:", 232, 325, LT, RGB(yellow),0
 'GUI Numberbox nbr_lo, 318,MM.VPos-6,90,MM.FontHeight+12,RGB(yellow),RGB(64,64,64)
 'GUI Button pb_test, "TEST", 257, 383, 130, 40,RGB(yellow), RGB(red)
 '-a_g
 '+A_G
 GUI Caption c_hi, "High:", XF*232, YF*260, "LT", RGB(yellow)
 GUI Numberbox nbr_hi, XF*318,MM.VPos-YF*6,XF*90,MM.FontHeight+YF*12,RGB(yellow),RGB(64,64,64)
 GUI Caption c_lo, "Low:", XF*232, YF*325, LT, RGB(yellow),0
 GUI Numberbox nbr_lo, XF*318,MM.VPos-YF*6,XF*90,MM.FontHeight+YF*12,RGB(yellow),RGB(64,64,64)
 GUI Button pb_test, "TEST", XF*257, YF*383, XF*130, YF*40,RGB(yellow), RGB(red)
 '+a_g
 
 CtrlVal(nbr_lo) = 15.7 : CtrlVal(nbr_hi) = 35.5
 
 ' draw the two LEDs
 '-A_G
 'Const ledsX = 255, coff = 50 ' define their position
 'ledsY = 105 : GUI LED led_run, "Running", ledsX, ledsY, 15, RGB(green)
 'ledsY = ledsY+49 : GUI LED led_alarm, "Alarm", ledsX, ledsY, 15, RGB(red)
 'CtrlVal(led_run) = 1 ' the switch defaults to on so set the LED on
 '-a_g
 '+A_G
 Const ledsX = XF*255, coff = 50 ' define their position A_G Note: this is th eonly occurance of 'coff'
 'ledsY = YF*105 : GUI LED led_run, "Running", ledsX, ledsY, XF*15, RGB(green)     'Strict change
 'ledsY = ledsY+YF*49 : GUI LED led_alarm, "Alarm", ledsX, ledsY, XF*15, RGB(red)  'Strict change
 ledsY = YF*105 : GUI LED led_run, "Running", ledsX, ledsY, 10, RGB(green)         'A_G Looks better
 ledsY = ledsY+YF*49 : GUI LED led_alarm, "Alarm", ledsX, ledsY, 10, RGB(red)      'A_G Looks better
 CtrlVal(led_run) = 1 ' the switch defaults to on so set the LED on
 '+a_g
 
 ' the logging frame with check boxes and a text box
 Colour RGB(cyan), 0
 '-A_G
 'GUI Frame frm_log, "Log File", 450, 20, 330, 355, RGB(green)
 'GUI Checkbox cb_enabled, "Logging Enabled", 470, 50, 30, RGB(cyan)
 'GUI Caption c_fname, "File Name", 470, 105
 'GUI Textbox tb_fname, 470, 135, 290, 40, RGB(cyan), RGB(64,64,64)
 'GUI Caption c_log, "Record:", 470, 205, , RGB(cyan), 0
 'GUI Checkbox cb_flow, "Flow Rate", 500, 245, 25
 'GUI Checkbox cb_alarm, "Alarms", 500, 285, 25
 'GUI Checkbox cb_warn, "Warnings", 500, 325, 25
 '-a_g
 '+A_G
 'GUI Frame frm_log, "Log File", XF*450, YF*20, XF*330, YF*355, RGB(green)   'Strict change
 GUI Frame frm_log, "Log File", XF*450, YF*20, XF*335, YF*355, RGB(green)    'Looks better
 'GUI Checkbox cb_enabled, "Logging Enabled", XF*470, YF*50, XF*30, RGB(cyan)'Strict change
 GUI Checkbox cb_enabled, "Logging Enabled", XF*470, YF*50, 25, RGB(cyan)    'Looks better
 GUI Caption c_fname, "File Name", XF*470, YF*105
 GUI Textbox tb_fname, XF*470, YF*135, XF*290, YF*40, RGB(cyan), RGB(64,64,64)
 GUI Caption c_log, "Record:", XF*470, YF*205, , RGB(cyan), 0
 'GUI Checkbox cb_flow, "Flow Rate", XF*500, YF*245, XF*25 'Strict change
 'GUI Checkbox cb_alarm, "Alarms", XF*500, YF*285, XF*25   'Strict change
 'GUI Checkbox cb_warn, "Warnings", XF*500, YF*325, XF*25  'Strict change
 GUI Checkbox cb_flow, "Flow Rate", XF*500, YF*245, 25     'Looks better
 GUI Checkbox cb_alarm, "Alarms", XF*500, YF*285, 25       'Looks better
 GUI Checkbox cb_warn, "Warnings", XF*500, YF*325, 25      'Looks better
 '+a_g
 
 CtrlVal(cb_enabled) = 1
 CtrlVal(tb_fname) = "LOGFILE.TXT"
 ' define and display the spinbox for controlling the backlight
 'GUI Caption c_bright, "Backlight", 442, 415, ,RGB(200,200,255),0         '-A_G
 'GUI Spinbox sb_bright, MM.HPos + 8, 400, 200, 50,,,10, 10, 100           '-A_G
 GUI Caption c_bright, "Backlight", XF*442, YF*415, ,RGB(200,200,255),0    '+A_G
 GUI Spinbox sb_bright, MM.HPos + XF*8, YF*400, XF*200, YF*50,,,10, 10, 100'+A_G
 CtrlVal(sb_bright) = 100

 ' All the controls have been defined and displayed. At this point
 ' the program could do some real work but because this is just a
 ' demo there is nothing to do. So it just sits in a loop.
 Do : Loop
 ' the interrupt routine for touch down
 ' using a select case command it has a different process for each control
Sub TouchDown
 Select Case Touch(REF) ' find out the control touched
   Case cb_enabled ' the enable check box
     If CtrlVal(cb_enabled) Then
       GUI ENABLE c_fname, tb_fname, c_log, cb_flow, cb_alarm, cb_warn
     Else
       GUI Disable c_fname, tb_fname, c_log, cb_flow, cb_alarm, cb_warn
     EndIf
   Case sb_bright ' the brightness spin box
     BackLight CtrlVal(sb_bright)
   Case sw_pmp ' the pump on/off switch
     CtrlVal(led_run) = CtrlVal(sw_pmp)
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 20.1)
     CtrlVal(r_norm) = 1
   Case pb_test ' the alarm test button
     CtrlVal(led_alarm) = 1
     If BeepOK then GUI beep 250                           '+A_G (the only change to this SUB
   Case r_econ ' the economy radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 18.3)
   Case r_norm ' the normal radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 20.1)
   Case r_hi ' the high radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 23.7)
 End Select
End Sub
 ' interrupt routine when the touch is removed
Sub TouchUp
 Select Case Touch(LASTREF) ' use the last reference
   Case pb_test ' was it the test button
     CtrlVal(led_alarm) = 0 ' turn off the LED
 End Select
End Sub


 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 10:56pm 11 Oct 2023
Copy link to clipboard 
Print this post

Hello all,
Now that I've got Geoff's demo working on my 480x320 screen I can play with the code.
The penny is slowly dropping.
As Geoff said above, the TouchUp is used to capture the TEXTBOX and NUMBERBOX entries.

I added the last three Case tests to the TouchUp SUB and it becomes a BFO (Blinding Flash of the Obvious).
Rather than printing the values one might use a variable to take back into the main loop for printing and use.

Many thanks,

Andrew


Sub TouchUp
 'print "LASTREF= "; Touch(LASTREF)
 Select Case Touch(LASTREF) ' use the last reference
   Case pb_test ' was it the test button
     CtrlVal(led_alarm) = 0 ' turn off the LED
   Case nbr_hi
     print "Alarm Hi= ";CtrlVal(nbr_hi)
   Case nbr_lo
     print "Alarm Lo= ";CtrlVal(nbr_lo)
   CASE tb_fname 'Keyboard closed by tapping "Ent"
     print "Fname= ";CtrlVal(tb_fname)
 End Select
End Sub
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 06:49am 12 Oct 2023
Copy link to clipboard 
Print this post

Sounds like you are making progress.

Unless you want to take immediate action you don't need to trap the touchup and touchdown events.  For example, if you defined a textbox for the user to enter a file name thus:
GUI Textbox #3, 470, 135, 290, 40, RGB(cyan), RGB(64,64,64)

When you come to open the file you could simply refer to the control value of the textbox, thus:
OPEN CtrlVal$(#3) FOR OUTPUT AS #1

Nothing more is required and you don't need to know what the user has typed into the textbox.

Geoff
P.S. You might need to trap any errors (using ON ERROR) in the OPEN statement in case the user typed an invalid filename/path.
P.S.S. Let me know if I have confused you!
Geoff Graham - http://geoffg.net
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 07:13am 12 Oct 2023
Copy link to clipboard 
Print this post

Thanks Geoff.
That makes sense and the ERROR checking is a good hint.

Cheers,

Andrew

PS: Is an idea to repeat the video and sample code from the MicroMite Plus manual in the PicoMite manual??
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 08:47am 12 Oct 2023
Copy link to clipboard 
Print this post

  Quote  P.S. You might need to trap any errors (using ON ERROR) in the OPEN statement in case the user typed an invalid filename/path.


I hate and despise ON ERROR  

Much better to us MM.INFO(EXISTS FILE fname$) to do the check before opening
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 04:07am 13 Oct 2023
Copy link to clipboard 
Print this post

Hi Peter,
I'll use MM.INFO(EXISTS FILE . . .).

Cheers,

Andrew
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 08:51pm 16 Oct 2023
Copy link to clipboard 
Print this post

Hi all,
Here is an update of the code, with most of the editorial comments removed.
It is otherwise unchanged for my version above.
(and it has no error checking).

Cheers,

Andrew


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Demonstration program for the Micromite+
 ' It does not do anything useful except demo the various controls
 '
 ' Geoff Graham, October 2015
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' Edited by Andrew_G to enable display on a 480 x 320 LCD as well as Geoff's 800 x 480.
 '
 ' '+A_G and '-A_G annotate changes in Geoff's code (ie + and -)
 ' Most of the changes are made via XF and YF below but there are a few manual tweaks.
 ' These are annotated "A_G Looks better".
 ' It runs on a 480x320 LCD and should run on others - albeit with some easthetic tweaking.
 ' There have been some manual tweaks due to:
 '   changes in FONT sizes
 '   non-scalability of the thickness of radio buttons, LEDs and checkboxes.
 ' The effort has gone into making it work as intended, not into making it look
 ' as good as Geoff has it on the larger format.
 ' All acolades to Geoff . . .
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 Option Explicit
 Dim ledsY
 Colour RGB(white), RGB(black)
 Const XF = mm.HRES/800  '+A_G Factor to convert x values to current display
 Const YF = mm.VRES/480  '+A_G Factor to convert y values to current display
 CONST True = 1
 CONST False = 0
 CONST BeepOK = False    '+A_G Set to 'True' if Touch Beep has been set etc (not in A_G's case)
 
 ' reference numbers for the controls are defined as constants
 Const c_head = 1, c_pmp = 2, sw_pmp = 3, c_flow = 4, tb_flow = 5
 Const led_run = 6, led_alarm = 7
 Const frm_alarm = 20, nbr_hi = 21, nbr_lo = 22, pb_test =23
 Const c_hi = 24, c_lo = 25
 Const frm_pump = 30, r_econ = 31, r_norm = 32, r_hi = 33
 Const frm_log = 40, cb_enabled = 41, c_fname = 42, tb_fname = 43
 Const c_log = 44, cb_flow = 45, cb_pwr = 46, cb_warn = 47
 Const cb_alarm = 48, c_bright = 49, sb_bright = 50
 
 ' now draw the "Pump Control" display
 CLS
 GUI Interrupt TouchDown, TouchUp
 ' display the heading
 Font 3,1 : GUI Caption c_head, "Pump Control", XF*10, 0   '+A_G (note: no YF)
 Font 2,1 : GUI Caption c_pmp, "Pump", XF*20, YF*60, , RGB(brown)
 
 ' now, define and display the controls
 ' first display the switch
 Font 4
 GUI Switch sw_pmp, "ON|OFF", XF*20, YF*90, XF*150, YF*50, RGB(white),RGB(brown)
 CtrlVal(sw_pmp) = 1
 
 ' the flow rate display box
 Font 4,1 : GUI Caption c_flow, "Flow Rate", XF*20, YF*170,, RGB(brown),0
 Font 4 : GUI Displaybox tb_flow, XF*20, YF*200, XF*150, YF*45
 CtrlVal(tb_flow) = "20.1"
 
 ' the radio buttons and their frame
 Font 4,1 : GUI Frame frm_pump, "Power", XF*20, YF*290, XF*170, YF*163, RGB(200,20,255)
 GUI Radio r_econ, "Economy", XF*43, YF*328, 10, RGB(230, 230, 255)      '+A_G XF*12 replaced by '10'
 GUI Radio r_norm, "Normal", XF*43, YF*374 '+A_G
 GUI Radio r_hi, "High", XF*43, YF*418     '+A_G
 CtrlVal(r_norm) = 1 ' start with the "normal" button selected
 
 ' the alarm frame with two number boxes and a push button switch
 Font 4,1 : GUI Frame frm_alarm, "Alarm", XF*220, YF*220, XF*200, YF*233,RGB(green)
 GUI Caption c_hi, "High:", XF*232, YF*260, "LT", RGB(yellow)
 GUI Numberbox nbr_hi, XF*318,MM.VPos-YF*6,XF*90,MM.FontHeight+YF*12,RGB(yellow),RGB(64,64,64)
 GUI Caption c_lo, "Low:", XF*232, YF*325, LT, RGB(yellow),0
 GUI Numberbox nbr_lo, XF*318,MM.VPos-YF*6,XF*90,MM.FontHeight+YF*12,RGB(yellow),RGB(64,64,64)
 GUI Button pb_test, "TEST", XF*257, YF*383, XF*130, YF*40,RGB(yellow), RGB(red)
 CtrlVal(nbr_lo) = 15.7 : CtrlVal(nbr_hi) = 35.5
 
 ' draw the two LEDs
 Const ledsX = XF*255, coff = 50 ' define their position A_G Note: this is the only occurance of 'coff'
 ledsY = YF*105 : GUI LED led_run, "Running", ledsX, ledsY, 10, RGB(green)   'A_G Looks better
 ledsY = ledsY+YF*49 : GUI LED led_alarm, "Alarm", ledsX, ledsY, 10, RGB(red)'A_G Looks better
 CtrlVal(led_run) = 1 ' the switch defaults to on so set the LED on
 
 ' the logging frame with check boxes and a text box
 Colour RGB(cyan), 0
 GUI Frame frm_log, "Log File", XF*450, YF*20, XF*335, YF*355, RGB(green)    'A_G Looks better
 GUI Checkbox cb_enabled, "Logging Enabled", XF*470, YF*50, 25, RGB(cyan)    'A_G Looks better
 GUI Caption c_fname, "File Name", XF*470, YF*105
 GUI Textbox tb_fname, XF*470, YF*135, XF*290, YF*40, RGB(cyan), RGB(64,64,64)
 GUI Caption c_log, "Record:", XF*470, YF*205, , RGB(cyan), 0
 GUI Checkbox cb_flow, "Flow Rate", XF*500, YF*245, 25     'A_G Looks better
 GUI Checkbox cb_alarm, "Alarms", XF*500, YF*285, 25       'A_G Looks better
 GUI Checkbox cb_warn, "Warnings", XF*500, YF*325, 25      'A_G Looks better
 CtrlVal(cb_enabled) = 1
 CtrlVal(tb_fname) = "LOGFILE.TXT"
 
 ' define and display the spinbox for controlling the backlight
 GUI Caption c_bright, "Backlight", XF*442, YF*415, ,RGB(200,200,255),0    
 GUI Spinbox sb_bright, MM.HPos + XF*8, YF*400, XF*200, YF*50,,,10, 10, 100
 CtrlVal(sb_bright) = 100
 
 ' All the controls have been defined and displayed. At this point
 ' the program could do some real work but because this is just a
 ' demo there is nothing to do. So it just sits in a loop.
 Do : Loop
 
 ' the interrupt routine for touch down
 ' using a select case command it has a different process for each control
Sub TouchDown
 Select Case Touch(REF) ' find out the control touched
   Case cb_enabled ' the enable check box
     If CtrlVal(cb_enabled) Then
       GUI ENABLE c_fname, tb_fname, c_log, cb_flow, cb_alarm, cb_warn
     Else
       GUI Disable c_fname, tb_fname, c_log, cb_flow, cb_alarm, cb_warn
     EndIf
   Case sb_bright ' the brightness spin box
     BackLight CtrlVal(sb_bright)
   Case sw_pmp ' the pump on/off switch
     CtrlVal(led_run) = CtrlVal(sw_pmp)
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 20.1)
     CtrlVal(r_norm) = 1
   Case pb_test ' the alarm test button
     CtrlVal(led_alarm) = 1
     If BeepOK then GUI beep 250             '+A_G (the only change to this SUB
   Case r_econ ' the economy radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 18.3)
   Case r_norm ' the normal radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 20.1)
   Case r_hi ' the high radio button
     CtrlVal(tb_flow) = Str$(CtrlVal(sw_pmp) * 23.7)
 End Select
End Sub
 
 ' interrupt routine when the touch is removed
Sub TouchUp
 Select Case Touch(LASTREF) ' use the last reference
   Case pb_test ' was it the test button
     CtrlVal(led_alarm) = 0 ' turn off the LED
 End Select
End Sub

 
Print this page


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

© JAQ Software 2024