mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-25 00:26:54 +01:00
reorganize, allow setting start value from web panel part 1
This commit is contained in:
@@ -1175,6 +1175,7 @@ int http_fn_cfg(http_request_t *request) {
|
||||
poststr(request,g_header);
|
||||
poststr(request,"<form action=\"cfg_pins\"><input type=\"submit\" value=\"Configure Module\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_generic\"><input type=\"submit\" value=\"Configure General\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_startup\"><input type=\"submit\" value=\"Configure Startup\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_quick\"><input type=\"submit\" value=\"Quick Config\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_wifi\"><input type=\"submit\" value=\"Configure WiFi\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_mqtt\"><input type=\"submit\" value=\"Configure MQTT\"/></form>");
|
||||
@@ -1372,6 +1373,66 @@ int http_fn_cfg_generic(http_request_t *request) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
int http_fn_cfg_startup(http_request_t *request) {
|
||||
int iChanged = 0;
|
||||
int iChangedRequested = 0;
|
||||
int channelIndex;
|
||||
int newValue;
|
||||
int i;
|
||||
char tmpA[128];
|
||||
char tmpB[64];
|
||||
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request,htmlHeader);
|
||||
poststr(request,g_header);
|
||||
|
||||
hprintf128(request,"<h5>Here you can set pin start values<h5>");
|
||||
hprintf128(request,"<h5>For relays, simply use 1 or 0</h5>");
|
||||
//hprintf128(request,"<h5>For 'remember last power state', use -1 as a special value</h5>");
|
||||
hprintf128(request,"<h5>For dimmers, range is 0 to 100</h5>");
|
||||
hprintf128(request,"<h5>For custom values, you can set any number you want to</h5>");
|
||||
hprintf128(request,"<h5>Remember that you can also use short startup command to run commands like led_baseColor #FF0000 and led_enableAll 1 etc</h5>");
|
||||
|
||||
if( http_getArg(request->url,"idx",tmpA,sizeof(tmpA))) {
|
||||
channelIndex = atoi(tmpA);
|
||||
if( http_getArg(request->url,"value",tmpA,sizeof(tmpA))) {
|
||||
newValue = atoi(tmpA);
|
||||
|
||||
|
||||
CFG_SetChannelStartupValue(channelIndex,newValue);
|
||||
|
||||
hprintf128(request,"<h5>Setting channel %i start value to %i<h5>",channelIndex,newValue);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
if(CHANNEL_IsInUse(i)) {
|
||||
int startValue;
|
||||
|
||||
startValue = CFG_GetChannelStartupValue(i);
|
||||
|
||||
poststr(request,"<br><form action=\"/cfg_startup\">\
|
||||
<label for=\"boot_ok_delay\">New start value for channel ");
|
||||
hprintf128(request, "%i",i);
|
||||
poststr(request,":</label><br>\
|
||||
<input type=\"hidden\" id=\"idx\" name=\"idx\" value=\"");
|
||||
hprintf128(request, "%i",i);
|
||||
poststr(request,"\">");
|
||||
poststr(request,"<input type=\"number\" id=\"value\" name=\"value\" value=\"");
|
||||
hprintf128(request, "%i",startValue);
|
||||
poststr(request,"\"><br>");
|
||||
poststr(request,"<input type=\"submit\" value=\"Save\"/></form>");
|
||||
}
|
||||
}
|
||||
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void XR809_RequestOTAHTTP(const char *s);
|
||||
|
||||
|
||||
@@ -30,3 +30,4 @@ int http_fn_other(http_request_t *request);
|
||||
int http_fn_cm(http_request_t *request);
|
||||
int http_fn_startup_command(http_request_t *request);
|
||||
int http_fn_cfg_generic(http_request_t *request);
|
||||
int http_fn_cfg_startup(http_request_t *request);
|
||||
|
||||
@@ -531,6 +531,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
if(http_checkUrlBase(urlStr,"config_dump_table")) return http_fn_config_dump_table(request);
|
||||
if(http_checkUrlBase(urlStr,"startup_command")) return http_fn_startup_command(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_generic")) return http_fn_cfg_generic(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_startup")) return http_fn_cfg_startup(request);
|
||||
|
||||
if(http_checkUrlBase(urlStr,"cfg_quick")) return http_fn_cfg_quick(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_ha")) return http_fn_cfg_ha(request);
|
||||
|
||||
@@ -337,6 +337,23 @@ void CFG_Save_IfThereArePendingChanges() {
|
||||
g_cfg_pendingChanges = 0;
|
||||
}
|
||||
}
|
||||
void CFG_SetChannelStartupValue(int channelIndex,short newValue) {
|
||||
if(channelIndex < 0 || channelIndex >= CHANNEL_MAX) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_CFG, "CFG_SetChannelStartupValue: Channel index %i out of range <0,%i).",channelIndex,CHANNEL_MAX);
|
||||
return;
|
||||
}
|
||||
if(g_cfg.startChannelValues[channelIndex] != newValue) {
|
||||
g_cfg.startChannelValues[channelIndex] = newValue;
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
short CFG_GetChannelStartupValue(int channelIndex) {
|
||||
if(channelIndex < 0 || channelIndex >= CHANNEL_MAX) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_CFG, "CFG_SetChannelStartupValue: Channel index %i out of range <0,%i).",channelIndex,CHANNEL_MAX);
|
||||
return 0;
|
||||
}
|
||||
return g_cfg.startChannelValues[channelIndex];
|
||||
}
|
||||
void PIN_SetPinChannelForPinIndex(int index, int ch) {
|
||||
if(index < 0 || index >= PLATFORM_GPIO_MAX) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_CFG, "PIN_SetPinChannelForPinIndex: Pin index %i out of range <0,%i).",index,PLATFORM_GPIO_MAX);
|
||||
@@ -386,4 +403,5 @@ void CFG_InitAndLoad() {
|
||||
addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Correct config has been loaded with %i changes count.",g_cfg.changeCounter);
|
||||
}
|
||||
g_configInitialized = 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,6 +45,9 @@ void CFG_SetPingDisconnectedSecondsToRestart(int i);
|
||||
void CFG_SetPingIntervalSeconds(int i);
|
||||
void CFG_SetBootOkSeconds(int v);
|
||||
int CFG_GetBootOkSeconds();
|
||||
void CFG_SetChannelStartupValue(int channelIndex,short newValue);
|
||||
short CFG_GetChannelStartupValue(int channelIndex);
|
||||
void CFG_ApplyChannelStartValues();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -65,13 +65,6 @@ static byte g_timesUp[PLATFORM_GPIO_MAX];
|
||||
static byte g_lastValidState[PLATFORM_GPIO_MAX];
|
||||
|
||||
|
||||
void PIN_OnReboot() {
|
||||
int i;
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
g_channelValues[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PIN_SetupPins() {
|
||||
int i;
|
||||
for(i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
@@ -487,6 +480,19 @@ static void Channel_OnChanged(int ch, int prevValue, int iFlags) {
|
||||
}
|
||||
EventHandlers_ProcessVariableChange_Integer(CMD_EVENT_CHANGE_CHANNEL0 + ch, prevValue, iVal);
|
||||
}
|
||||
void CFG_ApplyChannelStartValues() {
|
||||
int i;
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
int iValue;
|
||||
|
||||
iValue = g_cfg.startChannelValues[i];
|
||||
if(iValue == -1) {
|
||||
|
||||
} else {
|
||||
g_channelValues[i] = iValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
int CHANNEL_Get(int ch) {
|
||||
if(ch < 0 || ch >= CHANNEL_MAX) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_GENERAL,"CHANNEL_Get: Channel index %i is out of range <0,%i)\n\r",ch,CHANNEL_MAX);
|
||||
@@ -652,7 +658,11 @@ void PIN_Input_Handler(int pinIndex)
|
||||
uint8_t read_gpio_level;
|
||||
|
||||
handle = &g_buttons[pinIndex];
|
||||
read_gpio_level = handle->hal_button_Level(handle);
|
||||
if(handle->hal_button_Level != 0) {
|
||||
read_gpio_level = handle->hal_button_Level(handle);
|
||||
} else {
|
||||
read_gpio_level = handle->button_level;
|
||||
}
|
||||
|
||||
//ticks counter working..
|
||||
if((handle->state) > 0)
|
||||
@@ -959,7 +969,7 @@ OS_Timer_t timer;
|
||||
#else
|
||||
beken_timer_t g_pin_timer;
|
||||
#endif
|
||||
void PIN_Init(void)
|
||||
void PIN_StartButtonScanThread(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -972,7 +982,7 @@ void PIN_Init(void)
|
||||
OS_TimerSetInvalid(&timer);
|
||||
if (OS_TimerCreate(&timer, OS_TIMER_PERIODIC, PIN_ticks, NULL,
|
||||
PIN_TMR_DURATION) != OS_OK) {
|
||||
printf("PIN_Init timer create failed\n");
|
||||
printf("PIN_AddCommands timer create failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -991,8 +1001,14 @@ void PIN_Init(void)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PIN_AddCommands(void)
|
||||
{
|
||||
|
||||
CMD_RegisterCommand("showgpi", NULL, showgpi, "log stat of all GPIs", NULL);
|
||||
CMD_RegisterCommand("setChannelType", NULL, CMD_SetChannelType, "qqqqqqqq", NULL);
|
||||
CMD_RegisterCommand("showChannelValues", NULL,CMD_ShowChannelValues, "log channel values", NULL);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,8 @@ typedef struct mainConfig_s {
|
||||
char shortDeviceName[32];
|
||||
char longDeviceName[64];
|
||||
pinsState_t pins;
|
||||
byte unusedSectorA[256];
|
||||
short startChannelValues[CHANNEL_MAX];
|
||||
byte unusedSectorA[128];
|
||||
byte unusedSectorB[128];
|
||||
byte unusedSectorC[55];
|
||||
byte timeRequiredToMarkBootSuccessfull;
|
||||
@@ -133,8 +134,9 @@ extern char g_enable_pins;
|
||||
#define CHANNEL_SET_FLAG_FORCE 1
|
||||
#define CHANNEL_SET_FLAG_SKIP_MQTT 2
|
||||
|
||||
void PIN_Init(void);
|
||||
void PIN_AddCommands(void);
|
||||
void PIN_SetupPins();
|
||||
void PIN_StartButtonScanThread(void);
|
||||
void PIN_OnReboot();
|
||||
void CFG_ClearPins();
|
||||
int PIN_GetPinRoleForPinIndex(int index);
|
||||
|
||||
@@ -321,7 +321,6 @@ void Main_Init()
|
||||
|
||||
// read or initialise the boot count flash area
|
||||
HAL_FlashVars_IncreaseBootCount();
|
||||
PIN_OnReboot();
|
||||
|
||||
g_bootFailures = HAL_FlashVars_GetBootFailures();
|
||||
if (g_bootFailures > RESTARTS_REQUIRED_FOR_SAFE_MODE){
|
||||
@@ -359,7 +358,6 @@ void Main_Init()
|
||||
|
||||
HTTPServer_Start();
|
||||
ADDLOGF_DEBUG("Started http tcp server\r\n");
|
||||
|
||||
// only initialise certain things if we are not in AP mode
|
||||
if (!bSafeMode){
|
||||
|
||||
@@ -368,7 +366,9 @@ void Main_Init()
|
||||
#endif
|
||||
RepeatingEvents_Init();
|
||||
|
||||
PIN_Init();
|
||||
CFG_ApplyChannelStartValues();
|
||||
|
||||
PIN_AddCommands();
|
||||
|
||||
//CFG_ApplyStartChannelValues();
|
||||
ADDLOGF_DEBUG("Initialised pins\r\n");
|
||||
@@ -387,7 +387,6 @@ void Main_Init()
|
||||
// and we may add a command to empty fs just be writing first sector?
|
||||
init_lfs(0);
|
||||
#endif
|
||||
|
||||
// initialise rest interface
|
||||
init_rest();
|
||||
|
||||
@@ -412,6 +411,7 @@ void Main_Init()
|
||||
g_enable_pins = 1;
|
||||
// this actually sets the pins, moved out so we could avoid if necessary
|
||||
PIN_SetupPins();
|
||||
PIN_StartButtonScanThread();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user