neiam
/lambent_ex
Lambent Aether 5
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
rgbww strips: the white channel min over a list, not an integer
5318609 · Gabe Morell · 2026-11-04 21:24
Files changed
modified
lib/lambent_ex/scan/8266-7777.ex
+3
−2
@@ -388,7 +388,8 @@ defmodule LambentEx.Scan.ESP8266x7777 do
| 388 | 388 | end |
| 389 | 389 | end |
| 390 | 390 | |
| 391 | − defp rgb_shift(stream, device) do | |
| 391 | + @doc false | |
| 392 | + def rgb_shift(stream, device) do | |
| 392 | 393 | chunked = Enum.chunk_every(stream, 3) |
| 393 | 394 | |
| 394 | 395 | chunked |
@@ -398,7 +399,7 @@ defmodule LambentEx.Scan.ESP8266x7777 do
| 398 | 399 | |
| 399 | 400 | defp pixel_order("rgb"), do: fn [r, g, b] -> [g, r, b] end |
| 400 | 401 | defp pixel_order("grb"), do: fn [r, g, b] -> [r, g, b] end |
| 401 | − defp pixel_order("rgbww"), do: fn [r, g, b] -> [g, r, b, Enum.min(C.wrgb([r, g, b]), r)] end | |
| 402 | + defp pixel_order("rgbww"), do: fn [r, g, b] -> [g, r, b, Enum.min([C.wrgb([r, g, b]), r])] end | |
| 402 | 403 | defp pixel_order("rgbnw"), do: fn [r, g, b] -> [g, r, b, C.wrgb([r, g, b])] end |
| 403 | 404 | defp pixel_order("rgbcw"), do: fn [r, g, b] -> [g, r, b, Enum.min([C.wrgb([r, g, b]), b])] end |
| 404 | 405 |
added
test/lambent_ex/pixel_order_test.exs
+19
−0
@@ -0,0 +1,19 @@
| 1 | +defmodule LambentEx.PixelOrderTest do | |
| 2 | + use ExUnit.Case, async: true | |
| 3 | + | |
| 4 | + alias LambentEx.Scan.ESP8266x7777, as: Scan | |
| 5 | + | |
| 6 | + defp shift(pixels, ord), do: Scan.rgb_shift(pixels, %{"ord" => ord}) | |
| 7 | + | |
| 8 | + test "rgb strips get green first" do | |
| 9 | + assert shift([200, 100, 50], "rgb") == [100, 200, 50] | |
| 10 | + end | |
| 11 | + | |
| 12 | + test "warm white strips get a white channel, held to the red" do | |
| 13 | + assert shift([200, 100, 50, 0, 0, 0], "rgbww") == [100, 200, 50, 25, 0, 0, 0, 0] | |
| 14 | + end | |
| 15 | + | |
| 16 | + test "cool white strips get a white channel, held to the blue" do | |
| 17 | + assert shift([200, 100, 50], "rgbcw") == [100, 200, 50, 25] | |
| 18 | + end | |
| 19 | +end |
Parents: b513f30