Hello Guest it is May 08, 2021, 07:24:51 AM

Author Topic: Mach4 screen GRAPHICS -- makin' it Purdy  (Read 28658 times)

0 Members and 1 Guest are viewing this topic.

Offline Bodini

*
  •  216 216
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #20 on: March 11, 2015, 08:33:25 AM »
I poked at it a little here.
Code: [Select]
color = scr.GetProperty('led73','Color')
wx.wxMessageBox (color)

It reported back some numbers a string as I changed the Led. Red is 0, Purple is 32, Blue is 4. If these follow some convention, tell me about it. :)


A little further info:

Oops, it actually reported back color as a string.  That can make a difference, depending on what you want to do with it.

Things such as 'Value' (whether an led is on or off) is actually a number of 0 or 1.

There is always the "type" function in Lua to check.

Code: [Select]
color = scr.GetProperty('led73','Color')
colortype = type(color)
wx.wxMessageBox (colortype)

-Nick

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #21 on: March 11, 2015, 11:52:33 AM »
I have not tried to attach code before, so hopefully this will work. [edit] OK it worked.  The attached file is the same code that is in the scroll box. I don't know which is preferable, so I did both.

With kudos to Bodini for the ides of reading out the values, I took it a bit further and made what I call a 'code fragment' for my library. This is probably all that I will ever do with LEDs because I find the other stuff more interesting to mess with.

NOTE: this code only covers the colors for LED (plus on/off for practical reasons). It will seem disjointed because I am showing multiples ways of doing things instead of making nice tidy lists. There are many other parameters that can be manipulated in the same way by simply changing the parameter name and using appropriate values. Bodini has posted a method to determine the actual values . . which may or may not match what is in the input box for the particular screen control in the Mach4 screen editor.

This is my first posting of actual code, so I'll provide a 'blurb' on how to look at it and use it for those unfamiliar with such things.

This code is shared here for anyone to use. Note that it is not a finished code intended to be 'run'. It probably would but everything would happen so fast it would not be useful.

For those who are not familiar with the Lua editor, you can step thru code one line at a time using the F11 key. It doesn't seem completely stable to me as it often will just quit for no apparent reason, but just use the dropdown menu and pick 'start debugging and then you can step thru using the F11 key. A small green triangle marks the line the interpreter is running at any given moment and when the code 'calls' a function it will jump to where that function is which may be far away from the line that calls it, but it will return to where it started after the function has finished executing.


If you want to stop 'debugging' go back to the drop down and click the obvious choice. Note that you must stop the debugging before you can edit (cut and paste).

Code: [Select]
-- Lua Code Fragment
-- © 2015 www.theCUBEstudio.com
-- color codes and usage for Mach4 screen LED


--color = scr.GetProperty('led10','Color')
--wx.wxMessageBox (color)

-- NOTE: color numbers are exponents
-- NOTE: color names red/green for LEDs is a state change that follows the On/Off state
-- NOTE: Parameter named 'Value' in an LED is the On/Off switch -- usage example below

-- Observation: The exponent value (color number) for Red/green and Yellow colors have equal delta
---------------- therefor could be used to create a 'stoplight' effect by calculating the color value
---------------- the exponent values are 0,1,and 2, so by using a default, the control value can be booleani


-- USAGE: color numbers can be imput expressly in the function -or-
--------- intuitive variables can be pre-defined - see example below  -or-
--------- color number can be calculated and then used by either method


-- SYNTAX:  scr.SetProperty('NameOfScreenControl','NameOfParameter','NewStringValue');







-- ****************** creating and loading Variables for each Color **********
--******************* (these are the actual correct values ******************

red = "0";
amber = "2";  
blue = "4";
green = "8";

nocolor = tostring(2^4); -- string value saved is "16"
purple = tostring(2^6);  -- string value saved is "32"

white = 64;   -- example using numeric value - musyt be converted to string in the screen call
yellow = 128;
-- odd duck:
green_red = "9";

-- ************************ Variables for ON and OFF

ledON = "1";  --example of storing the variable as a string
ledOFF = 0;   --can also be stored as a number
              -- see examples below for the proper syntax for each method

-- *************************

-- example usage by string variable

       scr.SetProperty('led10', 'Color', blue);
       scr.SetProperty('led10', 'Value', '1'); -- note that a string value can be created 'on the fly'
       scr.SetProperty('led10', 'Value', '0');

-- if numeric formula is pre-coverter to a string, just use the variable name

       scr.SetProperty('led10', 'Color', purple);
       scr.SetProperty('led10', 'Value', ledON);
       scr.SetProperty('led10', 'Value', tostring(ledOFF));

-- if the Color variable contains a number, it must be converted to a string in the function call

       scr.SetProperty('led10', 'Color', tostring(white));
       scr.SetProperty('led10', 'Value', '1');
       scr.SetProperty('led10', 'Value', '0');


--************************* Example using exponents

local i = 0;


for i = 0,7,1 do
--- color string value can be calculated and coverted on the fly
       scr.SetProperty('led10', 'Color', tostring(2^i));
       scr.SetProperty('led10', 'Value', '1');
       scr.SetProperty('led10', 'Value', '0');
end

--************************* stoplight example ********************

StopLightColor = "";
UserInput = 0;
-- ********************************* set up a function to change the light
function ChangeStopLight()
-- wx.wxMessageBox (tostring(UserInput));
  
  if (UserInput > 1) then
     StopLightColor = tostring(128);
  elseif (UserInput == 1) then
     StopLightColor = tostring(8);
  else
     StopLightColor = tostring(0);
  end    
   scr.SetProperty('led10', 'Color', StopLightColor);
   scr.SetProperty('led10', 'Value', '1');
end

-- ****************************** simulate user input

for i = 0,2,1 do
-- wx.wxMessageBox (tostring(i));
  scr.SetProperty('led10', 'Value','0');
  UserInput = i;  
  ChangeStopLight()
end
« Last Edit: March 11, 2015, 12:04:08 PM by simpson36 »

Offline ger21

*
  • *
  •  6,289 6,289
    • View Profile
    • The CNC Woodworker
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #22 on: March 11, 2015, 12:03:47 PM »
Thanks for sharing that.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #23 on: March 11, 2015, 12:24:46 PM »

It reported back some numbers a string as I changed the Led. Red is 0, Purple is 32, Blue is 4. If these follow some convention, tell me about it. :)


