Files
ninlight-w600/test/test_board.c
T
Michael SauerandClaude Opus 5 7a5f26d717 fix(board): Farbtemperaturbereiche der Weiss-Varianten korrigieren
Die vier reinen Weiss-Lampen standen flach auf 2500-6500 K, was fuer keine
von ihnen stimmte. Nach Michaels Produktdaten:

- E27 CW/WW, E14 CW/WW, GU10 CW/WW: 2700-6500 K (vorher 2500-5000)
- G95 Vintage:                      2000-5000 K (vorher 2500-5000)

Die drei erstgenannten haben damit oben 1500 K verschenkt, die G95 unten
500 K. Die RGB-Varianten und das EVK standen schon richtig auf 2700-6500.

test_board.c prueft die Bereiche jetzt pro Board statt ueber die Faustregel
"RGB oder nicht" - die G95 ist die Ausnahme, und eine Faustregel, die eine
Ausnahme hat, ist keine. Die beiden Clamp-Tests in test_boot_state.c lesen
die Obergrenze jetzt vom Board, statt die Zahl zu wiederholen: sie pruefen
das Begrenzen, nicht die Konstante.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 21:28:33 +02:00

120 lines
4.4 KiB
C

#include <string.h>
#include "unity.h"
#include "board/nl_board.h"
void setUp(void) {}
void tearDown(void) {}
static const char *IDS[] = {"evk", "e27_rgb", "e14_rgb", "gu10_rgb", "e27_cw", "e14_cw", "gu10_cw", "g95_cw"};
static void test_all_devices_present(void)
{
TEST_ASSERT_EQUAL_UINT(8, nl_boards_count);
for (size_t i = 0; i < 8; i++) {
const nl_board_t *b = nl_board_find(IDS[i]);
TEST_ASSERT_NOT_NULL_MESSAGE(b, IDS[i]);
TEST_ASSERT_EQUAL_STRING(IDS[i], b->id);
TEST_ASSERT_NOT_NULL(b->name);
}
}
static void test_unknown_is_null(void)
{
TEST_ASSERT_NULL(nl_board_find("e27"));
TEST_ASSERT_NULL(nl_board_find(""));
}
static void test_rgb_flags_and_ct_ranges(void)
{
for (size_t i = 0; i < nl_boards_count; i++) {
const nl_board_t *b = &nl_boards[i];
bool rgb = strstr(b->id, "rgb") != NULL || strcmp(b->id, "evk") == 0;
/* Measured on real bulbs, 2026-09-13: every lamp but the G95 covers 2700..6500 K.
The G95 Vintage is a warm bulb and reaches 2000 K at the bottom but stops at
5000 K - hard-coded per board rather than derived, because "warm variant" is a
property of that one product, not of a class of them. */
bool g95 = strcmp(b->id, "g95_cw") == 0;
TEST_ASSERT_EQUAL_MESSAGE(rgb, b->has_rgb, b->id);
TEST_ASSERT_EQUAL_UINT16_MESSAGE(g95 ? 2000 : 2700, b->ct_min, b->id);
TEST_ASSERT_EQUAL_UINT16_MESSAGE(g95 ? 5000 : 6500, b->ct_max, b->id);
}
}
static void test_pwm_boards_consistent(void)
{
for (size_t i = 0; i < nl_boards_count; i++) {
const nl_board_t *b = &nl_boards[i];
if (b->driver != NL_DRV_PWM)
continue;
TEST_ASSERT_TRUE(b->pwm_freq_hz > 0);
TEST_ASSERT_TRUE(b->pwm[NL_CH_CW].pwm_ch >= 0);
TEST_ASSERT_TRUE(b->pwm[NL_CH_WW].pwm_ch >= 0);
for (int c = NL_CH_R; c <= NL_CH_B; c++)
TEST_ASSERT_EQUAL_MESSAGE(b->has_rgb, b->pwm[c].pwm_ch >= 0, b->id);
for (int c = 0; c < NL_CH_COUNT; c++) {
if (b->pwm[c].pwm_ch < 0)
continue;
TEST_ASSERT_TRUE(b->pwm[c].pwm_ch <= 4);
for (int d = c + 1; d < NL_CH_COUNT; d++) {
if (b->pwm[d].pwm_ch < 0)
continue;
TEST_ASSERT_NOT_EQUAL(b->pwm[c].pwm_ch, b->pwm[d].pwm_ch);
TEST_ASSERT_NOT_EQUAL(b->pwm[c].pin, b->pwm[d].pin);
}
}
}
}
static void test_sm_boards_consistent(void)
{
for (size_t i = 0; i < nl_boards_count; i++) {
const nl_board_t *b = &nl_boards[i];
if (b->driver != NL_DRV_SM2135EH)
continue;
TEST_ASSERT_TRUE(b->has_rgb);
TEST_ASSERT_NOT_EQUAL(NL_PIN_NONE, b->sm_clk_pin);
TEST_ASSERT_NOT_EQUAL(NL_PIN_NONE, b->sm_dat_pin);
TEST_ASSERT_NOT_EQUAL(b->sm_clk_pin, b->sm_dat_pin);
TEST_ASSERT_NOT_EQUAL(0, b->sm_current);
}
}
static void test_known_values_from_old_firmware(void)
{
const nl_board_t *evk = nl_board_find("evk");
TEST_ASSERT_EQUAL(NL_DRV_PWM, evk->driver);
TEST_ASSERT_EQUAL_UINT32(5000, evk->pwm_freq_hz);
TEST_ASSERT_EQUAL_INT8(0, evk->pwm[NL_CH_R].pwm_ch);
TEST_ASSERT_EQUAL_UINT8(NL_PB(18), evk->pwm[NL_CH_R].pin);
TEST_ASSERT_TRUE(evk->pwm[NL_CH_R].active_low);
const nl_board_t *e27 = nl_board_find("e27_rgb");
TEST_ASSERT_EQUAL(NL_DRV_SM2135EH, e27->driver);
TEST_ASSERT_EQUAL_UINT8(NL_PB(13), e27->sm_clk_pin);
TEST_ASSERT_EQUAL_UINT8(NL_PB(8), e27->sm_dat_pin);
TEST_ASSERT_EQUAL_HEX8(0x17, e27->sm_current);
TEST_ASSERT_EQUAL_HEX8(0x73, nl_board_find("e14_rgb")->sm_current);
TEST_ASSERT_EQUAL_HEX8(0x63, nl_board_find("gu10_rgb")->sm_current);
const nl_board_t *e27cw = nl_board_find("e27_cw");
TEST_ASSERT_TRUE(e27cw->pwm[NL_CH_CW].antiphase);
TEST_ASSERT_EQUAL_UINT8(NL_PB(13), e27cw->pwm[NL_CH_CW].pin);
TEST_ASSERT_EQUAL_UINT32(600, e27cw->pwm_freq_hz);
const nl_board_t *g95 = nl_board_find("g95_cw");
TEST_ASSERT_EQUAL_UINT8(NL_PB(15), g95->pwm[NL_CH_WW].pin);
TEST_ASSERT_EQUAL_INT8(3, g95->pwm[NL_CH_WW].pwm_ch);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_all_devices_present);
RUN_TEST(test_unknown_is_null);
RUN_TEST(test_rgb_flags_and_ct_ranges);
RUN_TEST(test_pwm_boards_consistent);
RUN_TEST(test_sm_boards_consistent);
RUN_TEST(test_known_values_from_old_firmware);
return UNITY_END();
}