mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-04 19:25:47 +00:00
proj
This commit is contained in:
@ -205,6 +205,7 @@
|
||||
<ClCompile Include="src\driver\drv_wemo.c" />
|
||||
<ClCompile Include="src\driver\drv_uart.c" />
|
||||
<ClCompile Include="src\driver\drv_ucs1912.c" />
|
||||
<ClCompile Include="src\driver\drv_widget.c" />
|
||||
<ClCompile Include="src\hal\bk7231\hal_adc_bk7231.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
|
||||
@ -342,6 +342,7 @@
|
||||
<ClCompile Include="src\driver\drv_test_charts.c" />
|
||||
<ClCompile Include="src\sim\Controller_Switch.cpp" />
|
||||
<ClCompile Include="src\sim\Controller_DHT11.cpp" />
|
||||
<ClCompile Include="src\driver\drv_widget.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\base64\base64.h" />
|
||||
|
||||
@ -96,6 +96,7 @@ void DRV_Toggler_QuickTick();
|
||||
void DRV_InitPWMToggler();
|
||||
|
||||
void DRV_Widget_AddToHtmlPage(http_request_t *request);
|
||||
void DRV_Widget_BeforeState(http_request_t* request);
|
||||
void DRV_Widget_Init();
|
||||
|
||||
void DRV_HTTPButtons_ProcessChanges(http_request_t* request);
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
/*
|
||||
startDriver widget
|
||||
widget_create 0 0 demo1.html
|
||||
|
||||
*/
|
||||
const char *demo =
|
||||
@ -24,19 +25,80 @@ const char *demo =
|
||||
"}"
|
||||
"</script>";
|
||||
|
||||
typedef enum {
|
||||
WIDGET_STATIC,
|
||||
WIDGET_STATE,
|
||||
} WidgetLocation;
|
||||
|
||||
void DRV_Widget_AddToHtmlPage(http_request_t *request) {
|
||||
poststr(request, demo);
|
||||
typedef struct widget_s {
|
||||
char *fname;
|
||||
WidgetLocation location;
|
||||
char *cached;
|
||||
byte bAllowCache;
|
||||
struct widget_s *next;
|
||||
} widget_t;
|
||||
|
||||
widget_t *g_widgets = 0;
|
||||
|
||||
void DRV_Widget_Display(http_request_t *request, widget_t *w) {
|
||||
// fast path - cached
|
||||
if (w->cached) {
|
||||
poststr(request, w->cached);
|
||||
return;
|
||||
}
|
||||
char *data = (char*)LFS_ReadFile(w->fname);
|
||||
if (data == 0) {
|
||||
return;
|
||||
}
|
||||
poststr(request, data);
|
||||
|
||||
if (w->bAllowCache) {
|
||||
w->cached = data;
|
||||
return;
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
void DRV_Widget_DisplayList(http_request_t* request, WidgetLocation loc) {
|
||||
widget_t *w = g_widgets;
|
||||
while (w) {
|
||||
if (w->location == loc) {
|
||||
DRV_Widget_Display(request, w);
|
||||
}
|
||||
w = w->next;
|
||||
}
|
||||
}
|
||||
void DRV_Widget_BeforeState(http_request_t* request) {
|
||||
DRV_Widget_DisplayList(request, WIDGET_STATIC);
|
||||
}
|
||||
|
||||
void DRV_Widget_AddToHtmlPage(http_request_t *request) {
|
||||
DRV_Widget_DisplayList(request, WIDGET_STATE);
|
||||
}
|
||||
void Widget_Add(widget_t **first, widget_t *n) {
|
||||
if (*first == 0) {
|
||||
*first = n;
|
||||
}
|
||||
else {
|
||||
widget_t *tmp = *first;
|
||||
while (tmp->next) {
|
||||
tmp = tmp->next;
|
||||
}
|
||||
tmp->next = n;
|
||||
}
|
||||
}
|
||||
static commandResult_t CMD_Widget_Create(const void *context, const char *cmd, const char *args, int flags) {
|
||||
Tokenizer_TokenizeString(args, TOKENIZER_ALLOW_QUOTES);
|
||||
|
||||
if(Tokenizer_GetArgsCount()<=1) {
|
||||
if(Tokenizer_GetArgsCount()<3) {
|
||||
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
|
||||
}
|
||||
const char *fname = Tokenizer_GetArg(0);
|
||||
|
||||
widget_t *n = malloc(sizeof(widget_t));
|
||||
memset(n, 0, sizeof(widget_t));
|
||||
n->location = Tokenizer_GetArgInteger(0);
|
||||
n->bAllowCache = Tokenizer_GetArgInteger(1);
|
||||
const char *fname = Tokenizer_GetArg(2);
|
||||
n->fname = strdup(fname);
|
||||
Widget_Add(&g_widgets, n);
|
||||
return CMD_RES_OK;
|
||||
}
|
||||
void DRV_Widget_Init() {
|
||||
|
||||
@ -312,6 +312,13 @@ int http_fn_index(http_request_t* request) {
|
||||
MAIN_ScheduleUnsafeInit(3);
|
||||
}
|
||||
poststr(request, "</div>"); // end div#change
|
||||
|
||||
|
||||
#if defined(ENABLE_DRIVER_WIDGET)
|
||||
if (DRV_IsRunning("Widget")) {
|
||||
DRV_Widget_BeforeState(request);
|
||||
}
|
||||
#endif
|
||||
poststr(request, "<div id=\"state\">"); // replaceable content follows
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user