mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-04 20:45:32 +00:00
al;low empty entries in led remap (#1789)
* test * some verification * ha disc?
This commit is contained in:
@ -25,8 +25,7 @@ void BP1658CJ_Write(float *rgbcw) {
|
||||
|
||||
for(i = 0; i < 5; i++){
|
||||
// convert 0-255 to 0-1023
|
||||
//cur_col_10[i] = rgbcw[g_cfg.ledRemap.ar[i]] * 4;
|
||||
cur_col_10[i] = MAP(rgbcw[g_cfg.ledRemap.ar[i]], 0, 255.0f, 0, 1023.0f);
|
||||
cur_col_10[i] = MAP(GetRGBCW(rgbcw, g_cfg.ledRemap.ar[i]), 0, 255.0f, 0, 1023.0f);
|
||||
}
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_CMD, "Writing to Lamp (hex): #%02X%02X%02X%02X%02X", cur_col_10[0], cur_col_10[1], cur_col_10[2], cur_col_10[3], cur_col_10[4]);
|
||||
// If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate BP1658CJ's sleep mode ([0x80] ).
|
||||
|
||||
@ -97,10 +97,15 @@ void BP5758D_Write(float *rgbcw) {
|
||||
for(i = 0; i < 5; i++){
|
||||
// convert 0-255 to 0-1023
|
||||
//cur_col_10[i] = rgbcw[g_cfg.ledRemap.ar[i]] * 4;
|
||||
cur_col_10[i] = MAP(rgbcw[g_cfg.ledRemap.ar[i]], 0, 255.0f, 0, 1023.0f);
|
||||
cur_col_10[i] = MAP(GetRGBCW(rgbcw, g_cfg.ledRemap.ar[i]), 0, 255.0f, 0, 1023.0f);
|
||||
|
||||
}
|
||||
|
||||
#if WINDOWS
|
||||
void Simulator_StoreBP5758DColor(unsigned short *data);
|
||||
Simulator_StoreBP5758DColor(cur_col_10);
|
||||
#endif
|
||||
|
||||
// If we receive 0 for all channels, we'll assume that the lightbulb is off, and activate BP5758d's sleep mode.
|
||||
if (cur_col_10[0]==0 && cur_col_10[1]==0 && cur_col_10[2]==0 && cur_col_10[3]==0 && cur_col_10[4]==0) {
|
||||
bIsSleeping = true;
|
||||
|
||||
@ -64,7 +64,7 @@ void KP18058_Write(float *rgbcw) {
|
||||
Soft_I2C_WriteByte(&g_softI2C, byte2);
|
||||
Soft_I2C_WriteByte(&g_softI2C, byte3);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
float useVal = rgbcw[g_cfg.ledRemap.ar[i]];
|
||||
float useVal = GetRGBCW(rgbcw, g_cfg.ledRemap.ar[i]);
|
||||
unsigned short cur_col_10 = MAP(useVal, 0, 255.0f, 0, 1023.0f);
|
||||
byte a, b;
|
||||
a = cur_col_10 & 0x1F;
|
||||
|
||||
@ -40,6 +40,8 @@ void PT6523_ClearString();
|
||||
void TS_RunQuickTick();
|
||||
void TS_Init();
|
||||
|
||||
float GetRGBCW(float *ar, int index);
|
||||
|
||||
void SM2135_Init();
|
||||
|
||||
void SM2235_Init();
|
||||
|
||||
@ -16,6 +16,12 @@ static softI2C_t g_softI2C;
|
||||
static int g_current_setting_cw = SM2135_20MA;
|
||||
static int g_current_setting_rgb = SM2135_20MA;
|
||||
|
||||
float GetRGBCW(float *ar, int index) {
|
||||
if (index < 0 || index >= 5) {
|
||||
return 0;
|
||||
}
|
||||
return ar[index];
|
||||
}
|
||||
void SM2135_Write(float *rgbcw) {
|
||||
int i;
|
||||
int bRGB;
|
||||
@ -24,7 +30,7 @@ void SM2135_Write(float *rgbcw) {
|
||||
if(CFG_HasFlag(OBK_FLAG_SM2135_SEPARATE_MODES)) {
|
||||
bRGB = 0;
|
||||
for(i = 0; i < 3; i++){
|
||||
if(rgbcw[g_cfg.ledRemap.ar[i]]!=0) {
|
||||
if(GetRGBCW(rgbcw,g_cfg.ledRemap.ar[i])!=0) {
|
||||
bRGB = 1;
|
||||
break;
|
||||
}
|
||||
@ -33,9 +39,9 @@ void SM2135_Write(float *rgbcw) {
|
||||
Soft_I2C_Start(&g_softI2C, SM2135_ADDR_MC);
|
||||
Soft_I2C_WriteByte(&g_softI2C, combinedCurrent);
|
||||
Soft_I2C_WriteByte(&g_softI2C, SM2135_RGB);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.r]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.g]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.b]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.r));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.g));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.b));
|
||||
Soft_I2C_Stop(&g_softI2C);
|
||||
} else {
|
||||
Soft_I2C_Start(&g_softI2C, SM2135_ADDR_MC);
|
||||
@ -45,8 +51,8 @@ void SM2135_Write(float *rgbcw) {
|
||||
usleep(SM2135_DELAY);
|
||||
|
||||
Soft_I2C_Start(&g_softI2C, SM2135_ADDR_C);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.c]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.w]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.c));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.w));
|
||||
Soft_I2C_Stop(&g_softI2C);
|
||||
|
||||
}
|
||||
@ -54,11 +60,11 @@ void SM2135_Write(float *rgbcw) {
|
||||
Soft_I2C_Start(&g_softI2C, SM2135_ADDR_MC);
|
||||
Soft_I2C_WriteByte(&g_softI2C, combinedCurrent);
|
||||
Soft_I2C_WriteByte(&g_softI2C, SM2135_RGB);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.r]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.g]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.b]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.c]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, rgbcw[g_cfg.ledRemap.w]);
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.r));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.g));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.b));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.c));
|
||||
Soft_I2C_WriteByte(&g_softI2C, GetRGBCW(rgbcw,g_cfg.ledRemap.w));
|
||||
Soft_I2C_Stop(&g_softI2C);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ void SM2235_Write(float *rgbcw) {
|
||||
for (i = 0; i < 5; i++) {
|
||||
// convert 0-255 to 0-1023
|
||||
//cur_col_10[i] = rgbcw[g_cfg.ledRemap.ar[i]] * 4;
|
||||
cur_col_10[i] = MAP(rgbcw[g_cfg.ledRemap.ar[i]], 0, 255.0f, 0, 1023.0f);
|
||||
cur_col_10[i] = MAP(GetRGBCW(rgbcw,g_cfg.ledRemap.ar[i]), 0, 255.0f, 0, 1023.0f);
|
||||
}
|
||||
|
||||
#define SM2235_FIRST_BYTE(x) ((x >> 8) & 0xFF)
|
||||
|
||||
@ -230,15 +230,6 @@ int http_fn_index(http_request_t* request) {
|
||||
if (DRV_IsRunning("SM16703P")) {
|
||||
bForceShowRGB = true;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if ENABLE_LED_BASIC
|
||||
if (LED_IsLedDriverChipRunning()) {
|
||||
bForceShowRGBCW = true;
|
||||
}
|
||||
#else
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
http_setup(request, httpMimeTypeHTML); //Add mimetype regardless of the request
|
||||
@ -670,7 +661,8 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_LED_BASIC
|
||||
if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB || bForceShowSingleDimmer) {
|
||||
if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB
|
||||
|| bForceShowSingleDimmer || LED_IsLedDriverChipRunning()) {
|
||||
int c_pwms;
|
||||
int lm;
|
||||
int c_realPwms = 0;
|
||||
@ -683,6 +675,9 @@ int http_fn_index(http_request_t* request) {
|
||||
// into high power 3-outputs single colors LED controller
|
||||
PIN_get_Relay_PWM_Count(0, &c_pwms, 0);
|
||||
c_realPwms = c_pwms;
|
||||
if (LED_IsLedDriverChipRunning()) {
|
||||
c_pwms = CFG_CountLEDRemapChannels();
|
||||
}
|
||||
if (bForceShowSingleDimmer) {
|
||||
c_pwms = 1;
|
||||
}
|
||||
@ -1901,7 +1896,10 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
|
||||
|
||||
#if ENABLE_LED_BASIC
|
||||
if (pwmCount == 5 || ledDriverChipRunning || (pwmCount == 4 && CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB))) {
|
||||
if (ledDriverChipRunning) {
|
||||
pwmCount = CFG_CountLEDRemapChannels();
|
||||
}
|
||||
if (pwmCount == 5 || (pwmCount == 4 && CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB))) {
|
||||
if (dev_info == NULL) {
|
||||
dev_info = hass_init_light_device_info(LIGHT_RGBCW);
|
||||
}
|
||||
|
||||
@ -313,6 +313,12 @@ void Test_LEDDriver_Palette() {
|
||||
CMD_ExecuteCommand("SPC 0 FF00FF", 0);
|
||||
|
||||
}
|
||||
unsigned short sim_smChannels[5];
|
||||
void Simulator_StoreBP5758DColor(unsigned short *data) {
|
||||
memcpy(sim_smChannels, data, sizeof(sim_smChannels));
|
||||
}
|
||||
|
||||
#define SELFTEST_ASSERT_SM_CHANNELS(a, b, c, d, e) SELFTEST_ASSERT(sim_smChannels[0] == a && sim_smChannels[1] == b && sim_smChannels[2] == c && sim_smChannels[3] == d && sim_smChannels[4] == e);
|
||||
|
||||
void Test_LEDDriver_RGBCW() {
|
||||
// reset whole device
|
||||
@ -555,8 +561,29 @@ void Test_LEDDriver_BP5758_RGBCW() {
|
||||
SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED Temperature Slider");
|
||||
|
||||
CMD_ExecuteCommand("StartDriver BP5758D", 0);
|
||||
CMD_ExecuteCommand("LED_Map 0 1 2 3 4", 0);
|
||||
CMD_ExecuteCommand("led_dimmer 100", 0);
|
||||
CMD_ExecuteCommand("led_temperature 500", 0);
|
||||
CMD_ExecuteCommand("led_basecolor_rgb FF0000", 0);
|
||||
|
||||
CMD_ExecuteCommand("led_enableAll 1", 0);
|
||||
// set RED - FF0000 , remap 0 to 0 -> 1023 (10 bit resolution)
|
||||
SELFTEST_ASSERT_SM_CHANNELS(1023, 0, 0, 0, 0);
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 4 1 2 3 0", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 0", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 1", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023);
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 1 4 2 3 0", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 0", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 1", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023);
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 1 0 2 3 4", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 0", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 1", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 1023, 0, 0, 0);
|
||||
|
||||
Test_FakeHTTPClientPacket_GET("index");
|
||||
SELFTEST_ASSERT_HTML_REPLY_CONTAINS("LED RGB Color");
|
||||
@ -589,8 +616,44 @@ void Test_LEDDriver_BP5758_RGBCW() {
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[4] == 2);
|
||||
|
||||
Test_FakeHTTPClientPacket_GET("index");
|
||||
//SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED RGB Color");
|
||||
SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED RGB Color");
|
||||
SELFTEST_ASSERT_HTML_REPLY_CONTAINS("LED Temperature Slider");
|
||||
|
||||
CMD_ExecuteCommand("LED_Map -1 -1 -1 3 4", 0);
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[0] == 0xff);
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[1] == 0xff);
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[2] == 0xff);
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[3] == 3);
|
||||
SELFTEST_ASSERT(g_cfg.ledRemap.ar[4] == 4);
|
||||
|
||||
CMD_ExecuteCommand("led_temperature 500", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 1", 0);
|
||||
CMD_ExecuteCommand("led_enableAll 1", 1);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 0, 1023);
|
||||
CMD_ExecuteCommand("led_temperature 154", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 0, 0, 1023, 0);
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 3 4 -1 -1 -1", 0);
|
||||
CMD_ExecuteCommand("led_temperature 500", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(0, 1023, 0, 0, 0);
|
||||
CMD_ExecuteCommand("led_temperature 154", 0);
|
||||
SELFTEST_ASSERT_SM_CHANNELS(1023, 0, 0, 0, 0);
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 0 1 2 -1 -1", 0);
|
||||
Test_FakeHTTPClientPacket_GET("index");
|
||||
SELFTEST_ASSERT_HTML_REPLY_CONTAINS("LED RGB Color");
|
||||
SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED Temperature Slider");
|
||||
|
||||
CMD_ExecuteCommand("LED_Map 0 1 2 3 4", 0);
|
||||
Test_FakeHTTPClientPacket_GET("index");
|
||||
SELFTEST_ASSERT_HTML_REPLY_CONTAINS("LED RGB Color");
|
||||
SELFTEST_ASSERT_HTML_REPLY_CONTAINS("LED Temperature Slider");
|
||||
|
||||
// absurd but still supported - single color
|
||||
CMD_ExecuteCommand("LED_Map 0 -1 -1 -1 -1", 0);
|
||||
Test_FakeHTTPClientPacket_GET("index");
|
||||
SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED RGB Color");
|
||||
SELFTEST_ASSERT_HTML_REPLY_NOT_CONTAINS("LED Temperature Slider");
|
||||
}
|
||||
void Test_LEDDriver_RGB(int firstChannel) {
|
||||
// reset whole device
|
||||
|
||||
Reference in New Issue
Block a user