Hello Guest it is April 10, 2024, 05:27:43 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - simpson36

151
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.

152

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.


153
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

154
Idea . . .

How about instead of boring check box, a push button? Same control, but lookin' good?

Mo' better . . .

How about a toggle switch?

Actual toggle switch? Oh yeah! Looks real? Oh yeah - a photo of a real switch . . Moves?  . .  oh yeah  . . Handle lights up?  . . Oh YEAH.    ;D

 I already have the transparency part (alpha channel) working . . . just need to get rid of the button outline as it looks a bit stupid just popping up out of nowhere.  :-\

155
Wouldn't cascading checkboxes be more fun?

Check . .

    Are you sure ? . . . .

      But are you REALLY sure? . . . .

       Is that Really REALLY SURE? . . .

        Do you have a note from your MOTHER? . . . .

 ::)

OK, just say how they should work and I'll see if I can make them up . . .  :(



156
OK, time for some more fun. Checkboxes . .  I'm on it!

Somebody just say how they are supposed to work  . . and look.

Do you just want a Boolean?  . . can do . . but it just seems so . .  minimalist . . .  ;)

157
I poked at it a little here.
Code: [Select]
color = scr.GetProperty('led73','Color')
wx.wxMessageBox (color)

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

You are wise, Obi-Wan!   :-*

That was the ticket. Reading out the codes was brilliant! Use those values and Bada-Bingg!  The colors change!

One big cookie for the man with the flag (the 'made in USA flag')


158
The Down and Dirty shows the use of scr.*********xx

Been there done that.

In the LuaCalls.txt document there are no functions that even contain the word 'prop'.

So not sure what to look for from here . . .

159
No joy.

Just to clarify, the 'Color' property is not working. Some of the others do work so I suspect this is just a dead ant.

ON/OFF and position work. It's sort of fun to make the thing jump all over the screen, but not particularly useful   :)

On the other hand, the 'hidden' property has no effect so jumping the LED into oblivion and back may be a workaround for making it 'disappear'.

In another thread, it was stated that some or the scr.********* command have been replaced by mc.*********, but so far I cannot find any mc.*********xx functions that even have the word 'prop' on them. I'll keep on tinkering . . . 

160
I'm not at a computer right now, by try (tostring('VALUE') on the value you want to pass.
Damn phone, damn Tapatalk... (tostring('VALUE')) is what I meant.

No problem, got that. I'll give it a try.