[TUTORIALS] V-TFT beginners example projects

General discussion on Visual TFT Software.
Author
Message
igeorge
Posts: 593
Joined: 28 Dec 2005 09:15

Re: [TUTORIAL] V-TFT beginners example project

#61 Post by igeorge » 12 Jun 2014 00:17

Hello Robert,
Finally, after hours on the phone with Filip it did work
The issue was the Hardware
ME sold to Mouser Mikromedia board , but they were different than one in the example.
For this reason, the Mikromedia board never initialize, so blank white screen
Second issue was the SD card.
I had 2 GB card which i could read on the card reader, but not on the Mikromedia.
Then, i changed to a 4 Gb card, same FAT format, and it start working
I look at your Demo but i do not have a 32 bit card
Mine is the Pic18FJ card
Do you have a tutorial for cards like that ?
Thanks
Ion
Experience is something you don't get until just after you need it

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#62 Post by Megahurts » 14 Jun 2014 21:11

Hi igeorge,

Sorry for late reply, been out of town couple of days.

Glad to hear that you guys figured out the issue(s). Good news indeed. :D

Now for some more kind of good news;
Now that you have a known working device V-TFT HW Profile, use (make another) copy of the tutorial event counter project (either the PIC32 or dsPIC33EP),
and load it in to V-TFT and open the options dialog, select your known working HW profile for the PIC18F MMB, and make sure the compiler language
is set to mBASIC, and when finished click 'OK'.

This will cause V-TFT to rebuild the project again and now the projects 'main' file has been replaced by the default framework layout
for the HW profile and compiler language settings changed in options.
(so it will not at present run correctly if compiled and loaded to your MMB device!!!)

Now EVERYTHING from the line below the programs name in the 'main' file needs to be replaced with the code that the tutorial
originally had as I supplied, by editing it in your compiler and recompiling, full license compiler version required.

The tutorial application is not dependent on any hardware or I/O connections for this reason, so it can be transported to any media HW.

You just need to make sure that all of the tutorials code or code to drive the wheel gadget display and/or the 2-click safety is transferred to the
V-TFT project set for any different hardware.

The software would need to be translated to the other languages manually in order to work with their compilers.

I think this is all you need to have it work, there might be postings earlier in this topic also to check, GL.
Robert. B^)
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

peek of CNC controller screen1

#63 Post by Megahurts » 16 Jun 2014 03:26

Hi All following,

Here is a quick peek of my CNC 3-Axis router controller screen 1 for personal project working on.
CnC_ClickStepper_Screen1.jpg
CnC_ClickStepper_Screen1.jpg (231.3 KiB) Viewed 15397 times
Center Circle Button is Dynamic so the caption can be changed to different letters reflecting operational modes, all others and background
circles are Static objects in the X/Y Axis movement control. (SS shown for Single Step per touch mode operation)
Color Zones/Buttons are Full-Step (Red), 1/2-Step (Yellow), 1/4-Step (Green) and 1/8-Step (Blue) motor movement modes.

Z-Axis control is on the right side, only 1/2 (Yellow), 1/4 (Green) and 1/8 (Blue) steps are allowed. Park Button turns Off and raises router for tool change/adjustment.

I mention this because There will be methods/tricks I will be using to make it work that will be shown as tutorials. :wink:

Regards, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: [TUTORIAL] V-TFT beginners example project

#64 Post by MaGiK » 16 Jun 2014 14:35

Hello Megahurts :D

I can see that you've been working hard on this.
Please keep up the great work.

I can't stop falling in love with CNC's and PCB's, so waiting for you to finish is like waiting for something very awesome to happen, such as waiting for MikroElektronika products to reach our warm homes :mrgreen:

Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#65 Post by Megahurts » 17 Jun 2014 00:09

Thanks MaGiK,
I can see that you've been working hard on this.
I have been thinking about and wanting one for many years now. I have been gathering parts from various machinery
(Obtainium we call it, something you Obtain and put to use doing something else),
for the components that would eventually mesh together to give me the functionality I wanted and need.
I use to buy used government equipment at auctions and anything that could not be resold-as-is or easily repaired, got torn apart
for recycling turn in, minus the Obtainium I kept for projects building, and I have a lot of projects going needing materials.

That screen though, got started four days ago. It is still in designing stage and changed a little from posting already, but reflects what
has been in my minds eye for some time now, just not crystal clear yet. But it will get there.

It is because of making my own PCB's for prototyping that I have a great need for it now. The more complex the designs are getting
means more drilling of component and via holes at tighter and tighter requirements, so doing by hand is getting harder and time consuming.
(and errors are happening too often by hand)

The prototyping of this will be done on the mmWorkStation so some code will be targeted for its unified device I/O connections library.
The WorkStation has the 4 Click board sockets, so using 3 of them for axis drives (and 1 or more yet to be determined), will make
this easy to develop and test without needing to make and drill a custom PCB first. (did I mention I hate drilling PCBs? or like least anyway.)

There will also be code for handling push button equivalents of TFT-TP inputs and how to handle doing it so routines for screen event handling are used (not hard).
I also have a high quality dual gimbals joystick from auction obtainium that RC controlled something robotic, that I might use instead of the TFT-TP one I made (last picture).
(use current design for testing app for driving motors at least)

I am excited for this one to be done too. It has the potential to help all projects from then on out and make some possible now when not before.

More later, will try to get pics of the HW taken to post, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

[TUTORIAL] V-TFT LAYOUT TRICK.

#66 Post by Megahurts » 20 Jun 2014 04:07

Hello V-TFT users,

Here is a little time saving Trick you can use in V-TFT when it comes time to assign events to your screen(s) objects.
Please refer to this image of modified layout and the parts I have marked with letter labels.
V-TFT layout trick.jpg
V-TFT layout trick.jpg (358.13 KiB) Viewed 15351 times
A. It was because most of the 60 objects on the screen would need TP event actions assigned to them that I figured this out.
B. For this example, this button object is selected, and will need a "OnClick()" event assigned.

C. TIP: The V-TFT documentation says to double click the action assignment box, but you must first have the "focus" of "Windows"
in the action assignment box before "double clicking" the box. A single click here puts the "Focus" on the box (cursor present),
then a double click here will work as the instructions say.

D. Double Clicking the assignment box places a new event handler routine in the events_code file at the location between the end of the last
routine and the end of the file - shown by these arrows (E). (mPASCAL code version shown)

F. After "Double Clicking" the assignment box, Windows "Focus" is switched to the "User Code" window.

Normally, you would have to now 'switch' back to the "Screen View" window in order to select the next object to have its event
action assigned, but with this layout (or any layout similar that has the "User Code" window always showing), you can now just click
on the next object you want to make an assignment for.

No more bouncing back and forth between screen and code windows while doing the assignments.

I only change the layout to this after doing all of the object editing (position and other properties editing... object name changes...).
Otherwise I use the default layout so I have a larger screen editing window to do object placements, (old eyes, so bigger is better for me).

I hope you find this useful with your work in V-TFT, Robert.

(BTW: @ MaGiK, I know you are following this so I have good news, the missing connectors have arrived today and are soldered in,
Now to get the code done so testing of them can be done.
Also as you can see, the design of the screen has changed a little, and more changes made to the 'Static' properties of many
buttons has also been done after I spent some time thinking about how I would want it to be able to change appearance depending
on the different modes that can be selected. The truth is that MMBs have very limited screen space and it takes a few tries to get
a layout set up that will be both easy to use and display the data needed. So there will probably be a few more changes before it is done.) :D
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

CNC controller screen layout update.

#67 Post by Megahurts » 22 Jun 2014 17:23

An update to the stepper controller screen1 has been done, here is a composite picture of the different menus that will be used.
With limited screen area to use and more functions I thought of that need to be accessed from this screen, I decided to have
the menu buttons on the bottom be dynamic and changeable, so 3 sets of 5 buttons can be changed by user during use.
cnc stepper menus.jpg
cnc stepper menus.jpg (226.61 KiB) Viewed 15317 times
The methodology of how this is done will be shown in the code example that follows. It should be noted that at this time, only 2 of
the allocated 3 sets of buttons will be coded for use until I think of other functions/features (if any) I need to add. So menu set 3
buttons that do not have a function assigned will have "xxxx" set in the buttons caption property.
With the buttons being dynamic (allocated in RAM) visual effects can be implemented to assist in providing more output state indications.
The menu 1 set shows one such occurrence with the "ALOCK" button. This button will control a Axis LOCK feature (all of the rectangles in the X,Y axis move input area)
that restricts movement inputs to 45 degree increments only. This will be the default start up state so the button must be preset
to the visual settings for showing it is in effect in V-TFT before compiling. The red color is set in the single (no gradient) color property,
by simply changing the gradient enabled property, one can flip easily between two different appearances for the button (gradient colors are set like the others),
by changing the Gradient Enabled (True-1/False-0) property and redrawing the button.

When the ALOCK function is OFF, the button will be grey gradient like the others and all of the rectangles on the axis movement
area will be gone, allowing for a variable analog like movement control of the X and Y axises to be input on the screen area.
(to do this, I had to also change the Static properties of the 32 rectangle buttons to True (in V-TFT), so their Active properties could be set False
and prevent any TP input that could conflict with tracking exact TP press point within the circular step-increment zones.)

The example code will follow in the next post later today, still working on it and making tutorial comments for the code and usage.

Oh, and I had to change the HW device targeted for this application, it was first set for the PIC18F MMB and mP compiler but
once I got done with the Screen1 layout and opened the project in mP and did a successful build, the code generated by V-TFT
alone took up over 49% of the ROM memory! I had not added a single line of User Code yet and could not see the PIC18F MMB
being able to handle all of the features and functions I would like it to have.
So I have switched the target HW to the dsPIC33EP MMB (and mBASIC Pro), I have on hand and with the User Code written so far the memory usage is now at:
RAM - 6.9% used
ROM - 11.1% used
Much better statistics for this early in the project. :D

