RGB/RGBW split/combine

RGB/RGBW split/combine #

Split RGB (3 bytes) into 3x 1 byte objects #

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'

rgb = event.getvalue()

red = bit.band(rgb / 0x10000, 0xFF)
green = bit.band(rgb / 0x100, 0xFF)
blue = bit.band(rgb, 0xFF)

grp.write(red_group, red, dt.uint8)
grp.write(green_group, green, dt.uint8)
grp.write(blue_group, blue, dt.uint8)

Combine 3x 1 byte objects into RGB (3 bytes) #

rgb_group = '0/3/1'

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'

red = grp.getvalue(red_group)
green = grp.getvalue(green_group)
blue = grp.getvalue(blue_group)

rgb = red * 0x10000 + green * 0x100 + blue
grp.update(rgb_group, rgb)

Split RGBW (4 bytes) into 4x 1 byte objects #

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'
white_group = '0/3/9'

rgbw = event.getvalue()

red = bit.band(rgbw / 0x1000000, 0xFF)
green = bit.band(rgbw / 0x10000, 0xFF)
blue = bit.band(rgbw / 0x100, 0xFF)
white = bit.band(rgbw, 0xFF)

grp.write(red_group, red, dt.uint8)
grp.write(green_group, green, dt.uint8)
grp.write(blue_group, blue, dt.uint8)
grp.write(white_group, white, dt.uint8)

Combine 4x 1 byte objects into RGBW (4 bytes) #

rgbw_group = '0/3/1'

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'
white_group = '0/3/9'

red = grp.getvalue(red_group)
green = grp.getvalue(green_group)
blue = grp.getvalue(blue_group)
white = grp.getvalue(white_group)

rgbw = red * 0x1000000 + green * 0x10000 + blue * 0x100 + white
grp.update(rgbw_group, rgbw)

Split DALI RGBW (6 bytes) into 4x 1 byte objects #

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'
white_group = '0/3/9'

rgbw = event.getvalue()

grp.write(red_group, rgbw.red or 0, dt.uint8)
grp.write(green_group, rgbw.green or 0, dt.uint8)
grp.write(blue_group, rgbw.blue or 0, dt.uint8)
grp.write(white_group, rgbw.white or 0, dt.uint8)

Combine 4x 1 byte objects into DALI RGBW (6 bytes) #

In this example R/G/B/W objects have 05.001 scale data type.

rgbw_group = '0/3/1'

red_group = '0/3/6'
green_group = '0/3/7'
blue_group = '0/3/8'
white_group = '0/3/9'

function getvalue(group)
  local val = grp.getvalue(group)
  return math.round(val * 2.55)
end

rgbw = {
  red = getvalue(red_group),
  green = getvalue(green_group),
  blue = getvalue(blue_group),
  white = getvalue(white_group),
}

grp.update(rgbw_group, rgbw)