PDA

View Full Version : Send Slider value to G5?



VicVonDoom
September 14th, 2008, 05:48 PM
is it possible to send a slider value thats setting a netremote variable (& displaying it in nr) then sending that value to a girder to be registered for use within girder (bear with me...)

The reason i ask is i would like to use a slider (min 0, max 255, start 0) have its current value displayed on my touchscreen and on release, insert that value in the middle of a sendserial comms string......

am i going about it all wrong? perhaps i should be setting a girder value & reading that back into netremote - therefore not tying up the netremote variables...?

VicVonDoom
September 18th, 2008, 02:05 PM
not drunk anymore.

I gots four sliders named RGBRed RGBGreen RGBBlue RGBDimmer and have edited the nr lua as follows....



function OnCCFLoad()
NetRemote.RegisterVariableWatch('RGBRed',NetRemote .GetPlugin('Girder'))
NetRemote.RegisterVariableWatch('RGBGreen',NetRemo te.GetPlugin('Girder'))
NetRemote.RegisterVariableWatch('RGBBlue',NetRemot e.GetPlugin('Girder'))
NetRemote.RegisterVariableWatch('RGBDimmer',NetRem ote.GetPlugin('Girder'))
end

This allows girder to have them appear in the log with the value as payload 3 (i think i'm right so far....)

i then made a girder scripting action to make a table using the following...

RGBValues = {Red={RGBRed}, Green={RGBGreen}, Blue={RGBBlue}, Dimmer={RGBDimmer}}

Question is, how do i go about putting the value of payload 3 from the logger into the table & am i on the right track as i'm not sure what to search for......

Much obliged for any help :)

Rob H
September 19th, 2008, 04:58 AM
You'd just want to create your table as


RGBValues = {Red = 0, Green = 0, Blue = 0, Dimmer = 0)

Then for e.g. the RGBRed event you'd have a Lua scripting action that does


RGBValues.Red = pld3

And similarly for the others.

VicVonDoom
September 19th, 2008, 02:15 PM
Ta very much, thats exactly what i'm after!!!

I also stuck this into the event lua (i liketo see things change...)


RGBValues.Red = pld3
RGBValues.RGBHexValues.HRed = math.decimaltohex(RGBValues.Red)

How do i go about making another variable with the results of the four converted to hex sliders? I been playing with tostring, but i'm not sure how to seperate the values and end up with the first result only...?!

Rob H
September 19th, 2008, 02:30 PM
Not sure I understand what you're asking for here

VicVonDoom
September 19th, 2008, 02:35 PM
make a Girder string with the values of RGBValues.RGBHexValues.HRed,
RGBValues.RGBHexValues.HBlue, RGBValues.RGBHexValues.HGreen, RGBValues.RGBHexValues.HDimmer.......?

Rob H
September 19th, 2008, 03:29 PM
I'd suggest using string.format() for that - you can even bypass converting it to hex - assuming the values are byte-sized you could do something like


string.format('%02x %02x %02x %02x', RGBValues.Red, RGBValues.Green, RGBValues.Blue, RGBValues.Dimmer)

Actually if you're going to do that you should change the event handling actions to do things like


RGBValues.Red = tonumber(pld3)

since I'm not sure that usual numerical conversion rules apply to string.format().

BTW if the values won't fit into a byte i.e. more than 255 you could change the %02x into %04x

VicVonDoom
September 19th, 2008, 03:47 PM
i swear to god i tried that over the past couple of days!

(well nearly...)


JIMTEST = string.format(%X, RGBValues.RGBHexValues.HRed, RGBValues.RGBHexValues.HGreen, RGBValues.RGBHexValues.HBlue, RGBValues.RGBHexValues.HDimmer)

My trouble is i forget as quick i read........ Learning takes even longer ;)
Thanks again Rob!

VicVonDoom
September 19th, 2008, 04:05 PM
just tried it & got FF FF FF FF from this...

string.format('%02x %02x %02x %02x', RGBValues.Red, RGBValues.Green, RGBValues.Blue, RGBValues.Dimmer)

changd it to this.....

string.format('%2x %2x %2x %2x', RGBValues.Red, RGBValues.Green, RGBValues.Blue, RGBValues.Dimmer)

works a treat!

VicVonDoom
September 22nd, 2008, 04:01 AM
ok,

so far i've managed to concoct a VERY rough gml with the sliders loading into a string named [RGBValues.RGBHexValues.RGBhex2] as follows....

"initalise & address (allways the same) RedValue GreenValue BlueValue DimmerValue" as follows...

"CA 00 00 00 00 05 7E 04 FF 00 00 64"


