* drawers draft

* test

* support post as well

* Update drv_drawers.c

* ambient

* add led_ambient

* foolproof compile

* disable drivers before merge
This commit is contained in:
openshwprojects
2024-05-14 10:41:33 +02:00
committed by GitHub
parent c80dac111f
commit 7a7ad1eba0
6 changed files with 184 additions and 2 deletions

View File

@ -351,6 +351,7 @@
<ClCompile Include="src\driver\drv_dht.c" />
<ClCompile Include="src\driver\drv_dht_internal.c" />
<ClCompile Include="src\driver\drv_doorSensorWithDeepSleep.c" />
<ClCompile Include="src\driver\drv_drawers.c" />
<ClCompile Include="src\driver\drv_freeze.c" />
<ClCompile Include="src\driver\drv_gn6932.c" />
<ClCompile Include="src\driver\drv_hd2015.c" />

View File

@ -334,6 +334,7 @@
<ClCompile Include="src\driver\drv_pixelAnim.c" />
<ClCompile Include="src\driver\drv_hd2015.c" />
<ClCompile Include="src\selftest\selftest_doorSensor.c" />
<ClCompile Include="src\driver\drv_drawers.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\base64\base64.h" />

167
src/driver/drv_drawers.c Normal file
View File

@ -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;
}
}

View File

@ -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

View File

@ -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",

View File

@ -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