As you will see from my posting, the color 'numbers' are actually exponents, which seems a little weird at first blush, but can actually be very useful.

A caveat with Lua is that you never really know the data type because Lua changes it on the fly. I'm not very familiar with Lua yet, but it seems the only time it is really unhappy with the wrong data type being in a var is when passing the value to a function, otherwise you really need to track it back, or test it as you pointed out, to know what the heck is in there.  

Lua is sort of like "programming for people who don't like to follow rules".

I typically identify variables with a 'tail' thus IntuitivelyNamedVariable_FL or IntuitivelyNamedVariable_INT if the distinction is important and of course if the variables have the same name.

It is noteworthy that the version of Lua current implemented in MACH4 is ALL floats. I can think of zero reason to do something like that and it is a huge PIA, but apparently they have come to the same conclusion because the latest version 'introduces' the integer data type.

On the other side of that coin is that Lua does have some unconventional math functions that are rather bizarre . . .  probably as a result of having only floats to work on . . but also very useful in some cases and they left them in!

So forwarned is forearmed as they say. This is a MAJOR change and will blow large holes in most calculations (well, mine anyway), so it would be a good idea to code in such a way as to minimize the impact of the introduction of the integer data type.

« Last Edit: March 11, 2015, 12:28:54 PM by simpson36 »

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #24 on: March 11, 2015, 12:30:43 PM »
Thanks for sharing that.

No problemo. Kudos to Bodini. He provided the key.  I just opened the door. . . . ;)

Now if someone knows how to turn off the box around the buttons, I can do some very cool stuff.
« Last Edit: March 11, 2015, 12:38:42 PM by simpson36 »

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #25 on: March 11, 2015, 02:48:19 PM »
Here are some ideas for cool radio buttons and checkboxes.

Should be apparent why the button borders have to go.

No new stuff for a while. Slammed schedule as always.

Offline Bodini

*
  •  216 216
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #26 on: March 11, 2015, 03:11:15 PM »
With kudos to Bodini for the ides of reading out the values,

Phfft. Scott (poppabear) and Craig (ya-nvr-no) and bfr549 (Terry) have provided a lot more info on this stuff than I ever could.  I was just able to hone in on what you needed to hear this time. ;-)

-Nick

Offline BR549

*
  •  6,952 6,952
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #27 on: March 11, 2015, 04:02:44 PM »
For added help in screens you may want to look at WX.Smith. It is an addon to lua for screens. AND they actually have a manual and speak normal humon.

(;-)TP

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #28 on: March 11, 2015, 05:26:46 PM »
With kudos to Bodini for the ides of reading out the values,

 I was just able to hone in on what you needed to hear this time. ;-)


My point exactly.  ;)

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Mach4 screen GRAPHICS -- makin' it Purdy
« Reply #29 on: March 11, 2015, 05:31:57 PM »
For added help in screens you may want to look at WX.Smith. It is an addon to lua for screens. AND they actually have a manual and speak normal humon.

(;-)TP


This may seem like a silly question, but are the MACH4 screens actually Lua.  ???

I was assuming that the MACH screen was written in some flavor of 'C"  and that Lua was just hooked in as the scripting language.

There was no time to dig into that FormBuilder thing, but it looked like it was just a screen tool and separate from MACH.

Put another way, if something were written using WX.Smith, is there a mechanism by which to connect it or integrate it to the MACH4 screen?

Eventually I might understand how all the players fit together, buy I'm still feeling my way along the wall for the light switch at this point, so if you can shed some light on how these things fit together, it would be mucho helpful.
« Last Edit: March 11, 2015, 05:40:56 PM by simpson36 »