diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj index e699b26a9..80902ed2d 100644 --- a/openBeken_win32_mvsc2017.vcxproj +++ b/openBeken_win32_mvsc2017.vcxproj @@ -351,6 +351,7 @@ + diff --git a/openBeken_win32_mvsc2017.vcxproj.filters b/openBeken_win32_mvsc2017.vcxproj.filters index 280344411..c7f235b82 100644 --- a/openBeken_win32_mvsc2017.vcxproj.filters +++ b/openBeken_win32_mvsc2017.vcxproj.filters @@ -334,6 +334,7 @@ + diff --git a/src/driver/drv_drawers.c b/src/driver/drv_drawers.c new file mode 100644 index 000000000..eeb24a405 --- /dev/null +++ b/src/driver/drv_drawers.c @@ -0,0 +1,167 @@ +#include "../new_common.h" +#include "../new_pins.h" +#include "../new_cfg.h" +// Commands register, execution API and cmd tokenizer +#include "../cmnds/cmd_public.h" +#include "../mqtt/new_mqtt.h" +#include "../logging/logging.h" +#include "drv_local.h" +#include "drv_uart.h" +#include "../httpserver/new_http.h" +#include "../hal/hal_pins.h" +#include "../quicktick.h" + +#define SPLIT_COLOR(x) (x >> 16) & 0xFF,(x >> 8) & 0xFF,x & 0xFF + +static int *g_timeOuts = 0; +static int g_numLEDs = 0; +static int g_on_color = 8900331; +static int g_off_color = 0; +static int g_on_timeout_ms; +static int g_changes = 0; +static bool g_bEnableAmbient = 0; +static int g_ambient_color = 0xFF0000; + +// http://127.0.0.1/led_index?params=5 +static int DR_LedIndex(http_request_t* request) { + char tmp[8]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedIndex: missing params\n"); + return 0; + } + int index = atoi(tmp); + g_timeOuts[index] = g_on_timeout_ms; +#if ENABLE_DRIVER_SM16703P + SM16703P_setPixel(index, SPLIT_COLOR(g_on_color)); +#endif + g_changes++; + return 0; +} +static void applyAmbient() { + int c = 0; + if (g_bEnableAmbient) { + c = g_ambient_color; + } + g_changes++; + for (int i = 0; i < g_numLEDs; i++) { +#if ENABLE_DRIVER_SM16703P + SM16703P_setPixel(i, SPLIT_COLOR(c)); +#endif + } +} +static int DR_LedEnableAmbient(http_request_t* request) { + char tmp[16]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedEnableAmbient: missing params\n"); + return 0; + } + g_bEnableAmbient = atoi(tmp); + applyAmbient(); + return 0; +} +static int DR_LedAmbientColor(http_request_t* request) { + char tmp[16]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedAmbientColor: missing params\n"); + return 0; + } + g_ambient_color = atoi(tmp); + applyAmbient(); + return 0; +} +static int DR_LedOnColor(http_request_t* request) { + char tmp[16]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedOnColor: missing params\n"); + return 0; + } + g_on_color = atoi(tmp); + return 0; +} +static int DR_LedOffColor(http_request_t* request) { + char tmp[16]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedOffColor: missing params\n"); + return 0; + } + g_off_color = atoi(tmp); + return 0; +} +static int DR_LedOnTimeout(http_request_t* request) { + char tmp[16]; + if (!http_getArg(request->url, "params", tmp, sizeof(tmp))) { + ADDLOG_INFO(LOG_FEATURE_CMD, "DR_LedOnTimeout: missing params\n"); + return 0; + } + g_on_timeout_ms = atoi(tmp); + return 0; +} +void Drawers_Init() { + + /* + // Usage: + startDriver SM16703P + SM16703P_Init 60 + // All arguments are optional + // startDriver Drawers [NumLEDs] [TimeoutMS] [OnColor] [OffColor] [AmbientColor] + startDriver Drawers 60 2000 0x00FF00 + + */ + g_numLEDs = Tokenizer_GetArgIntegerDefault(1, 128); + g_on_timeout_ms = Tokenizer_GetArgIntegerDefault(2, 1000); + g_on_color = Tokenizer_GetArgIntegerDefault(3, 8900331); + g_off_color = Tokenizer_GetArgIntegerDefault(4, 0); + g_ambient_color = Tokenizer_GetArgIntegerDefault(5, 0); + + if (g_timeOuts) { + free(g_timeOuts); + } + g_timeOuts = (int*)malloc(sizeof(int)*g_numLEDs); + + // turns on the LED + HTTP_RegisterCallback("/led_index", HTTP_GET, DR_LedIndex, 1); + HTTP_RegisterCallback("/led_index", HTTP_POST, DR_LedIndex, 1); + // sets the LED on color for all LEDs + HTTP_RegisterCallback("/led_on_color", HTTP_GET, DR_LedOnColor, 1); + HTTP_RegisterCallback("/led_on_color", HTTP_POST, DR_LedOnColor, 1); + // sets the LED off color for all LEDs + HTTP_RegisterCallback("/led_off_color", HTTP_GET, DR_LedOffColor, 1); + HTTP_RegisterCallback("/led_off_color", HTTP_POST, DR_LedOffColor, 1); + // sets the LED on timeout for all LEDs + HTTP_RegisterCallback("/led_on_timeout", HTTP_GET, DR_LedOnTimeout, 1); + HTTP_RegisterCallback("/led_on_timeout", HTTP_POST, DR_LedOnTimeout, 1); + // + HTTP_RegisterCallback("/enable_ambient", HTTP_GET, DR_LedEnableAmbient, 1); + HTTP_RegisterCallback("/enable_ambient", HTTP_POST, DR_LedEnableAmbient, 1); + // sets the LED on color for all LEDs + HTTP_RegisterCallback("/led_ambient", HTTP_GET, DR_LedAmbientColor, 1); + HTTP_RegisterCallback("/led_ambient", HTTP_POST, DR_LedAmbientColor, 1); + +} + +void Drawers_QuickTick() { + //SM16703P_setAllPixels(SPLIT_COLOR(g_on_color)); + + for (int i = 0; i < g_numLEDs; i++) { + if (g_timeOuts[i] > 0) { + g_timeOuts[i] -= g_deltaTimeMS; + if (g_timeOuts[i] <= 0) { +#if ENABLE_DRIVER_SM16703P + SM16703P_setPixel(i,SPLIT_COLOR(g_off_color)); +#endif + g_timeOuts[i] = 0; + g_changes++; + } + } + } + if (g_changes) { +#if ENABLE_DRIVER_SM16703P + SM16703P_Show(); +#else + ADDLOG_INFO(LOG_FEATURE_CMD, "ERROR! Drawers driver requires SM16703P\n"); +#endif + g_changes = 0; + } +} + + diff --git a/src/driver/drv_local.h b/src/driver/drv_local.h index d79de456c..f256b2f08 100644 --- a/src/driver/drv_local.h +++ b/src/driver/drv_local.h @@ -154,6 +154,10 @@ void PixelAnim_Init(); void PixelAnim_SetAnimQuickTick(); void PixelAnim_SetAnim(int j); +void Drawers_Init(); +void Drawers_QuickTick(); + + #define SM2135_DELAY 4 // Software I2C diff --git a/src/driver/drv_main.c b/src/driver/drv_main.c index fb81ea35b..155bab06f 100644 --- a/src/driver/drv_main.c +++ b/src/driver/drv_main.c @@ -56,6 +56,13 @@ static driver_t g_drivers[] = { //drvdetail:"requires":""} { "PixelAnim", PixelAnim_Init, NULL, NULL, PixelAnim_SetAnimQuickTick, NULL, NULL, false }, #endif +#if ENABLE_DRIVER_DRAWERS + //drvdetail:{"name":"Drawers", + //drvdetail:"title":"TODO", + //drvdetail:"descr":"Drawers", + //drvdetail:"requires":""} + { "Drawers", Drawers_Init, NULL, NULL, Drawers_QuickTick, NULL, NULL, false }, +#endif #if ENABLE_NTP //drvdetail:{"name":"NTP", diff --git a/src/obk_config.h b/src/obk_config.h index b83d9cd32..ab64f7278 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -62,8 +62,9 @@ #define ENABLE_EXPAND_CONSTANT 1 #define ENABLE_DRIVER_DHT 1 #define ENABLE_DRIVER_SM16703P 1 -#define ENABLE_DRIVER_PIXELANIM 1 -#define ENABLE_DRIVER_TMGN 1 +//#define ENABLE_DRIVER_PIXELANIM 1 +//#define ENABLE_DRIVER_TMGN 1 +//#define ENABLE_DRIVER_DRAWERS 1 #elif PLATFORM_BL602 @@ -119,6 +120,7 @@ #define ENABLE_EXPAND_CONSTANT 1 #define ENABLE_DRIVER_DHT 1 //#define ENABLE_DRIVER_AHT2X 1 +#define ENABLE_DRIVER_DRAWERS 1 #elif PLATFORM_LN882H