[edit note] I also realized that I would need a bunch of floating point variables used to handle the precision and unit
conversions this will need so it will work like I want/need it to. The dsPIC33EP or PIC32 then became the best of the only
options I have to choose from. So going to try the dsPIC33EP first and save the PIC32 MMB for something else that needs
the processing power it has.

Robert.
Last edited by Megahurts on 24 Jun 2014 15:01, edited 2 times in total.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

A STANDARD USER CODE ROUTINE FOR ALL V-TFT PROJECTS

#68 Post by Megahurts » 22 Jun 2014 22:59

Init_Vars(): A STANDARD USER CODE ROUTINE FOR ALL V-TFT PROJECTS.

Here is a pre-release of a new topic coverage addition to the tutorial PDF for those following this thread.
If you do not already do this with your projects, you should find it useful.
(the pdf coverage will include figures, images and example code listings of other tricks/tips)

V-TFT provides a number of code editing/input windows in the advanced project options areas depending on what HW profile
you have selected and option boxes checked or not.
(the content will also change when changes to target compiler or target HardWare options are changed in V-TFT)

They are each actually a separate sub routine code editor for us to add our own code to be executed when that routine gets called and
they all get called (if present because enabled in V-TFT project settings and options), from the "Start_TP()" instruction that gets executed first
in the project 'main' file. This call sends program execution to that routine located (implemented) in the projects 'driver' file/module.
Other start up routines V-TFT needs executed get called from here and some can be called from a routine called from here too.
All V-TFT projects have a few routines that are always present in a project and get called from the "Start_TP()" routine, and one
always present is also the first routine code editor you see in the V-TFT project options dialog window labeled "Init Code".
Code in this window shows up in the projects driver file in the routine named "Init_MCU()".

A V-TFT project will not function correctly or at all if these 'Start-Up' routines do not get executed or you make a change to the code that
corrupts the HW configurations or prevents proper execution of those tasks.
The explanation of those tasks is not covered here, and will be covered in a different topic section.

I have mentioned them because just like their importance to making a functioning V-TFT project,
Your 'User Code' that you have to make to bring life to what you designed in V-TFT will require its own initializing routine to preset
many of the 'User Variables' your code uses in order to work (correctly) when it is started up and other MCU HW you need to use in the project initialized or preconfigured (PORT inputs/outputs).

Sounds like reasonable requirements assumption yes?

The problems V-TFT users have mostly with trying to comply to this requirement usually comes down to where to place the code where
it is safe from being overwritten by V-TFT when editing project in V-TFT.

Here is a practice/method I have developed and use that I find easy to implement and provides consistent successful results.
With its usage in all projects created, it also means you are keeping a lot of code that could be responsible for making your
project work or not in one consistent location for easier debugging checks and tests.

Here is a code listing of the CNC controller projects 'events_code' file and example User "Init_Vars()" routine and the first event handler routine that changes the menu buttons, and a listing of the 'main' file with the call that is also required:
*These are not completed/finished program code, it is work in progress and opportunity for me to put out V-TFT tips and tricks faster than updating the PDF manual right now. So enjoy while it lasts for this project.

Code: Select all

module PIC33EP_CNC_Stepper_events_code

include PIC33EP_CNC_Stepper_objects
include PIC33EP_CNC_Stepper_resources
include PIC33EP_CNC_Stepper_driver

sub procedure Scrn1Btn_Menu2_EDIT_OnClick()
....  '* edited to save space in post
sub procedure Scrn1Btn_MenuCHANGE_OnClick()
....  '* edited to save space in post
sub procedure Scrn1CrclBtn_HOME_OnClick()
'--------------------- Externals ---------------------'
'----------------- End of Externals ------------------'

'-------------- User code declarations ---------------'
' V-TFT Driver File DrawObject Routines for Project List
' DrawScreen()
' DrawButton(@)
' DrawRoundButton(@)
' DrawCRoundButton(@)
' DrawCLabel(@)
' DrawCircle(@)
' DrawCCircle(@)
' DrawCircleButton(@)
' DrawCCircleButton(@)

' User Code Routines declaration List (only routines called from outside this module need to be listed)
sub procedure Init_Vars()

' User Code Global Variables declarations
dim MENU_PAGE    as byte
    STEP_MODE    as byte
    PRESS_COUNT  AS byte
    X_AXIS       as float
    Y_AXIS       as float
    Z_AXIS       as float


' User Code Global Array Variables for Shapes and Measurements and Axis Limits
dim SHAPE_RECTANGLE as float[3][8][2] '[3]x[4x2-POINT(X,Y)] [CUBED(Hi/Lo Z)] RECTANGLES
    SHAPE_TRIANGLE  as float[3][6][2] '[3]x[3x2-POINT(X,Y)] [CUBED(Hi/Lo Z)] TRIANGLES
    SHAPE_CIRCLE    as float[3][3][2] '[3]x[X, Y, Radius]   [CUBED(Hi/Lo Z)] CIRCLES
    MEASURE_X       as float[3]       '[X Axis StartX, EndX, Result]
    MEASURE_Y       as float[3]       '[Y Axis StartY, EndY, Result]
    MEASURE_Z       as float[3]       '[Z Axis StartZ, EndZ, Result]
    LIMIT_X         as float[3]       '[2 X-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    LIMIT_Y         as float[3]       '[2 Y-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    LIMIT_Z         as float[3]       '[2 Z-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    
' User Code Global Constants declarations


'----------- End of User code declarations -----------'

implements

'--------------------- User code ---------------------'
sub procedure Init_Vars()
' Presets User Code Global Variables
' [Tutorial Comments]- Making this routine and code to Call-It (in main project file),
' first in all projects makes the Compiler include the variables and their memory
' allocations in the compilation result. Otherwise, the compiler would determine
' any declared variables not actually referenced by any code as something to eliminate
' from the program code and will not be accounted for in compiled memory usage results.
'
'  This ensures you get a better sense of the resources your User Code will be using
' as you develop the application. As you add/declare Global variables to the code,
' put an entry here to assign a preset value so project statistics are accurate
' after a successful project build. Just declaring a variable does not ensure it
' stays present and accounted for in the final build.

 dim X, Y as byte  ' local temp variables

 MENU_PAGE   = 1
 STEP_MODE   = 1
 PRESS_COUNT = 0
 X_AXIS      = 0
 Y_AXIS      = 0
 Z_AXIS      = 0
 
 for X = 0 to 2      ' clear X,Y,Z measurement arrays
   MEASURE_X[X] = 0
   MEASURE_Y[X] = 0
   MEASURE_Z[X] = 0
                     ' clear X,Y,Z limits arrays
   LIMIT_X[X]   = 0
   LIMIT_Y[X]   = 0
   LIMIT_Z[X]   = 0
 next X
 X = 0
 LIMIT_X[2]   = 1    ' set default enforced areas to Inside axis points
 LIMIT_Y[2]   = 1
 LIMIT_Z[2]   = 1
 
 for X = 0 to 2      ' clear the 3 rectangle shapes
   for Y = 0 to 7
     SHAPE_RECTANGLE[X][Y][0] = 0
     SHAPE_RECTANGLE[X][Y][1] = 0
   next Y
 next X
 X = 0 Y = 0
 
 for X = 0 to 2      ' clear the 3 triangle shapes
   for Y = 0 to 5
     SHAPE_TRIANGLE[X][Y][0] = 0
     SHAPE_TRIANGLE[X][Y][1] = 0
   next Y
 next X
 X = 0 Y = 0
 
 for X = 0 to 2      ' clear the 3 circle shapes
   for Y = 0 to 2
     SHAPE_CIRCLE[X][Y][0] = 0
     SHAPE_CIRCLE[X][Y][1] = 0
   next Y
 next X
end sub

'----------------- End of User code ------------------'

' Event Handlers

'---------- Start of Screen1 Menu-1 Buttons handling
sub procedure Scrn1Btn_MenuCHANGE_OnClick()
' changes Active, Visible, Press color properties of 2 menu button sets (5 each)

 if (MENU_PAGE = 1) then  ' flip menus
    MENU_PAGE = 2
   else
    MENU_PAGE = 1
 end if
 
 select case MENU_PAGE    ' change properties and redraw current active set
   case 1                 ' Menu 1 set active
     Scrn1Btn_MenuCHANGE__Caption           = "MENU 1"
     Scrn1Btn_MenuSMODE_.Visible            = 1  '
     Scrn1Btn_MenuSMODE_.Active             = 1  ' Button 1
     Scrn1Btn_MenuSMODE_.PressColEnabled    = 1  '
     Scrn1Btn_MenuLIMITS_.Visible           = 1  '
     Scrn1Btn_MenuLIMITS_.Active            = 1  ' Button 2
     Scrn1Btn_MenuLIMITS_.PressColEnabled   = 1  '
     Scrn1Btn_MenuALOCK_.Visible            = 1  '
     Scrn1Btn_MenuALOCK_.Active             = 1  ' Button 3
     Scrn1Btn_MenuALOCK_.PressColEnabled    = 1  '
     Scrn1Btn_MenuPLAY_.Visible             = 1  '
     Scrn1Btn_MenuPLAY_.Active              = 1  ' Button 4
     Scrn1Btn_MenuPLAY_.PressColEnabled     = 1  '
     Scrn1Btn_MenuRECORD_.Visible           = 1  '
     Scrn1Btn_MenuRECORD_.Active            = 1  ' Button 5
     Scrn1Btn_MenuRECORD_.PressColEnabled   = 1  '

  ' set 2 buttons to false (inactive)
     Scrn1Btn_Menu2_SHAPE_.Visible          = 0  '
     Scrn1Btn_Menu2_SHAPE_.Active           = 0  ' Button 1
     Scrn1Btn_Menu2_SHAPE_.PressColEnabled  = 0  '
     Scrn1Btn_Menu2_MEASUR_.Visible         = 0  '
     Scrn1Btn_Menu2_MEASUR_.Active          = 0  ' Button 2
     Scrn1Btn_Menu2_MEASUR_.PressColEnabled = 0  '
     Scrn1Btn_Menu2_SAVREC_.Visible         = 0  '
     Scrn1Btn_Menu2_SAVREC_.Active          = 0  ' Button 3
     Scrn1Btn_Menu2_SAVREC_.PressColEnabled = 0  '
     Scrn1Btn_Menu2_EDIT_.Visible           = 0  '
     Scrn1Btn_Menu2_EDIT_.Active            = 0  ' Button 4
     Scrn1Btn_Menu2_EDIT_.PressColEnabled   = 0  '
     Scrn1Btn_Menu2_SETUP_.Visible          = 0  '
     Scrn1Btn_Menu2_SETUP_.Active           = 0  ' Button 5
     Scrn1Btn_Menu2_SETUP_.PressColEnabled  = 0  '
     DrawButton(@Scrn1Btn_MenuSMODE_)       ' redraw buttons to make visible.
     DrawButton(@Scrn1Btn_MenuLIMITS_)
     DrawButton(@Scrn1Btn_MenuALOCK_)
     DrawButton(@Scrn1Btn_MenuPLAY_)
     DrawButton(@Scrn1Btn_MenuRECORD_)

   case 2                 ' Menu 2 set active
     Scrn1Btn_MenuCHANGE__Caption           = "MENU 2"
     Scrn1Btn_MenuSMODE_.Visible            = 0  '
     Scrn1Btn_MenuSMODE_.Active             = 0  ' Button 1
     Scrn1Btn_MenuSMODE_.PressColEnabled    = 0  '
     Scrn1Btn_MenuLIMITS_.Visible           = 0  '
     Scrn1Btn_MenuLIMITS_.Active            = 0  ' Button 2
     Scrn1Btn_MenuLIMITS_.PressColEnabled   = 0  '
     Scrn1Btn_MenuALOCK_.Visible            = 0  '
     Scrn1Btn_MenuALOCK_.Active             = 0  ' Button 3
     Scrn1Btn_MenuALOCK_.PressColEnabled    = 0  '
     Scrn1Btn_MenuPLAY_.Visible             = 0  '
     Scrn1Btn_MenuPLAY_.Active              = 0  ' Button 4
     Scrn1Btn_MenuPLAY_.PressColEnabled     = 0  '
     Scrn1Btn_MenuRECORD_.Visible           = 0  '
     Scrn1Btn_MenuRECORD_.Active            = 0  ' Button 5
     Scrn1Btn_MenuRECORD_.PressColEnabled   = 0  '

  ' set 2 buttons to True (active)
     Scrn1Btn_Menu2_SHAPE_.Visible          = 1  '
     Scrn1Btn_Menu2_SHAPE_.Active           = 1  ' Button 1
     Scrn1Btn_Menu2_SHAPE_.PressColEnabled  = 1  '
     Scrn1Btn_Menu2_MEASUR_.Visible         = 1  '
     Scrn1Btn_Menu2_MEASUR_.Active          = 1  ' Button 2
     Scrn1Btn_Menu2_MEASUR_.PressColEnabled = 1  '
     Scrn1Btn_Menu2_SAVREC_.Visible         = 1  '
     Scrn1Btn_Menu2_SAVREC_.Active          = 1  ' Button 3
     Scrn1Btn_Menu2_SAVREC_.PressColEnabled = 1  '
     Scrn1Btn_Menu2_EDIT_.Visible           = 1  '
     Scrn1Btn_Menu2_EDIT_.Active            = 1  ' Button 4
     Scrn1Btn_Menu2_EDIT_.PressColEnabled   = 1  '
     Scrn1Btn_Menu2_SETUP_.Visible          = 1  '
     Scrn1Btn_Menu2_SETUP_.Active           = 1  ' Button 5
     Scrn1Btn_Menu2_SETUP_.PressColEnabled  = 1  '
     DrawButton(@Scrn1Btn_Menu2_SHAPE_)     ' redraw buttons to make visible.
     DrawButton(@Scrn1Btn_Menu2_MEASUR_)
     DrawButton(@Scrn1Btn_Menu2_SAVREC_)
     DrawButton(@Scrn1Btn_Menu2_EDIT_)
     DrawButton(@Scrn1Btn_Menu2_SETUP_)
 end select
end sub

Code: Select all

' *
' * Project name:
'     PIC33EP_CNC_Stepper.vtft
' * Generated by:
'     Visual TFT
' * Date of creation
'     6/20/2014
' * Time of creation
'     11:25:43 AM
' * Test configuration:
'     MCU:             P33EP512MU810
'     Dev.Board:       Mikromedia_for_dsPIC33_EP
'     Oscillator:      140000000 Hz
'     SW:              mikroBasic PRO for dsPIC
'                      http://www.mikroe.com/mikrobasic/dspic/
' *

program PIC33EP_CNC_Stepper_main

main:
                    ' the "Init_Vars()" call could go here also and be executed first if needed
  Start_TP()

  Init_Vars()     ' preload User Variables for start-up values
  
  WS_Init()

  while TRUE
    Check_TP()
                         ' the "Init_Vars()" call should NOT GO here inside the Main Loop.
  wend


end.
The "Init_Vars()" call can also be placed in the V-TFT user "Init_MCU()" routine that resides in the projects driver file as shown below.
V-TFT User Init code editor.jpg
V-TFT User Init code editor.jpg (190.59 KiB) Viewed 15294 times
(Adding the routine call "Init_Vars()" code instruction to the "Init_MCU()" routine by editing in a compiler will get overwritten/erased
when project is rebuilt in V-TFT, it must be added to that routine by using the "Init Code" editing window in V-TFT.)


One thing I am trying to figure out if it can be done, is to have all of those properties in each button set
being pointed to a single variable that then is changed between 0 and 1 to basically turn off or on the whole
set of buttons and only require 1 instruction line to affect them all.??
*Additionally, a method that does this would be best if it did not require editing the objects properties listings in the project 'driver' or 'objects' file.
(trying to find a way that is safe from being overwritten by V_TFT when project is loaded back in for any editing)

This may not be possible though, pointers and references to variables is an area in programming I am still trying to get my head around,
so I am not sure there is a way to 'group' the properties desired together so they all 'look' at the same variable or memory location
by some code that exists only in the 'User Code' or 'User Declarations' safe areas in the "events_code" module.

Maybe aCkO will read this and understand what I'm attempting and show a solution. It is one of the things I
wanted to get a method figured out for this year for you other users to be able to take advantage of.
I think it could be a very useful trick for being able to manage multiple objects better, like making it easier to have 'pop-up' windows/panels
for additional input or messages displayed on the same screen.
The problem I am having trying to figure this out, is that the objects properties are in a structure and need to affect certain properties in multiple objects,
without breaking anything so V-TFT won't work when it is done.

The method should work out like this (simple example for one objects properties):
In 'events_code' user declarations a variable of type needed to hold the properties possible values (byte or word usually) for True and False is declared.
Now references or pointers are declared so the value in the User Code variable gets assigned to the objects properties we want tied together.
changing the User Code variable to either a 1 or 0 would be like changing each property tied together in the object just like doing it with
an assignment instruction for each property, without the need to execute that many instructions, then a redraw of either all objects
grouped like this or a complete screen redraw will reflect and show the changes it caused to those objects.

How to tie many structured variables (in different objects) to one variable or memory location?

Anyone with good understanding of variable pointers and references have any ideas? or questions for more info about this?

One solution I am contemplating is to make a copy of either the 'driver' or 'objects' files and try the most obvious pointer implementation
of modifying those properties declarations or assignments in the copy and change its module name slightly and change the includes to use it instead of the original.
This way, V-TFT will not overwrite the files contents because it will not load that module file in to V-TFT if project is opened in V-TFT again.
Editing changes will be reflected and done to the original file and need to be replicated by user to the alternate file and the includes declaration changed again to use it.
(opinions, comments or questions on this very welcomed)

But back to the posting topic now to close it out, I think this methodology with User variables is a good practice that everyone should consider using.
It has made my work with V-TFT projects go a lot smoother and allowed for easier editing of the variable elements when needed.
(and it works for all 3 compiler languages!)

Hope this installment gives you guys some ideas and insight for your projects, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: [TUTORIAL] V-TFT beginners example project

#69 Post by MaGiK » 27 Jun 2014 14:31

Hello Megahurts :D
Megahurts wrote:(BTW: @ MaGiK, I know you are following this so I have good news, the missing connectors have arrived today and are soldered in. Now to get the code done so testing of them can be done. Also as you can see, the design of the screen has changed a little, and more changes made to the 'Static' properties of many buttons has also been done after I spent some time thinking about how I would want it to be able to change appearance depending on the different modes that can be selected. The truth is that MMBs have very limited screen space and it takes a few tries to get a layout set up that will be both easy to use and display the data needed. So there will probably be a few more changes before it is done.)
You should have said "BTW: @ MaGiK, I know you are stalking this ..." :lol:

Thank you so much for the updates.
They sound very promising.
I'm counting the days for you to finish.

BTW, I didn't answer you earlier on this because I was very busy reading for my final test. I got my M.Sc. degree yesterday (26/6/2014) and my grade is 85% -----> 89%. I don't know the exact grade, but I'm extremely happy that I have finally completed my studies. Man! They were too hard!

From now and on, I'll be free to catch up with your activities. Please keep them coming :D

Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#70 Post by Megahurts » 27 Jun 2014 17:50

Hey MaGiK,

Congratulations on the Degree and getting through it with a nice grade! So....it took how many days to sober up after??? :mrgreen: :lol:
Or is the party yet to come? :shock: :P

Glad you're back regardless. :D
"BTW: @ MaGiK, I know you are stalking this ..."
:lol:
Yea, whoop, whoop, I have a stalker finally! 8) :lol:

Seriously though, very glad to hear that you will have more free time, because I might need to borrow some of it. he,he,he :twisted:
How's your math skills? Mine suck.
Believe it or not, I got my math credits in High School (1976-1978) by taking computer programming (*D.E.C. BASIC) and did not really do any math,
the computer did it all. :oops:
*(Digital Equipment Corporation)

