add web ui

This commit is contained in:
Dennis Gunia
2025-10-19 16:33:59 +02:00
parent 0557c43016
commit 21b53b52ba
7 changed files with 518 additions and 5 deletions

View File

@@ -171,6 +171,14 @@ void cmd_dm_print_single(json_object *req, json_object *res)
}
}
// clear display
void cmd_dm_clear(json_object *req, json_object *res)
{
devicemgr_clearscreen();
json_object_object_add(res, "ack", json_object_new_boolean(true));
}
// ping device
void cmd_dr_ping(json_object *req, json_object *res)
@@ -375,6 +383,11 @@ json_object *parse_command(json_object *req)
cmd_dm_print(req, res);
return res;
}
else if (strcmp(command, "dm_clear") == 0)
{
cmd_dm_clear(req, res);
return res;
}
else if (strcmp(command, "dr_ping") == 0)
{
cmd_dr_ping(req, res);

View File

@@ -90,6 +90,7 @@ int devicemgr_readStatus(int device_id)
u_int32_t _counter = 0;
u_int8_t _status =
sfbus_read_status(devices[device_id].rs485_descriptor, devices[device_id].address, &_voltage, &_counter);
if (_status == 0xFF)
{
devices[device_id].powerState = UNKNOWN;
@@ -252,16 +253,16 @@ void setSingle(int id, char flap)
{
printf("match char %i %i %i\n", test_char, *symbols[ix], ix);
sfbus_display_full(devices[id].rs485_descriptor, devices[id].address, ix);
devices[id].current_flap = ix;
break;
}
}
devices[nextFreeSlot].current_flap = flap;
}
void setSingleRaw(int id, int flap)
{
sfbus_display_full(devices[id].rs485_descriptor, devices[id].address, flap);
devices[nextFreeSlot].current_flap = flap;
devices[id].current_flap = flap;
}
void devicemgr_printText(const char *text, int x, int y)
@@ -287,6 +288,21 @@ void devicemgr_printFlap(int flap, int x, int y)
}
}
// clears complete screen
void devicemgr_clearscreen()
{
for (int ix = 0; ix < SFDEVICE_MAXDEV; ix++)
{
if (devices[ix].address > 0)
{
if (devices[ix].current_flap != 0)
{
setSingleRaw(ix, 0);
}
}
}
}
int devicemgr_register(int rs485_descriptor, u_int16_t address, int x, int y, int nid)
{
if (nid < 0)
@@ -384,7 +400,7 @@ int devicemgr_load(char *file)
do
{
char* read_ret = fgets(line_in_file, JSON_MAX_LINE_LEN, fptr); // read line from file
char *read_ret = fgets(line_in_file, JSON_MAX_LINE_LEN, fptr); // read line from file
stringlen = strlen(line_in_file);
// printf("Read line with chars: %i : %s", stringlen, line_in_file); // only for testing
jobj = json_tokener_parse_ex(tok, line_in_file, stringlen);

View File

@@ -35,4 +35,5 @@ void devicemgr_printText(const char *text, int x, int y);
void devicemgr_printFlap(int flap, int x, int y);
int devicemgr_load(char *file);
int devicemgr_load_single(json_object *device_obj);
int devicemgr_remove(int id);
int devicemgr_remove(int id);
void devicemgr_clearscreen();

View File

@@ -14,7 +14,7 @@
#include <unistd.h>
#include <wsserver/ws.h>
#define WS_SERVER_PORT 8080
#define WS_SERVER_PORT 8089
#define WS_SERVER_ADDR "localhost"
int start_webserver();