Merge pull request #1362 from kyberias/stark-fixes

Stark and Wifi fixes
This commit is contained in:
Jaakko Haakana 2025-07-27 13:01:12 +03:00 committed by GitHub
commit ee561d18c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 14 deletions

View file

@ -59,16 +59,31 @@ class Esp32Hal {
return alloc_pins(name, pins[Is]...);
}
// Base case: no more pins
inline bool alloc_pins_ignore_unused_impl(const char* name) {
return alloc_pins(name); // Call with 0 pins
}
// Recursive case: process one pin at a time
template <typename... Rest>
bool alloc_pins_ignore_unused_impl(const char* name, gpio_num_t first, Rest... rest) {
if (first == GPIO_NUM_NC) {
return alloc_pins_ignore_unused_impl(name, rest...);
} else {
return call_alloc_pins_filtered(name, first, rest...);
}
}
// This helper just forwards pins after filtering is done
template <typename... Pins>
bool call_alloc_pins_filtered(const char* name, Pins... pins) {
return alloc_pins(name, pins...);
}
// Entry point
template <typename... Pins>
bool alloc_pins_ignore_unused(const char* name, Pins... pins) {
std::vector<gpio_num_t> valid_pins;
for (gpio_num_t pin : std::vector<gpio_num_t>{static_cast<gpio_num_t>(pins)...}) {
if (pin != GPIO_NUM_NC) {
valid_pins.push_back(pin);
}
}
return alloc_pins_from_vector(name, valid_pins, std::make_index_sequence<sizeof...(pins)>{});
return alloc_pins_ignore_unused_impl(name, static_cast<gpio_num_t>(pins)...);
}
virtual bool always_enable_bms_power() { return false; }

View file

@ -2,6 +2,7 @@
#define __LOGGING_H__
#include <inttypes.h>
#include "../../../USER_SETTINGS.h"
#include "Print.h"
#include "types.h"

View file

@ -113,16 +113,20 @@ void wifi_monitor() {
if ((hasConnectedBefore && (currentMillis - lastWiFiCheck > current_check_interval)) ||
(!hasConnectedBefore && (currentMillis - lastWiFiCheck > INIT_WIFI_FULL_RECONNECT_INTERVAL))) {
DEBUG_PRINTF("Time to monitor Wi-Fi status: %d, %d, %d, %d, %d\n", hasConnectedBefore, currentMillis, lastWiFiCheck,
current_check_interval, INIT_WIFI_FULL_RECONNECT_INTERVAL);
lastWiFiCheck = currentMillis;
wl_status_t status = WiFi.status();
if (status != WL_CONNECTED) {
// WL_IDLE_STATUS can mean we're connected but haven't yet gotten the IP.
if (status != WL_CONNECTED && status != WL_IDLE_STATUS) {
// Increase the current check interval if it's not at the maximum
if (current_check_interval + STEP_WIFI_CHECK_INTERVAL <= MAX_STEP_WIFI_CHECK_INTERVAL)
if (current_check_interval + STEP_WIFI_CHECK_INTERVAL <= MAX_STEP_WIFI_CHECK_INTERVAL) {
current_check_interval += STEP_WIFI_CHECK_INTERVAL;
#ifdef DEBUG_LOG
logging.println("Wi-Fi not connected, attempting to reconnect...");
#endif
}
DEBUG_PRINTF("Wi-Fi not connected (status=%d), attempting to reconnect\n", status);
// Try WiFi.reconnect() if it was successfully connected at least once
if (hasConnectedBefore) {
lastReconnectAttempt = currentMillis; // Reset reconnection attempt timer
@ -203,7 +207,7 @@ void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) {
clear_event(EVENT_WIFI_DISCONNECT);
set_event(EVENT_WIFI_CONNECT, 0);
connected_once = true;
DEBUG_PRINTF("Wi-Fi connected. RSSI: %d dBm, IP address: %s, SSID: %s\n", -WiFi.RSSI(),
DEBUG_PRINTF("Wi-Fi connected. status: %d, RSSI: %d dBm, IP address: %s, SSID: %s\n", WiFi.status(), -WiFi.RSSI(),
WiFi.localIP().toString().c_str(), WiFi.SSID().c_str());
hasConnectedBefore = true; // Mark as successfully connected at least once
reconnectAttempts = 0; // Reset the attempt counter