How do i get this string value to fire out the comport? (i've done the script to get the comport open & attached to the unit)

I've tried send serial action - But i'm not sure if you can put a variable value, i.e. the compiled string [RGBValues.RGBHexValues.RGBhex2] into it???

Is this possible?
Many thanks.....

Rob H
September 22nd, 2008, 04:19 AM
That should be okay, but it depends on the format of the string you're sending.

For testing I'd recommend setting the log level to 0, ie Log All Send/Receive.

For the best level of control it would be better to do all this in Lua ie have a method in your serial device that takes four parameters e.g.


SendRGBD = function(self, R, G, B, D)

Then you'd just use


device:SendRGBD(RGBValues.Red, RGBValues.Green, RGBValues.Blue, RGBValues.Dimmer)

VicVonDoom
September 22nd, 2008, 04:54 AM
cheers rob, point noted. However, i'm new to all this programming stuff and have to see cause/effect of my actions how & why its doing what its doing (or not, in my case ;))

i've put the two variables into the sendserial box as

[RGBValues.RGBHexValues.Init][RGBValues.RGBHexValues.RGBhex2]

this should out Hex as...

CA00000000027E12019588CA00000000057E04FFFFFF64csum spaced accordinally

The last two bytes "csum" is a checksum, but thats a ho nother kettle o fish....
Fancy lending a hand...?

Rob H
September 22nd, 2008, 10:12 AM
Do you have details of the protocol used? That would definitely help.

VicVonDoom
September 22nd, 2008, 10:33 AM
yessir,

i have it on authority that it uses modbus crc16
if you stick CA00000000057E040000FF64 into http://www.lammertbies.nl/comm/info/crc-calculation.html the result is the checksum..... works ok with all the values i've been trying anyway...

more precise protocol details are here (http://www.xeroflex.com/Usp3_com.pdf)

there's also a dll (http://www.chromoflex.com/test_dll.zip) and source (http://www.chromoflex.com/test_src.zip) but i have no idea what to do with them & was trying to keep it all within girder for simpletons sake ;)

Thanks again Rob, i know you guys are pulling your hair out with other stuff at the moment.....

VicVonDoom
September 22nd, 2008, 01:41 PM
I've run portmonitor & thought these might help:

CA 00 00 00 00 05 7E 04 FF 00 00 64 7A E0
CA 00 00 00 00 05 7E 04 00 FF 00 64 5E E0
CA 00 00 00 00 05 7E 04 00 00 FF 64 9E 91
CA 00 00 00 00 05 7E 04 FF 60 00 64 64 E0
CA 00 00 00 00 05 7E 04 FF FF 00 64 4A D0
CA 00 00 00 00 05 7E 04 00 FF 90 64 5E 8C
CA 00 00 00 00 05 7E 04 00 FF FF 64 AE A1
CA 00 00 00 00 05 7E 04 FF 00 FF 64 8A A1

VicVonDoom
September 24th, 2008, 11:31 AM
i've only just noticed that the info i gave you is not strictly true ;)

CA 00 00 00 00 05 7E 04 FF 00 00 64 7A E0

the 64 is the dimmer level, but it works like this....


set RGB to max and dimmer to 100% bright = FFFFFF64
set RGB to MID and dimmer to 50% bright = 7F7F7F32 not FFFFFF32 as you would expect.

i've got this to calculate out ok, so now the whole string needs to have this CRC thing done on it to get the finalised comms string ready to fire.....

So close.........

VicVonDoom
September 25th, 2008, 05:16 AM
:) :) WOOOOHOOOOO :) :)

got it working!

i borrowed some old code from another post to calculate the two checksums and then added these to the strings.

now if i change any of the four sliders, girder calculates & fires out the the serial commands to the unit......sweet.

now to tidy it up a little - thanks for the pointers rob!

Rob H
September 25th, 2008, 07:02 AM
Great! You are remembering to escape the CA and CB bytes after you calculate the CRC aren't you?

VicVonDoom
September 25th, 2008, 03:28 PM
if you really want to bore yourself - take a look at it fitted & working http://uk.youtube.com/watch?v=mO1Y11OsiCU

Cheers, Jim

Rob H
September 25th, 2008, 03:55 PM
Nice.

What are the RGB LED fittings you used?

VicVonDoom
September 25th, 2008, 04:13 PM
www.hiline-lighting.com sticky backed flexible strip, 5m for 100ish (12v reel on full power pulls less than 2amp)

Rob H
September 25th, 2008, 04:44 PM
Thanks, that's not a bad price at all - looks fairly bright from the video - was that just one strip?

VicVonDoom
September 25th, 2008, 05:16 PM
about 4m. uk sellers charge 40ish/m !!!

next on the list is wire it through that audon relay card to get 'zones' of lighting..... gotta get out more.....

Lihualee
September 29th, 2008, 08:50 AM
bump up ..