This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How to use new datatype RGB-W
#1
Hi,

I already know how to use RGB datatype (by a little tutorial by schneider), so I can split the value to the 3 objects (Red, Green, Blue) and viceversa.

Now how I can do with RGB-white?

And I tested it on visualization but it seems to me a little confusion

Attached Files Thumbnail(s)
   
Reply
#2
What is that you want to use it for? There is dedicated dpt for it and some KNX devices support it.
------------------------------
Ctrl+F5
Reply
#3
Which browser are you using? The slider is not displayed correctly. Are you using zoom/scaling?
Reply
#4
(14.08.2020, 12:59)admin Wrote: Which browser are you using? The slider is not displayed correctly. Are you using zoom/scaling?

Chrome without any scaling... same on Firefox and Edge.

I just want to let the user to click on RGB-W icon to set it. 

On the other side I would like to update the value when I set it with a script.

That's a ordinary conversion I do with a script for a RGB:

Write to RGB
----------------

Red = bit.rshift(bit.band(value, 0xFF0000), 16)
Green = bit.rshift(bit.band(value, 0xFF00), 8)
Blue = bit.band(value, 0xFF)
 
grp.write(redGroup, Red, dt.uint8)
grp.write(greenGroup, Green, dt.uint8)
grp.write(blueGroup, Blue, dt.uint8)


Read RGB
------------

red = grp.find(redGroup)
green = grp.find(greenGroup)
blue = grp.find(blueGroup)

redHex = red.datahex
greenHex = green.datahex
blueHex = blue.datahex

RGB = lmcore.hextoint(redHex..greenHex..blueHex)

grp.update(rgbGroup, RGB)



Now how  I a can do the same with a RGB-W object, which is made up of 4 scale % objects: RED - GREEN - BLU - WHITE?

Thanks.

Peppe
Reply
#5
Hi,

Use this for 4 byte RGBW:
Code:
value = event.getvalue()

-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)

-- Merge
RGBW = R * 0x1000000 + G * 0x10000 + B * 0x100 + W
BR,

Erwin
Reply
#6
Thank you so much!

BR

Peppe
Reply
#7
(23.08.2020, 10:02)Erwin van der Zwart Wrote: Hi,

Use this for 4 byte RGBW:
Code:
value = event.getvalue()

-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)

-- Merge
RGBW = R * 0x1000000 + G * 0x10000 + B * 0x100 + W
BR,

Erwin

I think there is a little mistake in that code because the colors shown by the icon don't match both ways: splitting and merging.
Reply
#8
Hi,

Just tested it and works as it should, are you using dpt 12.600?

BR,

Erwin
Reply
#9
(25.08.2020, 10:45)Erwin van der Zwart Wrote: Hi,

Just tested it and works as it should, are you using dpt 12.600?

BR,

Erwin
yes, I do.... and I use 05.001 scale for R, G, B and W.

Maybe it depends about when both scprits are enabled, they generate a sort of loop back.

Here are my script:

EVENT SCRIPT  'mergeRGBW'


R= grp.getvalue('32/3/1')

G = grp.getvalue('32/3/2')

B= grp.getvalue('32/3/3')

W = grp.getvalue('32/3/4')


RGBW = R * 0x1000000 + G * 0x10000 + B * 0x100 + W

if RGBW ~= grp.getvalue('32/1/20') then

  grp.update('32/1/20', RGBW) --- icon address
  alert (RGBW)

end


EVENT SCRIPT 'splitRGB'


value = event.getvalue() ---- from 32/1/20  icon address

-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)

if R ~= grp.getvalue('32/3/1') then
  grp.update('32/3/1', R)
  alert®
end

if R ~= grp.getvalue('32/3/2') then
  grp.update('32/3/2', G)
  alert(G)
end
 
if R ~= grp.getvalue('32/3/3') then
  grp.update('32/3/3', B)
  alert(B)
end

if R ~= grp.getvalue('32/3/4') then
  grp.update('32/3/4', W)
  alert(W)
end


That's all.  Still, there is a visualization issue like a reattach here

