From 7495c7032275b4dfa5a7d7f98d17be1e30ee0751 Mon Sep 17 00:00:00 2001 From: Tester23 <85486843+openshwprojects@users.noreply.github.com> Date: Tue, 28 Jan 2025 04:56:25 +0100 Subject: [PATCH] f div 1000 type --- src/httpserver/http_fns.c | 5 +++++ src/new_pins.c | 4 ++++ src/new_pins.h | 7 +++++++ src/selftest/selftest_tuyaMCU.c | 8 ++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 2e2616ac2..10daf28c3 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -2034,6 +2034,11 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { dev_info = hass_init_sensor_device_info(FREQUENCY_SENSOR, i, 3, 2, 1); } break; + case ChType_Frequency_div1000: + { + dev_info = hass_init_sensor_device_info(FREQUENCY_SENSOR, i, 4, 3, 1); + } + break; case ChType_Frequency_div10: { dev_info = hass_init_sensor_device_info(FREQUENCY_SENSOR, i, 3, 1, 1); diff --git a/src/new_pins.c b/src/new_pins.c index 79253af52..3c469ab93 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -1171,6 +1171,7 @@ int ChannelType_GetDivider(int type) { case ChType_Current_div1000: case ChType_LeakageCurrent_div1000: case ChType_ReadOnly_div1000: + case ChType_Frequency_div1000: return 1000; case ChType_Temperature_div2: return 2; @@ -1198,6 +1199,7 @@ const char *ChannelType_GetUnit(int type) { return "W"; case ChType_Frequency_div10: case ChType_Frequency_div100: + case ChType_Frequency_div1000: return "Hz"; case ChType_LeakageCurrent_div1000: case ChType_Current_div1000: @@ -1248,6 +1250,7 @@ const char *ChannelType_GetTitle(int type) { return "Power"; case ChType_Frequency_div10: case ChType_Frequency_div100: + case ChType_Frequency_div1000: return "Frequency"; case ChType_Current_div1000: case ChType_Current_div100: @@ -2128,6 +2131,7 @@ const char* g_channelTypeNames[] = { "Orp", "Tds", "Motion_n", + "Frequency_div1000", "error", "error", }; diff --git a/src/new_pins.h b/src/new_pins.h index 3511a3418..f29cb15c7 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -980,6 +980,13 @@ typedef enum channelType_e { //chandetail:"file":"new_pins.h", //chandetail:"driver":""} ChType_Motion_n, + //chandetail:{"name":"Frequency_div1000", + //chandetail:"title":"TODO", + //chandetail:"descr":"For TuyaMCU power metering. Not used for BL09** and CSE** sensors. Divider is used by TuyaMCU, because TuyaMCU sends always values as integers so we have to divide them before displaying on UI", + //chandetail:"enum":"ChType_Frequency_div1000", + //chandetail:"file":"new_pins.h", + //chandetail:"driver":""} + ChType_Frequency_div1000, //chandetail:{"name":"Max", //chandetail:"title":"TODO", //chandetail:"descr":"This is the current total number of available channel types.", diff --git a/src/selftest/selftest_tuyaMCU.c b/src/selftest/selftest_tuyaMCU.c index d3d61a288..03a77084e 100644 --- a/src/selftest/selftest_tuyaMCU.c +++ b/src/selftest/selftest_tuyaMCU.c @@ -625,13 +625,17 @@ void Test_TuyaMCU_Basic() { SELFTEST_ASSERT_CHANNEL(7, 302);// current SELFTEST_ASSERT_CHANNEL(9, 67); // power + + CMD_ExecuteCommand("linkTuyaMCUOutputToChannel 115 RAW_VCPPfF", 0); + CMD_ExecuteCommand("uartFakeHex 55 AA 03 07 00 13 73 00 00 0F 09 0F 00 00 BF 00 00 78 00 00 25 01 10 C3 32 18 ", 0); + // above command will just put into buffer - need at least a frame to parse it + Sim_RunFrames(100, false); + CMD_ExecuteCommand("linkTuyaMCUOutputToChannel 113 RAW_VCPPfF", 0); CMD_ExecuteCommand("uartFakeHex 55 AA 03 07 00 13 71 00 00 0F 09 29 00 01 B7 00 03 FC 00 00 00 03 E8 C3 32 65", 0); // above command will just put into buffer - need at least a frame to parse it Sim_RunFrames(100, false); - - SIM_ClearUART(); }