This was back when there were very few people that could write programs (before MS-DOS even) or knew how much math
a programmer was actually doing vs what math the computer was actually doing (to the non-computer science teachers, it
just looked like a lot of algebra equations, even to the math teachers) so the school officials assumed that us students were
doing a lot of math and gave us credits for algebra and calculus, but I never took either of those in High School and only did a
few courses of algebra in College uhhmm... .. 30 years ago (I think that's right :oops: ).

After that, when I went in to the Army for electronics training, they gave us the equations we needed to use (in the theory
phase on electronics) and required us to have a scientific calculator on hand at all times, even when taking tests - which was
more about identifying symptoms and diagnosing the malfunctions and very little math work required at that stage, just find
the induced problem, identify it specifically and successfully repair and test it. This I was very good at, not one practice or final
test problem missed and had the best score and time through course (self paced - 22 week long course done in 10 & 1/2 weeks).

Anyway, these days for me when it comes to coding solutions that require complex algorithms, I have to teach myself the
math most times if I can not figure out a simplistic way to code it or find an example to use to make the code work.

This CNC Mill project is going to kill many of my brain cells (most will suicide themselves I think), and at my age, not many to
spare left in there as it is. :roll: The ones in the best shape I have left only want to play Foosball 24/7. The next group that
seems to get a large say in things just want to grab the guitar and Rock Out 24/7 (I think they are the stoners that hid while I
was in the Army, but have decided they had enough of the closet and want to go on Tour with Ozzy. (I blame Ozzy for this
dilemma, getting Black Sabbath back together at his age, shame on him :evil: )

So as you can see, with another marathon night of bouncing between Wikipedia looking up Cartesian and Polar Coordinate
systems to refresh my memory and getting the elements identified that will need to be (maybe?) coded to make this work
without getting myself too deep in to stuff I have no right to attempt doing in code, has caused me to start blabbering already.
(low on caffeine too I think)

BTW, project code stats is now at:
18.6% RAM used; 81.4% free of 53248 bytes available.
12% ROM used; 88% free of 350207 bytes available.
Mostly just getting the variables and constants identifiers declared and around 16-24 common functions and routines coded I
have determined will be needed by event handler routines for axis's controls I have some code done for now.

So if you do not mind, I might need to pick your brain on some math questions soon. Trying to get the basics done first so
can do some testing on different motors I have.

I can post the files later if you'd like to look over what is so far, after I get some food and coffee in my system and a couple
of errands taken care of?

Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: [TUTORIAL] V-TFT beginners example project

#71 Post by MaGiK » 01 Jul 2014 14:51

Hello Megahurts :D
Megahurts wrote:Congratulations on the Degree and getting through it with a nice grade! So....it took how many days to sober up after??? Or is the party yet to come?
Glad you're back regardless.
Thank you so much for your kind words. You have no idea how much they mean to me. :D

As for the "party", unfortunately that didn't happen yet because it seems that I have to keep going to my college everyday for a range between two months -----> three just to finish the official paper work of my last achievement, so I'm not free yet :cry:
Megahurts wrote:Yea, whoop, whoop, I have a stalker finally!
I'm pretty sure you have a lot of stalkers. I'm the only one who admitted it :mrgreen:
Megahurts wrote:Seriously though, very glad to hear that you will have more free time, because I might need to borrow some of it. he,he,he. How's your math skills? Mine suck.
It would be a great honour to help out if needed. Other than going to separate offices in the university in the morning to complete the boring paper work, I'm 100% free to help out. Too bad it's concerning math though :(
Megahurts wrote:This was back when there were very few people that could write programs (before MS-DOS even) or knew how much math . a programmer was actually doing vs what math the computer was actually doing (to the non-computer science teachers, it just looked like a lot of algebra equations, even to the math teachers) so the school officials assumed that us students were
doing a lot of math and gave us credits for algebra and calculus, but I never took either of those in High School and only did a
few courses of algebra in College uhhmm... .. 30 years ago (I think that's right ).
Your case is similar to mine, but for a different subject. That's going to be drawing!
Most of the students were great with the T-square and other toys we're supposed to manually draw with except me.
However, I flipped the table around with the AutoCAD course (It's a software that allows drawing using your computer), so the teachers gave me the highest score in the overall drawing because I was simply the best MaGiKian of AutoCAD :lol:
Megahurts wrote:(self paced - 22 week long course done in 10 & 1/2 weeks).
That's why you have stalkers bro ... Being genius :shock:
Megahurts wrote:This CNC Mill project is going to kill many of my brain cells (most will suicide themselves I think), and at my age, not many to spare left in there as it is. The ones in the best shape I have left only want to play Foosball 24/7. The next group that
seems to get a large say in things just want to grab the guitar and Rock Out 24/7 (I think they are the stoners that hid while I
was in the Army, but have decided they had enough of the closet and want to go on Tour with Ozzy. (I blame Ozzy for this
dilemma, getting Black Sabbath back together at his age, shame on him )
This CNC Mill project is indeed a wunderbar project, so please be patient with it. I have a feeling that patience is the key with this one.
As for your brain cells, I'd say that you shouldn't worry. You're doing great! I think of you as an idol in that point of view because most of my teachers have stopped growing those brain cells although they're still young. Some are younger than half your age bro. So please don't worry about this. :D ... oh ... if you ever decided to upload some of your music to YouTube, please let me know.
Megahurts wrote:BTW, project code stats is now at:
18.6% RAM used; 81.4% free of 53248 bytes available.
12% ROM used; 88% free of 350207 bytes available.
Thank for the updates. They're appreciated.
Megahurts wrote:So if you do not mind, I might need to pick your brain on some math questions soon. Trying to get the basics done first so can do some testing on different motors I have.
Not exactly sure if this is my most powerful area, but if needed, then please post the issue here and I'll try to find a solution, but I gotta admit that it's not very promising unfortunately :(
Megahurts wrote:I can post the files later if you'd like to look over what is so far, after I get some food and coffee in my system and a couple of errands taken care of?
That would be very nice, but please don't think that I'm not stal ... following this if you didn't get a reply soon. It's just that this paper work is killing my soul.

Best Wishes and Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#72 Post by Megahurts » 06 Jul 2014 09:29

Hi MaGiK and everyone,

Thanks for the kind words back also.

I'm sure anyone who has recently been in collage or still in has better math skills than I have at hand, so don't be too sure that in that area you're sub-par, especially compared to mine.

I was very glad to see that you have training with CAD systems also. That area may be where you can really help out on this.
I also have some time using 3D software and have Inventor7 at my disposal, but most of my work in 3D was building Road Course Race Tracks for computer simulators/games as add-ons. No time at all with a 'Real' CNC system.

I looked up information about 'G code' and it made me want to abandon the whole idea truthfully. But I don't give up to easy on things thankfully.

If this project idea is to go full on and be something that anyone could hook up to a PC and have it follow the movement instructions from some CAD software, it will only happen if someone that knows the ins and outs of CAD systems can provide help and insight to that area.

I really would like it if it could parse G-code at some level within the limits of the machines capabilities. Even to make it do all of the drilling that a PCB designed on PCB software needs done requires this controller/interface design to have some capability
of interpreting codes for movement to have it fully automate the PCB hole drilling task.

This makes the whole project a tall ambition order to fill, and it means finding ways to simplify the GUI and its code footprint without forgoing important features, or highly desired ones I'd like it to have built in.

Right now I am working on a trick to help in that area, better control over V-TFT objects properties that uses less code than we currently have to use to get the same results in program display operations.

I'll be posting about this soon, when I get all the images and text finished for a proper understandable submission so everyone can easily grasp the concept(s).

Till then, thanks for the support and interests everyone, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#73 Post by Megahurts » 17 Jul 2014 12:30

Hi V.T.U.'s and followers of this topic,

Just a simple status update on the progress of designing a better menu buttons 'state' machine controlling routine or methods.

If you have not discovered it yet, I have another thread started that is a discussion of and example code of using pointers to
better control object properties.
It is at this thread topic in V-TFT General area:http://www.mikroe.com/forum/viewtopic.p ... 69#p241969
A lot of the development of using pointers for object and object properties control will be carried out in that thread, with the results implemented in code finalized being shown here and with detailed explanations about usage and methodology.

But in keeping with the intention to have this CNC project Open Sourced for everyone that is interested, here is complete code listing for
the projects 'events_code' file as it is at present for you to look over and analyze the methods we are trying to refine for state control over reused buttons.
It is not finished or working code at this time also, but informative with most code having explanation comments.
I just wanted for everyone to have opportunity to be up to date with its development and see what is done and needs to be done yet (a lot still).
*(At start of some comments there is this indicator [T.C.]- that means Tutorial Comments follow:)

Some code lines are commented out because they are being (have been) replaced by iteration looped indexed versions that optimize the code required to do same tasks and are left in listing here for comparisons of each solution methods.

Code: Select all

module PIC33EP_CNC_Stepper_events_code

include PIC33EP_CNC_Stepper_objects
include PIC33EP_CNC_Stepper_resources
include PIC33EP_CNC_Stepper_driver

sub procedure Circle1OnPress()
sub procedure Scrn1Btn_Menu1_ALOCK_OnClick()
sub procedure Scrn1Btn_Menu1_DRILL_OnClick()
sub procedure Scrn1Btn_Menu1_HOME_OnClick()
sub procedure Scrn1Btn_Menu1_SHAPE_OnClick()
sub procedure Scrn1Btn_Menu1_SMODE_OnClick()
sub procedure Scrn1Btn_Menu2_LIMITS_OnClick()
sub procedure Scrn1Btn_Menu2_MEASUR_OnClick()
sub procedure Scrn1Btn_MENU2_OFFSET_OnClick()
sub procedure Scrn1Btn_Menu3_EDIT_OnClick()
sub procedure Scrn1Btn_Menu3_NEXT_OnClick()
sub procedure Scrn1Btn_Menu3_PLAY_OnClick()
sub procedure Scrn1Btn_Menu3_PREV_OnClick()
sub procedure Scrn1Btn_Menu3_RECORD_OnClick()
sub procedure Scrn1Btn_Menu4_LOAD_OnClick()
sub procedure Scrn1Btn_Menu4_TOOL_OnClick()
sub procedure Scrn1Btn_Menu4_SAVREC_OnClick()
sub procedure Scrn1Btn_Menu4_SETUP_OnClick()
sub procedure Scrn1Btn_Menu4_SHUTDN_OnClick()
sub procedure Scrn1Btn_MenuCHANGE_OnClick()
sub procedure Scrn1BtnInd_MENU2_Results_OnClick()
sub procedure Scrn1BtnInd_Xaxis_OnClick()
sub procedure Scrn1BtnInd_Yaxis_OnClick()
sub procedure Scrn1BtnInd_Zaxis_OnClick()
sub procedure Scrn1BtnRnd_AxisMov_NoPress_OnUp()
sub procedure Scrn1BtnRnd_AxisMov_XLFT1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XLFT12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XLFT14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XLFT18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XRt1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XRt12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XRt14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XRt18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YDn1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YDn12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YDn14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YDn18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YUp1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YUp12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YUp14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YUp18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt18_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt1_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt12_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt14_OnPress()
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt18_OnPress()
sub procedure Scrn1BtnRnd_CUTonOFF_OnClick()
sub procedure Scrn1BtnRnd_MARK_OnClick()
sub procedure Scrn1BtnRnd_ZaxisDn12_OnPress()
sub procedure Scrn1BtnRnd_ZaxisDn14_OnPress()
sub procedure Scrn1BtnRnd_ZaxisDn18_OnPress()
sub procedure Scrn1BtnRnd_ZaxisPARK_OnClick()
sub procedure Scrn1BtnRnd_ZaxisUp12_OnPress()
sub procedure Scrn1BtnRnd_ZaxisUp14_OnPress()
sub procedure Scrn1BtnRnd_ZaxisUp18_OnPress()
sub procedure Scrn1BtnRndInd_UNITS_OnClick()
'--------------------- Externals ---------------------'
'----------------- End of Externals ------------------'

'-------------- User code declarations ---------------'

' V-TFT Driver File DrawObject Routines for Project List
' DrawScreen()
' DrawButton(@)
' DrawRoundButton(@)
' DrawCRoundButton(@)
' DrawCLabel(@)
' DrawCircle(@)
' DrawCCircle(@)
' DrawCircleButton(@)
' DrawCCircleButton(@)
' DrawCBox(@)
' DrawCRoundBox(@)
'______________________________________________________

'______________________________________________________
'dsPIC33EP MMB PORT Pins I/O Usage List (ext.connects)|
' PIN |I/O|A/D| BSP | Usage Description               |
'-----+---+---+-----+---------------------------------|
' RB2   I   D  G0.0   X-Axis Minimum Travel Limit Switch (Home)
' RB3   O   D  G0.1   X-Axis Motor MicroStep control MS1
' RB4   O   D  G0.2   Y-Axis Motor MicroStep control MS1
' RB5   O   D  G0.3   Z-Axis Motor MicroStep control MS1
' RB9   I   D  G0.4   X-Axis Maximum Travel Limit Switch
' RD6   O   D  G0.5   X-Axis Motor Driver ENABLE control
' RD7   O   D  G0.6   Y-Axis Motor Driver ENABLE control
' RD12  O   D  G0.7   Z-Axis Motor Driver ENABLE control
' RD13  I   D  G1.0   Y-Axis Minimum Travel Limit Switch (Home)
' RA14  I   D  G1.1   Y-Axis Maximum Travel Limit Switch
' RA15  I   D  G1.2   Motor Drivers ENABLED Toggle switch
' RD10  I   D  G1.3   Z-Axis Minimum Travel Limit Switch (Home)
' RC4   I   D  G1.4   Z-Axis Maximum Travel Limit Switch
' RD0          G1.5
' RB14         G1.6
' RG13         G1.7
' RG14         G2.0
' RG6          G2.1   SCK
' RG7          G2.2   SDI
' RG8          G2.3   SDO
' RF2   O   D  G2.4   X-Axis Motor STEP Control signal
' RF4   O   D  G2.5   Y-Axis Motor STEP Control signal
' RF5   O   D  G2.6   Z-Axis Motor STEP Control signal
' RF8          G2.7
' RF13         G3.0
' RA0   O   D  G3.1   X-Axis Motor MicroStep control MS2
' RA1   O   D  G3.2   X-Axis Motor Direction control
' RE8   O   D  G3.3   Y-Axis Motor MicroStep control MS2
' RE9   O   D  G3.4   Y-Axis Motor Direction control
' RD8   O   D  G3.5   Z-Axis Motor MicroStep control MS2
' RD9   O   D  G3.6   Z-Axis Motor Direction control
' RD11         G3.7
' RG0          G4.0
' RG1          G4.1
' RF0          G4.2
' RF1          G4.3
' RD3          G4.4
' RD1          G4.5
' RA2          G4.6   SCL
' RA3          G4.7   SDA
' RB0   I   A   A0    Joystick X Axis Analog ADC Input
' RB1   I   A   A1    Joystick Y Axis Analog ADC Input



' User Code Routines declaration List (only routines called from outside this module need to be listed)
sub procedure Init_Vars()

'______________________________________________________


' X,Y,Z Bipolar Stepper motor driver connections
'-----------------------------------------------

' X Axis Click board controls [WS Socket 1]
dim X_DIR    as sbit at LATA1_bit  ' WS G3.2
dim X_STEP   as sbit at LATF2_bit  ' WS G2.4
dim X_MS1    as sbit at LATB3_bit  ' WS G0.1
dim X_MS2    as sbit at LATA0_bit  ' WS G3.1
dim X_ENABLE as sbit at LATD6_bit  ' WS G0.5

dim X_DIR_Direction    as sbit at TRISA1_bit
dim X_STEP_Direction   as sbit at TRISF2_bit
dim X_MS1_Direction    as sbit at TRISB3_bit
dim X_MS2_Direction    as sbit at TRISA0_bit
dim X_ENABLE_Direction as sbit at TRISD6_bit

' Y Axis Click board controls [WS Socket 2]
dim Y_DIR    as sbit at LATE9_bit  ' WS G3.4
dim Y_STEP   as sbit at LATF4_bit  ' WS G2.5
dim Y_MS1    as sbit at LATB4_bit  ' WS G0.2
dim Y_MS2    as sbit at LATE8_bit  ' WS G3.3
dim Y_ENABLE as sbit at LATD7_bit  ' WS G0.6

dim Y_DIR_Direction    as sbit at TRISE9_bit
dim Y_STEP_Direction   as sbit at TRISF4_bit
dim Y_MS1_Direction    as sbit at TRISB4_bit
dim Y_MS2_Direction    as sbit at TRISE8_bit
dim Y_ENABLE_Direction as sbit at TRISD7_bit

' Z Axis Click board controls [WS Socket 3]
dim Z_DIR    as sbit at LATD9_bit  ' WS G3.6
dim Z_STEP   as sbit at LATF5_bit  ' WS G2.6
dim Z_MS1    as sbit at LATB5_bit  ' WS G0.3
dim Z_MS2    as sbit at LATD8_bit  ' WS G3.5
dim Z_ENABLE as sbit at LATD12_bit ' WS G0.7

dim Z_DIR_Direction    as sbit at TRISD9_bit
dim Z_STEP_Direction   as sbit at TRISF5_bit
dim Z_MS1_Direction    as sbit at TRISB5_bit
dim Z_MS2_Direction    as sbit at TRISD8_bit
dim Z_ENABLE_Direction as sbit at TRISD12_bit
'______________________________________________________

' Axis's Home/Maximum Travel Sensors Input declarations
' to be done still

'______________________________________________________


' User Code Global Variables declarations
  ' simplest type variables used for flags and state holders
dim MENU_PAGE     as byte   ' state holder for menu page selected
    STEP_MODE     as byte   ' state holder for stepping mode selected (SS,C1,C2,C3)
    PRESS_COUNT   as byte   ' flag/counter for OnPress inputs to do Single Step or count delay before continuous step start
    DISPLAY_UNITS as byte   ' state holder for the selected display units (step,inch,mm)
    ALOCK_ENABLE  as byte   ' state holder for Axis Lock function (0-off , 1-on)
    X_at_LIMIT    as bit    ' flag for X axis has reached a soft Limit boundary
    Y_at_LIMIT    as bit    ' flag for Y axis has reached a soft Limit boundary
    Z_at_LIMIT    as bit    ' flag for Z axis has reached a soft Limit boundary
    SET_X_cwDIR   as bit    ' holder of determined motor X CW rotation direction needed for proper movement
    SET_Y_cwDIR   as bit    ' holder of determined motor Y CW rotation direction needed for proper movement
    SET_Z_cwDIR   as bit    ' holder of determined motor Z CW rotation direction needed for proper movement
    SET_X_ccwDIR  as bit    ' holder of determined motor X CCW rotation direction needed for proper movement
    SET_Y_ccwDIR  as bit    ' holder of determined motor Y CCW rotation direction needed for proper movement
    SET_Z_ccwDIR  as bit    ' holder of determined motor Z CCW rotation direction needed for proper movement
    
    
  ' integer type variables used for holding values larger than 255
dim CRCL_X_POINT  as integer ' screen X coordinate for circle center (0-319)
    CRCL_Y_POINT  as integer ' screen Y coordinate for circle center (0-239)
    CRCL_R_VALUE  as integer ' screen circle radius value
    TOOL_OFFSET   as integer ' Defines diameter or radial offset used for cutter compensation
    
    
  ' float type variables used for precision calculations
dim X_STEPS       as float  '
    Y_STEPS       as float  '
    Z_STEPS       as float  '
    X_INCHES      as float  '
    Y_INCHES      as float  '
    Z_INCHES      as float  '
    X_miliMETERS  as float  '
    Y_miliMETERS  as float  '
    Z_miliMETERS  as float  '
    X_MARK        as float  '
    Y_MARK        as float  '
    Z_MARK        as float  '
    SET_INCH_CONV as float  '
    SET_MM_CONV   as float  '
        

'______________________________________________________

' User Code Global Array Variables for Shapes, Measurements, Axis Limits and Movement Recording
dim SHAPE_RECTANGLE as float[3][8][2] '[3]x[4x2-POINT(X,Y)] [CUBED(Hi/Lo Z)] RECTANGLES
    SHAPE_TRIANGLE  as float[3][6][2] '[3]x[3x2-POINT(X,Y)] [CUBED(Hi/Lo Z)] TRIANGLES
    SHAPE_CIRCLE    as float[3][3][2] '[3]x[X, Y, Radius]   [CUBED(Hi/Lo Z)] CIRCLES
    MEASURE_X       as float[3]       '[X Axis StartX, EndX, Result]
    MEASURE_Y       as float[3]       '[Y Axis StartY, EndY, Result]
    MEASURE_Z       as float[3]       '[Z Axis StartZ, EndZ, Result]
    LIMIT_X         as float[3]       '[2 X-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    LIMIT_Y         as float[3]       '[2 Y-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    LIMIT_Z         as float[3]       '[2 Z-points(Start,End), Inside(1)/Outside(0) Marked travel limits]
    MOVE_RECORD     as float[512][3]  '[512 movement points] [X-point, Y-point, Z-point]
    

'______________________________________________________

' User defined variable types declarations
typedef Str2 as string[2]   ' user type string - 2 characters length...step codes
typedef Str4 as string[4]   ' user type string - 4 characters length...units
typedef Str6 as string[6]   ' user type string - 6 characters length...menu buttons labels

'______________________________________________________

' User Code Global Constants declarations
const HALF_STEP    as float = 0.5   ' value of half a step
      QUARTR_STEP  as float = 0.25  ' value of a quarter step
      EIGHTH_STEP  as float = 0.125 ' value of an eighth of a step
      PI           as float = 3.1415' value for Pi calculations
      MOTORx_DEG   as float = 7.5   ' X-Axis motors degrees of movement per step
      MOTORy_DEG   as float = 7.5   ' Y-Axis motors degrees of movement per step
      MOTORz_DEG   as float = 7.5   ' Z-Axis motors degrees of movement per step
      Mx_ROT_STEPS as byte  = 48    ' X-Axis motors steps per revolution
      My_ROT_STEPS as byte  = 48    ' Y-Axis motors steps per revolution
      Mz_ROT_STEPS as byte  = 48    ' Z-Axis motors steps per revolution
      
      
const STEP_CODES   as Str2[4] = ("SS","C1","C2","C3") ' step mode selected indicators for
                                                      ' Scrn1CrclBtn_StepMode__Caption
const UNITS_TEXT   as Str4[3] = ("STEP","INCH"," MM ")' movement units to display

const MENU_BTNS    as TButtonPtr[5] =
 (@Scrn1Btn_MenuButton1_, @Scrn1Btn_MenuButton2_, @Scrn1Btn_MenuButton3_,
  @Scrn1Btn_MenuButton4_, @Scrn1Btn_MenuButton5_)


' Constants for screen1 Menu sets names of function buttons at bottom of screen
const MENU_SET_TXT as Str6[4][5] = (
     ("SMODE","SHAPE","ALOCK","HOME","DRILL"),    ' Menu Set 1 - index 0 :0,1,2,3,4
     ("LIMITS","OFFSET","MEASUR","",""),          ' Menu Set 2 - index 1 :0,1,2
     ("EDIT","PREV","PLAY","NEXT","RECORD"),      ' Menu Set 3 - index 2 :0,1,2,3,4
     ("SETUP","SHUTDN","TOOL","SAVREC","LOAD"))   ' Menu Set 4 - index 3 :0,1,2,3,4

const MENU_EVENTS as longword[4][5] =
  (
    (
      @Scrn1Btn_Menu1_SMODE_OnClick,
      @Scrn1Btn_Menu1_SHAPE_OnClick,
      @Scrn1Btn_Menu1_ALOCK_OnClick,
      @Scrn1Btn_Menu1_HOME_OnClick,
      @Scrn1Btn_Menu1_DRILL_OnClick
    ),
    (
      @Scrn1Btn_Menu2_LIMITS_OnClick,
      @Scrn1Btn_MENU2_OFFSET_OnClick,
      @Scrn1Btn_Menu2_MEASUR_OnClick,
      0,
      0
    ),
    (
      @Scrn1Btn_Menu3_EDIT_OnClick,
      @Scrn1Btn_Menu3_PREV_OnClick,
      @Scrn1Btn_Menu3_PLAY_OnClick,
      @Scrn1Btn_Menu3_NEXT_OnClick,
      @Scrn1Btn_Menu3_RECORD_OnClick
    ),
    (
      @Scrn1Btn_Menu4_SETUP_OnClick,
      @Scrn1Btn_Menu4_SHUTDN_OnClick,
      @Scrn1Btn_Menu4_TOOL_OnClick,
      @Scrn1Btn_Menu4_SAVREC_OnClick,
      @Scrn1Btn_Menu4_LOAD_OnClick
    )
  )


                                                     
'______________________________________________________

'----------- End of User code declarations -----------'

implements

'--------------------- User code ---------------------'
' [T.C.]- implements is the equivalent of the main files required "main:"
'  statement and it too, is also required in every projects module files.
'  Since program flow from the main file has to get here by way of a routine call
'  to one of the modules public interface declarations of routine prototypes,
'  that are actually coded in a routine below implements, program execution is
'  encapsulated to flow only within one or more routines (calls to other routines
'  in this module or other modules can be done, to a limit).
'  There is not any program instructions or statements executable outside of a
'  routines declaration and its 'end xxx' statement allowed like in the 'main:'
'  section of the main file.
'
sub procedure Init_Vars()
' Presets User Code Global Variables
' [T.C.]- Making this routine and code to Call-It (in main project file),
' first in all projects makes the Compiler include the variables and their memory
' allocations in the compilation result. Otherwise, the compiler would determine
' any declared variables not actually referenced by any code as something to eliminate
' from the program code and will not be accounted for in compiled memory usage results.
'
'  This ensures you get a better sense of the resources your User Code will be using
' as you develop the application. As you add/declare Global variables to the code,
' put an entry here to assign a preset value so project statistics are accurate
' after a successful project build. Just declaring a variable does not ensure it
' stays present and accounted for in the final build.

 dim X as word     ' local temp variables for iteration loops usage
     Y as byte     '

 MENU_PAGE     = 1
 STEP_MODE     = 0
 PRESS_COUNT   = 0
 ALOCK_ENABLE  = 1
 X_at_LIMIT    = 0
 Y_at_LIMIT    = 0
 Z_at_LIMIT    = 0
 DISPLAY_UNITS = 0
 X_STEPS       = 0
 Y_STEPS       = 0
 Z_STEPS       = 0
 SET_X_cwDIR   = 0
 SET_Y_cwDIR   = 0
 SET_Z_cwDIR   = 0
 SET_X_ccwDIR  = 1
 SET_Y_ccwDIR  = 1
 SET_Z_ccwDIR  = 1

 X_INCHES      = 0
 Y_INCHES      = 0
 Z_INCHES      = 0
 X_milIMETERS  = 0
 Y_milIMETERS  = 0
 Z_milIMETERS  = 0
 X_MARK        = 0
 Y_MARK        = 0
 Z_MARK        = 0
 SET_INCH_CONV = 0
 SET_MM_CONV   = 0
 CRCL_X_POINT  = 0
 CRCL_Y_POINT  = 0
 CRCL_R_VALUE  = 0
 TOOL_OFFSET   = 0
 

 X_DIR_Direction    = 0  ' X-Axis control pins set to output
 X_STEP_Direction   = 0
 X_MS1_Direction    = 0
 X_MS2_Direction    = 0
 X_ENABLE_Direction = 0

 Y_DIR_Direction    = 0  ' Y-Axis control pins set to output
 Y_STEP_Direction   = 0
 Y_MS1_Direction    = 0
 Y_MS2_Direction    = 0
 Y_ENABLE_Direction = 0
 
 Z_DIR_Direction    = 0  ' Z-Axis control pins set to output
 Z_STEP_Direction   = 0
 Z_MS1_Direction    = 0
 Z_MS2_Direction    = 0
 Z_ENABLE_Direction = 0
 
 X_DIR     = 0           ' Set clockwise direction
 X_STEP    = 0
 X_MS1     = 0           ' Set full step
 X_MS2     = 0           '
 X_ENABLE  = 1           ' X-Axis driver disabled
 Y_DIR     = 0           ' Set clockwise direction
 Y_STEP    = 0
 Y_MS1     = 0           ' Set full step
 Y_MS2     = 0           '
 Y_ENABLE  = 1           ' Y-Axis driver disabled
 Z_DIR     = 0           ' Set clockwise direction
 Z_STEP    = 0
 Z_MS1     = 0           ' Set full step
 Z_MS2     = 0           '
 Z_ENABLE  = 1           ' Z-Axis driver disabled

 for X = 0 to 2      ' clear X,Y,Z measurement arrays
   MEASURE_X[X] = 0
   MEASURE_Y[X] = 0
   MEASURE_Z[X] = 0
                     ' clear X,Y,Z limits arrays
   LIMIT_X[X]   = 0
   LIMIT_Y[X]   = 0
   LIMIT_Z[X]   = 0
 next X
 X = 0
 LIMIT_X[2]   = 1    ' set default enforced areas to Inside axis points
 LIMIT_Y[2]   = 1
 LIMIT_Z[2]   = 1
 
 for X = 0 to 2      ' clear the 3 rectangle shapes
   for Y = 0 to 7
     SHAPE_RECTANGLE[X][Y][0] = 0
     SHAPE_RECTANGLE[X][Y][1] = 0
   next Y
 next X
 X = 0 Y = 0
 
 for X = 0 to 2      ' clear the 3 triangle shapes
   for Y = 0 to 5
     SHAPE_TRIANGLE[X][Y][0] = 0
     SHAPE_TRIANGLE[X][Y][1] = 0
   next Y
 next X
 X = 0 Y = 0
 
 for X = 0 to 2      ' clear the 3 circle shapes
   for Y = 0 to 2
     SHAPE_CIRCLE[X][Y][0] = 0
     SHAPE_CIRCLE[X][Y][1] = 0
   next Y
 next X
 X = 0 Y = 0
 
 for X = 0 to 512
   for Y = 0 to 2
     MOVE_RECORD[X][Y] = 0
   next Y
 next X
 
 
end sub
'_____________________________________________________

' Routine to Enable Click Stepper motor driver boards
sub procedure Enable_Clicks()
  X_ENABLE = 0
  Y_ENABLE = 0
  Z_ENABLE = 0
end sub
'_____________________________________________________

' Routine to Disable Click Stepper motor driver boards
sub procedure Disable_Clicks()
  X_ENABLE = 1
  Y_ENABLE = 1
  Z_ENABLE = 1
end sub
'_____________________________________________________

' Routine to execute single step on X-Axis
sub procedure Single_Step_X()
  X_STEP = 0
  Delay_ms(3)
  X_STEP = 1
  Delay_ms(3)
end sub
'_____________________________________________________

' Routine to execute single step on Y-Axis
sub procedure Single_Step_Y()
  Y_STEP = 0
  Delay_ms(3)
  Y_STEP = 1
  Delay_ms(3)
end sub
'_____________________________________________________

' Routine to execute single step on Z-Axis
sub procedure Single_Step_Z()
  Z_STEP = 0
  Delay_ms(3)
  Z_STEP = 1
  Delay_ms(3)
end sub
'_____________________________________________________

' Routines to set X,Y,Z Axis to FULL STEP MODE
sub procedure Set_X_1step()
  X_MS1 = 0
  X_MS2 = 0
end sub

sub procedure Set_Y_1step()
  Y_MS1 = 0
  Y_MS2 = 0
end sub

sub procedure Set_Z_1step()
  Z_MS1 = 0
  Z_MS2 = 0
end sub
'_____________________________________________________

' Routines to set X,Y,Z Axis to HALF STEP MODE
sub procedure Set_X_12step()
  X_MS1 = 1
  X_MS2 = 0
end sub

sub procedure Set_Y_12step()
  Y_MS1 = 1
  Y_MS2 = 0
end sub

sub procedure Set_Z_12step()
  Z_MS1 = 1
  Z_MS2 = 0
end sub
'_____________________________________________________

' Routines to set X,Y Axis to QUARTER STEP MODE
sub procedure Set_X_14step()
  X_MS1 = 0
  X_MS2 = 1
end sub

sub procedure Set_Y_14step()
  Y_MS1 = 0
  Y_MS2 = 1
end sub

sub procedure Set_Z_14step()
  Z_MS1 = 0
  Z_MS2 = 1
end sub
'_____________________________________________________

' Routines to set X,Y Axis to EIGHTH STEP MODE
sub procedure Set_X_18step()
  X_MS1 = 1
  X_MS2 = 1
end sub

sub procedure Set_Y_18step()
  Y_MS1 = 1
  Y_MS2 = 1
end sub

sub procedure Set_Z_18step()
  Z_MS1 = 1
  Z_MS2 = 1
end sub
'_____________________________________________________
' routine to redraw the 5 screen1 function menu buttons after set change
sub procedure DrawMenu()
  DrawCBox(@Scrn1Box_BackFILLMenu)   ' totaly erase menu buttons from display
  DrawButton(@Scrn1Btn_MenuButton1_) ' redraw Menu Button 1 with current properties settings
  DrawButton(@Scrn1Btn_MenuButton2_) ' redraw Menu Button 2 with current properties settings
  DrawButton(@Scrn1Btn_MenuButton3_) ' redraw Menu Button 3 with current properties settings
  DrawButton(@Scrn1Btn_MenuButton4_) ' redraw Menu Button 4 with current properties settings
  DrawButton(@Scrn1Btn_MenuButton5_) ' redraw Menu Button 5 with current properties settings
  DrawButton(@Scrn1BtnInd_MENU2_Results_)' redraw results button indicator if set visible
  DrawButton(@Scrn1Btn_MenuCHANGE_)  ' redraw Menu change button with new caption
end sub
'_____________________________________________________



'----------------- End of User code ------------------'

' Event Handlers

'---------- Start of Screen1 Menu Navigation Button handling
sub procedure Scrn1Btn_MenuCHANGE_OnClick()
' cycles to next menu set of buttons on each press (click),
' changes the Caption Label for each button in the menu set
' changes each buttons ".OnClickPtr" reference to use a routine for current function
dim i as byte

 if (MENU_PAGE = 3) then  ' cycle to next menu or roll over to first menu
    MENU_PAGE = 0
   else
    inc(MENU_PAGE)
 end if
 
' change the 5 Menu Buttons Captions text to current menu set function labels
'  Scrn1Btn_MenuButton1__Caption = MENU_SET_TXT[MENU_PAGE][0]
'  Scrn1Btn_MenuButton2__Caption = MENU_SET_TXT[MENU_PAGE][1]
'  Scrn1Btn_MenuButton3__Caption = MENU_SET_TXT[MENU_PAGE][2]
'  Scrn1Btn_MenuButton4__Caption = MENU_SET_TXT[MENU_PAGE][3]
'  Scrn1Btn_MenuButton5__Caption = MENU_SET_TXT[MENU_PAGE][4]

  for i = 0 to 4  ' aCkO's alternate method: changes buttons captions and OnClick pointers
    strcpy(MENU_BTNS[i]^.Caption, MENU_SET_TXT[MENU_PAGE][i])
    MENU_BTNS[i]^.OnClickPtr = MENU_EVENTS[MENU_PAGE][i]
  next i

 
 select case MENU_PAGE    ' change Menu Buttons to active set and set pointers to active handlers
   case 0                 ' Menu 1 set active
     Scrn1Btn_MenuCHANGE__Caption     = "MENU 1"
'     Scrn1Btn_MenuButton1_.OnClickPtr = @Scrn1Btn_Menu1_SMODE_OnClick
'     Scrn1Btn_MenuButton2_.OnClickPtr = @Scrn1Btn_Menu1_SHAPE_OnClick
'     Scrn1Btn_MenuButton3_.OnClickPtr = @Scrn1Btn_Menu1_ALOCK_OnClick
'     Scrn1Btn_MenuButton4_.OnClickPtr = @Scrn1Btn_Menu1_HOME_OnClick
'     Scrn1Btn_MenuButton5_.OnClickPtr = @Scrn1Btn_Menu1_DRILL_OnClick
     
     if (ALOCK_ENABLE = 1) then
       Scrn1Btn_MenuButton3_.Gradient   = 0   ' ALOCK is enabled, so button is solid red
      else
       Scrn1Btn_MenuButton3_.Gradient   = 1   ' ALOCK is disabled, so button is gradient colors
     end if
     
   case 1                 ' Menu 2 set active
     Scrn1Btn_MenuCHANGE__Caption     = "MENU 2"
'     Scrn1Btn_MenuButton1_.OnClickPtr = @Scrn1Btn_Menu2_LIMITS_OnClick
'     Scrn1Btn_MenuButton2_.OnClickPtr = @Scrn1Btn_Menu2_OFFSET_OnClick
'     Scrn1Btn_MenuButton3_.OnClickPtr = @Scrn1Btn_Menu2_MEASUR_OnClick
'     Scrn1Btn_MenuButton4_.OnClickPtr = 0      ' clear function pointer - inactive button this menu set
'     Scrn1Btn_MenuButton5_.OnClickPtr = 0      ' clear function pointer - inactive button this menu set

     Scrn1Btn_MenuButton3_.Gradient        = 1 ' set gradient for button 3 to enabled
     Scrn1Btn_MenuButton4_.Visible         = 0 ' Hide Button 4
     Scrn1Btn_MenuButton4_.Active          = 0 ' disable Button 4
     Scrn1Btn_MenuButton4_.PressColEnabled = 0 ' disable Button 4 press color
     Scrn1Btn_MenuButton5_.Visible         = 0 ' Hide Button 5
     Scrn1Btn_MenuButton5_.Active          = 0 ' disable Button 5
     Scrn1Btn_MenuButton5_.PressColEnabled = 0 ' disable Button 5 press color
     
                                               ' this button replaces buttons 4&5 this menu set (double wide for display out)
     Scrn1BtnInd_MENU2_Results_.Visible    = 1 ' make visible measurments output display button
     Scrn1BtnInd_MENU2_Results_.Active     = 1 ' enable display button for touch to clear
  
   
   case 2                 ' Menu 3 set active
     Scrn1Btn_MenuCHANGE__Caption     = "MENU 3"
'     Scrn1Btn_MenuButton1_.OnClickPtr = @Scrn1Btn_Menu3_EDIT_OnClick
'     Scrn1Btn_MenuButton2_.OnClickPtr = @Scrn1Btn_Menu3_PREV_OnClick
'     Scrn1Btn_MenuButton3_.OnClickPtr = @Scrn1Btn_Menu3_PLAY_OnClick
'     Scrn1Btn_MenuButton4_.OnClickPtr = @Scrn1Btn_Menu3_NEXT_OnClick
'     Scrn1Btn_MenuButton5_.OnClickPtr = @Scrn1Btn_Menu3_RECORD_OnClick

     Scrn1Btn_MenuButton4_.Visible         = 1 ' enable and make visible buttons 4&5 again
     Scrn1Btn_MenuButton4_.Active          = 1 ' "                                       "
     Scrn1Btn_MenuButton4_.PressColEnabled = 1 ' "                                       "
     Scrn1Btn_MenuButton5_.Visible         = 1 ' "                                       "
     Scrn1Btn_MenuButton5_.Active          = 1 ' "                                       "
     Scrn1Btn_MenuButton5_.PressColEnabled = 1 ' "                                       "
     
     Scrn1BtnInd_MENU2_Results_.Visible    = 0 ' hide measurments output display button
     Scrn1BtnInd_MENU2_Results_.Active     = 0 ' disable display button for touch to clear
   
   case 3                 ' Menu 4 set active
     Scrn1Btn_MenuCHANGE__Caption     = "MENU 4"  ' change menu button caption to current set.
'     Scrn1Btn_MenuButton1_.OnClickPtr = @Scrn1Btn_Menu4_SETUP_OnClick
'     Scrn1Btn_MenuButton2_.OnClickPtr = @Scrn1Btn_Menu4_SHUTDN_OnClick
'     Scrn1Btn_MenuButton3_.OnClickPtr = @Scrn1Btn_Menu4_TOOL_OnClick
'     Scrn1Btn_MenuButton4_.OnClickPtr = @Scrn1Btn_Menu4_SAVREC_OnClick
'     Scrn1Btn_MenuButton5_.OnClickPtr = @Scrn1Btn_Menu4_LOAD_OnClick

   

 end select
 
 DrawMenu()                           ' blanks and redraws menu buttons with
                                      ' current properties settings
end sub
'---------- End of Screen1 Menu Navigation Button handling
'
'---------- Start of  S C R E E N 1  M E N U-1  Buttons handling
'Button 1"SMODE" 2"SHAPE" 3"ALOCK" 4"HOME" 5"DRILL"
sub procedure Scrn1Btn_Menu1_SMODE_OnClick()       ' Button 1

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu1_SHAPE_OnClick()       ' Button 2

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu1_ALOCK_OnClick()       ' Button 3

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu1_HOME_OnClick()        ' Button 4

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu1_DRILL_OnClick()       ' Button 5

end sub
'---------- End of Screen1 Menu-1 Buttons handling
'
'---------- Start of  S C R E E N 1  M E N U-2  Buttons handling
'Button 1"LIMITS" 2"OFFSET" 3"MEASUR" 4"Results"
sub procedure Scrn1Btn_Menu2_LIMITS_OnClick()       ' Button 1

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_MENU2_OFFSET_OnClick()       ' Button 2

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu2_MEASUR_OnClick()       ' Button 3

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnInd_MENU2_Results_OnClick()   ' Button 4

end sub
'---------- End of Screen1 Menu-2 Buttons handling
'
'---------- Start of  S C R E E N 1  M E N U-3  Buttons handling
'Button 1"EDIT" 2"PREV" 3"PLAY" 4"NEXT" 5"RECORD"
sub procedure Scrn1Btn_Menu3_PLAY_OnClick()    ' Button 1

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu3_RECORD_OnClick()  ' Button 2

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu3_EDIT_OnClick()    ' Button 3

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu3_PREV_OnClick()    ' Button 4

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu3_NEXT_OnClick()    ' Button 5

end sub
'---------- End of Screen1 Menu-3 Buttons handling
'
'---------- Start of  S C R E E N 1  M E N U-4  Buttons handling
'Button 1"SETUP" 2"SHUTDN" 3"RESET" 4"SAVREC" 5"LOAD"
sub procedure Scrn1Btn_Menu4_SETUP_OnClick()  ' Button 1

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu4_SHUTDN_OnClick() ' Button 2

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu4_TOOL_OnClick()  ' Button 3

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu4_SAVREC_OnClick() ' Button 4

end sub
'-----------------------------------------------------
sub procedure Scrn1Btn_Menu4_LOAD_OnClick()   ' Button 5

end sub
'---------- End of Screen1 Menu-4 Buttons handling
'
'---------- Start of Command Buttons Handling
sub procedure Scrn1BtnRnd_MARK_OnClick()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisPARK_OnClick()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_CUTonOFF_OnClick()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRndInd_UNITS_OnClick()

end sub
'---------- End of Command Buttons Handling
'
'---------- Start of all OnPress buttons common OnUp event handler
sub procedure Scrn1BtnRnd_AxisMov_NoPress_OnUp()
' This routine is called by any OnPress event assigned Objects that has been pressed
' but now is no longer being pressed so that tracking flags and counters can be
' reset in preperation for next time a OnPress Object is pressed.

  PRESS_COUNT = 0
  
end sub
'---------- End of all OnPress buttons common OnUp event handler
'
'---------- Start of TP freehand X,Y input press event handler
sub procedure Circle1OnPress()


end sub
'---------- End of TP freehand X,Y input press event handler
'_____________________________________________________
'---------- Start of X/Y Step move control Button Handling
sub procedure Scrn1BtnRnd_AxisMov_XLFT18_OnPress()
' move X axis motor 1/8th step
'  if ((
    if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
      PRESS_COUNT = 1
      Set_X_18step()
      X_DIR    = 1
      Single_Step_X()
    end if
  
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XRt18_OnPress()
' move X axis motor 1/8th step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_18step()
    X_DIR    = 0
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XLFT14_OnPress()
' move X axis motor 1/4 step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_14step()
    X_DIR    = 1
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XRt14_OnPress()
' move X axis motor 1/4 step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_14step()
    X_DIR    = 0
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XLFT12_OnPress()
' move X axis motor 1/2 step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_12step()
    X_DIR    = 1
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XRt12_OnPress()
' move X axis motor 1/2 step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_12step()
    X_DIR    = 0
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XLFT1_OnPress()
' move X axis motor 1 full step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_1step()
    X_DIR    = 1
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XRt1_OnPress()
' move X axis motor 1 full step
  if ((STEP_MODE = 0) and (PRESS_COUNT = 0)) then
    PRESS_COUNT = 1
    Set_X_1step()
    X_DIR    = 0
    Single_Step_X()
  end if
end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YUp18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YDn18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YUp14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YDn14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YUp12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YDn12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YUp1_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YDn1_OnPress()

end sub
'---------- End of X/Y Step move Buttons Handling
'
'---------- Start of 45deg XY Step move Buttons Handling
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYUpLFT1_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXUpRt1_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_YXDnRt1_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_AxisMov_XYDnLFT1_OnPress()

end sub
'---------- End of 45deg XY Step move Buttons Handling
'
'---------- Start of Z step move Button Handling
sub procedure Scrn1BtnRnd_ZaxisUp18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisDn18_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisUp14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisDn14_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisUp12_OnPress()

end sub
'-----------------------------------------------------
sub procedure Scrn1BtnRnd_ZaxisDn12_OnPress()

end sub
'---------- End of Z step move Button Handling







sub procedure Scrn1BtnInd_Xaxis_OnClick()

end sub


sub procedure Scrn1BtnInd_Yaxis_OnClick()

end sub

sub procedure Scrn1BtnInd_Zaxis_OnClick()

end sub



end.
As always, any comments or questions are welcomed. I hope this is informative and useful to you all, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

Megahurts
Posts: 900
Joined: 01 Oct 2009 22:48
Location: Rocky Mountains, USA.

Re: [TUTORIAL] V-TFT beginners example project

#74 Post by Megahurts » 03 Aug 2014 02:33

Hi All,

I finally got around to getting some pictures of the "Obtainium" parts and material that is to be used to make the CNC Mill.
But since there is a limit of 3 images (uploads) allowed to a post, I will start a LibStock project page and post the rest of the images and code updates there after this one.

This image is of the salvaged HP X/Y Plotter-vinyl cutter bed I will use for the transom (X,Z Axis's) that will span across the moveable base tray (Y Axis).
(no image of Y axis tray right now, still in storage.)
CNC_Mill_Parts (1).jpg
CNC_Mill_Parts (1).jpg (874.81 KiB) Viewed 14979 times
This will be mounted vertically, top of image will be the bottom edge of X axis. The spanning Z-axis slider is almost at its topmost position as shown.
All of the vinyl cutter/Pen holder parts have been removed and the metal snap on cover for protecting the steel cable and pulleys is not installed.
CNC_Mill_Parts (23).jpg
CNC_Mill_Parts (23).jpg (1 MiB) Viewed 14979 times
This image (above) shows the back side of the transom and the oil dampened flywheels on the stepper motors and the heatsinked transistors of the H-bridge motor driver PCB.
This unit uses full side to side parallel 'Push-Pull' steel cables wound on stepper winch hubs to ensure smooth accurate positioning of the two axis's sliders.
CNC_Mill_Parts (13).jpg
CNC_Mill_Parts (13).jpg (942.52 KiB) Viewed 14979 times
Here are some more of the parts to be used (if needed) to build this thing. Large chrome-molly steel slider rods like those can be gotten from
old laser printers or flatbed scanner/copiers.
The far right part (looks like upside down Y), is one of two that will be end mounts for the HP plotter bed to fix it vertically over tray bed.

Not all available parts are shown here. Will post them later in the project blog page @LibStock and will post the link for it here after it gets set up.

I promised someone :wink: some pictures on this, so glad to finally have this little job taken care of, for now. More later, Robert.
HW: easyPIC5|PICFlash2|easyBT|smartGSM|easyGSM|PICPLC16|mmWorkStation|FT800 Eve|PIC Clicker/2|
MMBs:PIC18F,PIC33EP,PIC32|CLICKs:DAC,ADC,GPS L10,Thermo,8x8B LED,Stepper,W/B OLED,9DOF,GPS3,tRF,Hall I|

SW: mP for PIC|mB for PIC-dsPIC-PIC32|Visual-TFT|

MaGiK
Posts: 897
Joined: 19 Apr 2013 10:00

Re: [TUTORIAL] V-TFT beginners example project

#75 Post by MaGiK » 04 Aug 2014 15:51

Hello dear Megahurts :D

Thank you so much for the updates and the photos.
This is surely looks promising.

Is the CNC going to have the ability to change the width of a particular track that is expected to carry a large amount of current?
Or would it be needed to go through that particular track more than once to create the required width?

Once again, thanks a lot for the photos :mrgreen:
Please keep up the hard work :D

Best Wishes and Best Regards
My hobby is collecting MikroElektronika products.
Gotta catch them all!

Post Reply

Return to “Visual TFT General”