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 : GUI Demos
Author | Message | ||||
retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 131 |
Could people kindly add working demo code for GUI controls. I was sure there was a demo which showed all the controls but i can't find it. Others showing the latest developments would be a great help to study. I have snatched a few samples from the forum but it is still a steep learning curve. I'm running an Extreme 144 with 7" SDD 1963 display if that helps Thanks.. Gen1 Honda Insights. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5867 |
Micromite Plus Manual under Examples In my copy, it starts on page 39 It may not have all the GUI elements but it's a good start. Jim VK7JH MMedit MMBasic Help |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1094 |
@retepsnikrep Peter, A copy of Geoff's program to save you typing it in - just select the code below and paste into MMEdit for download to your MZ 144. Note as Geoff says in the manual, it is just a demo of GUI controls. Have fun. Doug. ' Pump Control program from Micromite Plus Manual ' Geoff Graham 2016 ' Option Explicit Dim ledsY Colour RGB(white), RGB(black) ' 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 Font 3 : GUI Caption c_pmp, "Pump", 20, 60, , RGB(brown) ' now, define and display the controls ' first display the switch Font 4 GUI Switch sw_pmp, "ON|OFF", 20, 90, 150, 50, RGB(white),RGB(brown) CtrlVal(sw_pmp) = 1 ' the flow rate display box Font 3 : GUI Caption c_flow, "Flow Rate", 20, 170,, RGB(brown),0 Font 4 : GUI Displaybox tb_flow, 20, 200, 150, 45 CtrlVal(tb_flow) = "20.1" ' the radio buttons and their frame Font 3 : GUI Frame frm_pump, "Power", 20, 290, 170, 163,RGB(200,20,255) GUI Radio r_econ, "Economy", 35, 318, 25, RGB(230, 230, 255) GUI Radio r_norm, "Normal", 35, 364 GUI Radio r_hi, "High", 35, 408 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) 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) CtrlVal(nbr_lo) = 15.7 : CtrlVal(nbr_hi) = 35.5 ' draw the two LEDs Const ledsX = 240, coff = 50 ' define their position ledsY = 90 : GUI LED led_run, "Running", ledsX, ledsY, 30, RGB(green) ledsY = ledsY+49 : GUI LED led_alarm, "Alarm", ledsX, ledsY, 30, RGB(red) 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", 450, 20, 330, 355, RGB(green),0 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 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 GUI Spinbox sb_bright, MM.HPos + 8, 400, 200, 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 Restore 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 GUI beep 250 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 ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1321 |
The Manual's p39 pump demo should be allright with @retepsnikrep's 7" display, but it throws some errors with my 4.3" display (SSD1963 480x272 in landscape mode). At a quick look it seems some of the controls are defined outside the range of the 4.3 inch-er. Guess that should be noted in the Manual. Greg |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3163 |
Good point, I will do that. Geoff Geoff Graham - http://geoffg.net |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Try this Version. I think it's the one I modified to run on the CGMicro2 with a 320 240 display. Tiny stuff but it did work. Phil. [code]''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Demonstration program for the Micromite+ ' It does not do anything useful except demo the various controls ' ' Geoff Graham, October 2015 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Autorun On Option Explicit Dim ledsY Colour RGB(white), RGB(black) ' 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 : GUI Caption c_head, "Pump Control", 10, 0 Font 2 : GUI Caption c_pmp, "Pump", 10, 25, , RGB(brown) ' now, define and display the controls ' first display the switch Font 2 GUI Switch sw_pmp, "OFF|ON", 10, 45, 70, 30, RGB(white),RGB(brown) CtrlVal(sw_pmp) = 1 ' the flow rate display box Font 2 : GUI Caption c_flow, "Flow Rate", 5, 75,, RGB(brown),0 Font 2 : GUI Displaybox tb_flow, 5, 100, 105, 25 CtrlVal(tb_flow) = "20.1" ' the radio buttons and their frame Font 2 : GUI Frame frm_pump, "Power", 5, 140, 105, 90,RGB(200,20,255) Font 1 GUI Radio r_econ, "Economy", 10, 150, 25, RGB(230, 230, 255) GUI Radio r_norm, "Normal", 10, 175 GUI Radio r_hi, "High", 10, 200 CtrlVal(r_norm) = 1 ' start with the "normal" button selected ' the alarm frame with two number boxes and a push button switch Font 2 : GUI Frame frm_alarm, "Alarm", 115, 115, 90, 115,RGB(green) Font 1 GUI Caption c_hi, "Hi:", 120, 150, LT, RGB(yellow) GUI Numberbox nbr_hi, 150,MM.VPos-6,40,MM.FontHeight+6,RGB(yellow),RGB(64,64,64) GUI Caption c_lo, "Lo:", 120, 175, LT, RGB(yellow),0 GUI Numberbox nbr_lo, 150,MM.VPos-6,40,MM.FontHeight+6,RGB(yellow),RGB(64,64,64) GUI Button pb_test, "TEST", 125, 200, 70, 25,RGB(yellow), RGB(red) CtrlVal(nbr_lo) = 15.7 : CtrlVal(nbr_hi) = 35.5 ' draw the two LEDs Const ledsX = 125, coff = 50 ' define their position ledsY = 50 : GUI LED led_run, "Running", ledsX, ledsY, 16, RGB(green) ledsY = ledsY+25 : GUI LED led_alarm, "Alarm", ledsX, ledsY, 16, RGB(red) 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 Font 2 GUI Frame frm_log, "Log File", 210, 10, 110, 160, RGB(green),0 Font 1 GUI Checkbox cb_enabled, "Log On", 215, 20, 20, RGB(cyan) GUI Caption c_fname, "File Name", 215, 45 GUI Textbox tb_fname, 215, 60, 100, 20, RGB(cyan), RGB(64,64,64) GUI Caption c_log, "Record:", 215, 85, , RGB(cyan), 0 GUI Checkbox cb_flow, "Flow", 220, 100, 20 GUI Checkbox cb_alarm, "Alarms", 220, 120, 20 GUI Checkbox cb_warn, "Warnings", 220, 140, 20 CtrlVal(cb_enabled) = 1 CtrlVal(tb_fname) = "LOGFILE.TXT" ' define and display the spinbox for controlling the backlight GUI Caption c_bright, "Back Light", 230, 190,,RGB(200,200,255),0 GUI Spinbox sb_bright, 210, 210, 110, 25,,,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 Restore 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 Print CtrlVal(sw_pmp) 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 Open "Test.txt" For Append As #1 Print "File Opened" Print #1, "Hello World", Time$ Print "Hello World", Time$ Close #1 Print "File Closed" CtrlVal(led_alarm) = 1 GUI beep 250 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 [/code] |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1321 |
Yes that works OK on the 4.3 inch-er. Leaves some spare room but shows the idea. As-is there's a double-barreled shotgun down at the 'Power' radio buttons; these few changes on lines 39 to 41 fix that. Greg GUI Radio r_econ, "Economy", 20, 160, 10, RGB(230, 230, 255) GUI Radio r_norm, "Normal", 20, 185 GUI Radio r_hi, "High", 20, 210 |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Just reloaded this in a new E100 with 5.05.01 & get a error. Line [56] Error: Argument count Easily fixed by removing ",0" from the lines end, but may be worth a change in the manual for the new comers @geoffg. Cheers Phil. Edit:- Is it just me or do others feel the display behaviour of the switch is back the front? As in the "On" side is bigger & brighter when the switch is in the off position? And Vise versa. Edited 2020-02-12 11:19 by Phil23 |
||||
mikeb Senior Member Joined: 10/04/2016 Location: AustraliaPosts: 173 |
@Phil23 I thought the same, on first glance, but then reasoned that the 'brighter' object was the target of my intention. It got me past what I originally thought was odd. @all you wizards out there. It would be great to have an application that created a work space, from a drop down menu, with the intended display resolution. It would also have a list of icons representing the available controls which could be placed on the work space giving a 'real' representation of how the display would look at 'runtime'. These controls could be 'rescaled' on the fly. Font size could also be selected. It would also create the 'Page' structure. In the background, it would create the necessary code to allow pasting into a users 'runtime' environment. It would take so much time out of the 'visualisation' required when writing code. This is a similar concept to the 4D Systems IDE. regards, Mike B. Edited 2020-02-12 16:51 by mikeb There are 10 kinds of people in the world. Those that understand binary and those that don't. |
||||
Print this page |