From 69121fb2529246a2ff2de50a4b4866e8f90ddbf9 Mon Sep 17 00:00:00 2001
From: openshwprojects <85486843+openshwprojects@users.noreply.github.com>
Date: Mon, 30 Jun 2025 21:56:13 +0200
Subject: [PATCH] merge gosund sw2 port (not clear if it will be used)
---
openBeken_win32_mvsc2017.vcxproj | 1 +
openBeken_win32_mvsc2017.vcxproj.filters | 2 +
src/cmnds/cmd_newLEDDriver.c | 5 +++
src/driver/drv_gosundSW2.c | 56 ++++++++++++++++++++++++
src/driver/drv_local.h | 3 ++
src/driver/drv_main.c | 8 ++++
src/driver/drv_public.h | 1 +
src/httpserver/http_fns.c | 13 +++++-
8 files changed, 87 insertions(+), 2 deletions(-)
create mode 100644 src/driver/drv_gosundSW2.c
diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj
index 9dda10f44..cdfcb65f6 100644
--- a/openBeken_win32_mvsc2017.vcxproj
+++ b/openBeken_win32_mvsc2017.vcxproj
@@ -221,6 +221,7 @@
+
diff --git a/openBeken_win32_mvsc2017.vcxproj.filters b/openBeken_win32_mvsc2017.vcxproj.filters
index 44723e4db..45d068fd3 100644
--- a/openBeken_win32_mvsc2017.vcxproj.filters
+++ b/openBeken_win32_mvsc2017.vcxproj.filters
@@ -399,6 +399,8 @@
+
+
diff --git a/src/cmnds/cmd_newLEDDriver.c b/src/cmnds/cmd_newLEDDriver.c
index a383a1ce6..32a5a69f3 100644
--- a/src/cmnds/cmd_newLEDDriver.c
+++ b/src/cmnds/cmd_newLEDDriver.c
@@ -248,6 +248,11 @@ void LED_ApplyEmulatedCool(int firstChannelIndex, float chVal) {
}
void LED_I2CDriver_WriteRGBCW(float* finalRGBCW) {
+#ifdef ENABLE_DRIVER_GOSUNDSW2
+ if (DRV_IsRunning("GosundSW2")) {
+ DRV_GosundSW2_Write(finalRGBCW)
+ }
+#endif
#ifdef ENABLE_DRIVER_LED
if (CFG_HasFlag(OBK_FLAG_LED_EMULATE_COOL_WITH_RGB)) {
if (g_lightMode == Light_Temperature) {
diff --git a/src/driver/drv_gosundSW2.c b/src/driver/drv_gosundSW2.c
new file mode 100644
index 000000000..f8e2d47d3
--- /dev/null
+++ b/src/driver/drv_gosundSW2.c
@@ -0,0 +1,56 @@
+// based on info from here:
+// https://www.elektroda.com/rtvforum/viewtopic.php?p=21593497#21593497
+#include "../obk_config.h"
+
+
+
+#if ENABLE_DRIVER_GOSUNDSW2
+
+#include
+#include
+
+#include "drv_local.h"
+#include "../logging/logging.h"
+#include "../new_cfg.h"
+#include "../new_pins.h"
+#include "../cmnds/cmd_public.h"
+#include "drv_uart.h"
+
+#define SW2_BAUDRATE 9600
+
+void DRV_GosundSW2_RunFrame() {
+ if (UART_GetDataSize() >= 5) {
+ char buff[5];
+ for (int i = 0; i < 5; i++) {
+ buff[i] = UART_GetByte(i);
+ }
+ UART_ConsumeBytes(5);
+ float dimmerVal = buff[1] / 100.0;
+
+ }
+
+}
+void DRV_GosundSW2_Write(float* finalRGBCW) {
+
+ float state = finalRGBCW[0];
+
+ uint8_t dimmerVal = 0;
+
+ if (state > 0.0)
+ {
+ dimmerVal = (127.0 * state) + 0.5;
+ dimmerVal |= 0x80; /* Bit 7 seems to control the relay */
+ }
+
+ addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "Writing dimmer value %02X", dimmerVal);
+ UART_SendByte(dimmerVal);
+}
+// startDriver GosundSW2
+// backlog clearConfig; startDriver GosundSW2
+void DRV_GosundSW2_Init() {
+ UART_InitUART(SW2_BAUDRATE, 0, false);
+ UART_InitReceiveRingBuffer(256);
+}
+
+
+#endif
diff --git a/src/driver/drv_local.h b/src/driver/drv_local.h
index aa17c2c6a..d529d555d 100644
--- a/src/driver/drv_local.h
+++ b/src/driver/drv_local.h
@@ -52,6 +52,9 @@ void KP18058_Init();
void SM15155E_Init();
+void DRV_GosundSW2_Init();
+void DRV_GosundSW2_RunFrame();
+
void SM16703P_Init();
void SM16703P_setPixel(int pixel, int r, int g, int b);
void SM16703P_setPixelWithBrig(int pixel, int r, int g, int b);
diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c
index 23e5c6145..2344f50d8 100644
--- a/src/driver/drv_main.c
+++ b/src/driver/drv_main.c
@@ -82,6 +82,14 @@ static driver_t g_drivers[] = {
+#if ENABLE_DRIVER_GOSUNDSW2
+ //drvdetail:{"name":"GosundSW",
+ //drvdetail:"title":"TODO",
+ //drvdetail:"descr":"GosundSW2.",
+ //drvdetail:"requires":""}
+ { "GosundSW2", DRV_GosundSW2_Init, NULL, NULL, DRV_GosundSW2_RunFrame, NULL, NULL, false },
+#endif
+
#if ENABLE_DRIVER_TCL
{ "TCL", TCL_Init, TCL_UART_RunEverySecond, TCL_AppendInformationToHTTPIndexPage, NULL, NULL, NULL, TCL_DoDiscovery, false },
#endif
diff --git a/src/driver/drv_public.h b/src/driver/drv_public.h
index dc6057afe..c8f8c7369 100644
--- a/src/driver/drv_public.h
+++ b/src/driver/drv_public.h
@@ -64,6 +64,7 @@ void DRV_OnChannelChanged(int channel, int iVal);
#if PLATFORM_BK7231N
void SM16703P_setMultiplePixel(uint32_t pixel, uint8_t *data, bool push);
#endif
+void DRV_GosundSW2_Write(float* rgbcw);
void SM2135_Write(float* rgbcw);
void BP5758D_Write(float* rgbcw);
void BP1658CJ_Write(float* rgbcw);
diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c
index acde85a4f..6fd719655 100644
--- a/src/httpserver/http_fns.c
+++ b/src/httpserver/http_fns.c
@@ -654,8 +654,14 @@ int http_fn_index(http_request_t* request) {
}
}
+ bool bForceShowSingleDimmer = 0;
+#if ENABLE_DRIVER_GOSUNDSW2
+ if (DRV_IsRunning("GosundSW2")) {
+ bForceShowSingleDimmer = 1;
+ }
+#endif
#if ENABLE_LED_BASIC
- if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB) {
+ if (bRawPWMs == 0 || bForceShowRGBCW || bForceShowRGB || bForceShowSingleDimmer) {
int c_pwms;
int lm;
int c_realPwms = 0;
@@ -668,7 +674,10 @@ 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 (bForceShowRGBCW) {
+ if (bForceShowSingleDimmer) {
+ c_pwms = 1;
+ }
+ else if (bForceShowRGBCW) {
c_pwms = 5;
}
else if (bForceShowRGB) {