diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index bc2cd7ec8..6a23b9624 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -294,6 +294,21 @@ int http_fn_index(http_request_t *request) { poststr(request,"
"); + if(1) { + int bFirst = true; + hprintf128(request,"
"); + for(i = 0; i < CHANNEL_MAX; i++) { + if(CHANNEL_IsUsed(i)) { + int value = CHANNEL_Get(i); + if(bFirst == false) { + hprintf128(request,", "); + } + hprintf128(request,"Channel %i = %i",i,value); + bFirst = false; + } + } + hprintf128(request,"
"); + } hprintf128(request,"
Cfg size: %i, change counter: %i, ota counter: %i, boot incompletes %i (might change to 0 if you wait to 30 sec)!
", sizeof(g_cfg),g_cfg.changeCounter,g_cfg.otaCounter,Main_GetLastRebootBootFailures()); diff --git a/src/new_cfg.c b/src/new_cfg.c index ab209daa6..00d8239a4 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -361,16 +361,16 @@ void PIN_SetPinChannel2ForPinIndex(int index, int ch) { g_cfg.pins.channels2[index] = ch; } } -void CFG_ApplyStartChannelValues() { - int i; - - // apply channel values - for(i = 0; i < CHANNEL_MAX; i++) { - if(CHANNEL_IsInUse(i)) { - CHANNEL_Set(i,0,CHANNEL_SET_FLAG_FORCE | CHANNEL_SET_FLAG_SKIP_MQTT); - } - } -} +//void CFG_ApplyStartChannelValues() { +// int i; +// +// // apply channel values +// for(i = 0; i < CHANNEL_MAX; i++) { +// if(CHANNEL_IsInUse(i)) { +// CHANNEL_Set(i,0,CHANNEL_SET_FLAG_FORCE | CHANNEL_SET_FLAG_SKIP_MQTT); +// } +// } +//} void CFG_InitAndLoad() { byte chkSum; diff --git a/src/new_cfg.h b/src/new_cfg.h index 3f815e21d..7c38be71c 100644 --- a/src/new_cfg.h +++ b/src/new_cfg.h @@ -26,7 +26,7 @@ void CFG_SetMQTTPass(const char *s); const char *CFG_GetWebappRoot(); int CFG_SetWebappRoot(const char *s); void CFG_InitAndLoad(); -void CFG_ApplyStartChannelValues(); +//void CFG_ApplyStartChannelValues(); void CFG_Save_IfThereArePendingChanges(); void CFG_Save_SetupTimer(); void CFG_IncrementOTACount(); diff --git a/src/new_pins.c b/src/new_pins.c index 03ff5e404..7d7c1b4f1 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -60,8 +60,17 @@ pinButton_s g_buttons[PLATFORM_GPIO_MAX]; void (*g_doubleClickCallback)(int pinIndex) = 0; +static byte g_timesDown[PLATFORM_GPIO_MAX]; +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; @@ -361,6 +370,13 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { } break; case IOR_ToggleChannelOnToggle: + { + // digital input + HAL_PIN_Setup_Input_Pullup(index); + // otherwise we get a toggle on start + g_lastValidState[index] = PIN_ReadDigitalInputValue_WithInversionIncluded(index); + } + break; case IOR_DigitalInput: case IOR_DigitalInput_n: { @@ -379,6 +395,21 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_LED_n: case IOR_Relay: case IOR_Relay_n: + { + int channelIndex; + int channelValue; + + channelIndex = PIN_GetPinChannelForPinIndex(index); + channelValue = g_channelValues[channelIndex]; + + HAL_PIN_Setup_Output(index); + if(role == IOR_LED_n || role == IOR_Relay_n) { + HAL_PIN_SetOutputValue(index,!channelValue); + } else { + HAL_PIN_SetOutputValue(index,channelValue); + } + } + break; case IOR_LED_WIFI: case IOR_LED_WIFI_n: { @@ -621,7 +652,7 @@ void PIN_Input_Handler(int pinIndex) uint8_t read_gpio_level; handle = &g_buttons[pinIndex]; - read_gpio_level = button_generic_get_gpio_value(handle); + read_gpio_level = handle->hal_button_Level(handle); //ticks counter working.. if((handle->state) > 0) @@ -718,9 +749,6 @@ void PIN_Input_Handler(int pinIndex) } } -byte g_timesDown[PLATFORM_GPIO_MAX]; -byte g_timesUp[PLATFORM_GPIO_MAX]; -byte g_lastValidState[PLATFORM_GPIO_MAX]; static void PIN_set_wifi_led(int value){ int i; diff --git a/src/new_pins.h b/src/new_pins.h index 6a93b7390..a08ced3bc 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -135,6 +135,7 @@ extern char g_enable_pins; void PIN_Init(void); void PIN_SetupPins(); +void PIN_OnReboot(); void CFG_ClearPins(); int PIN_GetPinRoleForPinIndex(int index); int PIN_GetPinChannelForPinIndex(int index); diff --git a/src/user_main.c b/src/user_main.c index d90c8f255..f9141a82c 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -321,6 +321,7 @@ 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){ @@ -361,9 +362,6 @@ void Main_Init() // only initialise certain things if we are not in AP mode if (!bSafeMode){ - g_enable_pins = 1; - // this actually sets the pins, moved out so we could avoid if necessary - PIN_SetupPins(); #ifndef OBK_DISABLE_ALL_DRIVERS DRV_Generic_Init(); @@ -372,7 +370,7 @@ void Main_Init() PIN_Init(); - CFG_ApplyStartChannelValues(); + //CFG_ApplyStartChannelValues(); ADDLOGF_DEBUG("Initialised pins\r\n"); // initialise MQTT - just sets up variables. @@ -410,6 +408,10 @@ void Main_Init() CMD_ExecuteCommand(CFG_GetShortStartupCommand(), COMMAND_FLAG_SOURCE_SCRIPT); CMD_ExecuteCommand("exec autoexec.bat", COMMAND_FLAG_SOURCE_SCRIPT); + + g_enable_pins = 1; + // this actually sets the pins, moved out so we could avoid if necessary + PIN_SetupPins(); } }