Attached Files Thumbnail(s)
   
Reply
#10
See if this Custom CSS fixes the slider layout for you:
Code:
.slider-wrap {
  font-size: 0;
}
.slider-h .slider-min {
  margin-right: 9px;
}
.slider-h .slider-max {
  margin-left: 9px;
}

Add this to both of your scripts to prevent loops:
Code:
if event.sender == 'se' then
  return
end
You should also use grp.checkupdate() instead of grp.getvalue/grp.getvalue, you already have copy-paste errors where you compare R with all other components.
Reply
#11
(25.08.2020, 11:38)admin Wrote: See if this Custom CSS fixes the slider layout for you:
Code:
.slider-wrap {
  font-size: 0;
}
.slider-h .slider-min {
  margin-right: 9px;
}
.slider-h .slider-max {
  margin-left: 9px;
}

Add this to both of your scripts to prevent loops:
Code:
if event.sender == 'se' then
  return
end
You should also use grp.checkupdate() instead of grp.getvalue/grp.getvalue, you already have copy-paste errors where you compare R with all other components.


OK! Now everything is fine, thank you so much!    

Just to a better understanding: what is the core difference between grp.checkupdate, grp.getvalue and grp.update?

Thank you for everything
BR


PEPPE
Reply
#12
See Lua documentation here: https://openrb.com/docs/lua.htm#grp.checkwrite
The basic idea is to write less code by using built-in functions instead of writing more complex code, which leads to more possible errors.
Reply
#13
Hi,

I think your issue with the merge is in the 5.001 scale objects as they return 0-100 within the script engine instead of 0-255, when you split/merge a RGBW value you will have 0-255 format so you might want to use a calculation R = math.round((R * 2.55),0) before pushing it to the merge calculation (and do the same with other 3 colors)

BR,

Erwin
Reply
#14
When merging it is better to use hex values as then it is dpt independent(still  1 byte). Updated the old RGB script, not tested Smile
Code:
------------------- Configurable parameters ------------------------------------

redGroup   = '1/1/1' --- modify ether group address or name of group
greenGroup = 'LED1 Green Status' --- modify ether group address or name of group
blueGroup  = '1/1/3' --- modify ether group address or name of group
whiteGroup = '1/1/4'

rgbwGroup   = 'RGB Value' --- modify ether group address or name of group

-------------------------------------------------------------------------------


red   = grp.find(redGroup)
green = grp.find(greenGroup)
blue  = grp.find(blueGroup)
white = grp.find(whiteGroup)

RGBW = lmcore.hextoint(red.datahex..green.datahex..blue.datahex..white.datahex)

grp.write(rgbwGroup, RGBW)
------------------------------
Ctrl+F5
Reply
#15
(25.08.2020, 15:43)Erwin van der Zwart Wrote: Hi,

I think your issue with the merge is in the 5.001 scale objects as they return 0-100 within the script engine instead of 0-255, when you split/merge a RGBW value you will have 0-255 format so you might want to use a calculation R = math.round((R * 2.55),0) before pushing it to the merge calculation (and do the same with other 3 colors)

BR,

Erwin


yes, I noticed it and fixed, thanks.

Here another issue with visualization (see attached pic): what are the black spot on preset? How to avoid that?

Attached Files Thumbnail(s)
   
Reply
#16
Black spot is W value of RGBW
Reply
#17
This is the white status. Change the white value and it will have different colour
------------------------------
Ctrl+F5
Reply
#18
(26.08.2020, 08:12)Daniel. Wrote: This is the white status. Change the white value and it will have different colour
Big Grin  Ok sorry to not understood!
Reply
#19
Sorry, my script was working on the LM (firmware 20200720) in our office. 

Today I restored it on a new LM (firmware 20200727) at customers' and it doesn't work and give me the attached warning.

We are blocked now.

Can you please help me?

Thanks

Peppe

Attached Files Thumbnail(s)
       
Reply
#20
Paste the script as a code not image
------------------------------
Ctrl+F5
Reply


Forum Jump: