Refactoring: Module entkoppelt und Aufrufe über main zentralisiert
wifi_mgr vollständig von http_portal und dns_captive entkoppelt - Neues Callback-Interface in http_portal implementiert - Callback-Initialisierung in main.c hinzugefügt (WiFi-Creds, Device-Info) - dns_captive in eigenes Modul ausgelagert (dns_captive.h ergänzt) - Alte Vorwärtsdeklarationen entfernt und öffentliche API in wifi_mgr.h ergänzt - Startreihenfolge der Module neu strukturiert (Orchestrierung in main.c) - Projektabhängigkeiten vereinfacht und Zyklus zwischen Modulen aufgelöst
This commit is contained in:
+57
-15
@@ -5,7 +5,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include "wifi_mgr.h"
|
||||
#include "sen5x_app.h"
|
||||
#include "storage.h"
|
||||
|
||||
@@ -42,7 +41,32 @@
|
||||
#include "images.h"
|
||||
#include "screens.h" // <-- Zugriff auf objects.* und tick_screen()
|
||||
|
||||
// Entfernt: extern lv_obj_t *ui_wifi/influx/mdns;
|
||||
#include "wifi_mgr.h"
|
||||
#include "dns_captive.h"
|
||||
#include "http_portal.h"
|
||||
|
||||
// --- Callback-Implementierungen für das Portal ---
|
||||
|
||||
static bool app_load_sta_creds(char **ssid, char **pass)
|
||||
{
|
||||
// Wenn du das Portal später mal /scan oder Default-SSID aus NVS ziehen lassen willst
|
||||
return storage_load_wifi_creds(ssid, pass);
|
||||
}
|
||||
|
||||
static void app_save_sta_creds_and_reconnect(const char *ssid, const char *pass)
|
||||
{
|
||||
wifi_mgr_save_sta_creds_and_reconnect(ssid, pass);
|
||||
}
|
||||
|
||||
static void app_save_device_info(
|
||||
const char *devicename,
|
||||
const char *token,
|
||||
const char *bucket,
|
||||
const char *org)
|
||||
{
|
||||
storage_save_device_name(devicename);
|
||||
storage_save_influx_softap(org, bucket, token);
|
||||
}
|
||||
|
||||
// ---------- Status-Icons updaten: nutzt die in screens.c erzeugten Objekte ----------
|
||||
static void ui_update_status_icons(void)
|
||||
@@ -308,14 +332,10 @@ static void button_init(void)
|
||||
// Beim Loslassen nach langem Drücken -> wirklich resetten
|
||||
iot_button_register_cb(g_btn, BUTTON_LONG_PRESS_UP, NULL, reset_button_cb, NULL);
|
||||
}
|
||||
|
||||
/* ==================== app_main (unverändert, plus Button-Reset) ==================== */
|
||||
|
||||
/* ==================== main ==================== */
|
||||
void app_main(void)
|
||||
{
|
||||
/*
|
||||
esp_log_level_set("storage", ESP_LOG_NONE);
|
||||
*/
|
||||
|
||||
esp_log_level_set("*", ESP_LOG_NONE);
|
||||
|
||||
@@ -324,7 +344,7 @@ void app_main(void)
|
||||
sys_status_set_influx_ok(false);
|
||||
sys_status_set_mdns_ok(false);
|
||||
|
||||
// 0) NVS zuerst
|
||||
// NVS zuerst
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
@@ -332,21 +352,21 @@ void app_main(void)
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
// --- Storage/WiFi wie gehabt ---
|
||||
// --- Storage
|
||||
ESP_ERROR_CHECK(storage_init());
|
||||
storage_debug_dump();
|
||||
// WiFi Manager initialisieren
|
||||
wifi_mgr_init();
|
||||
wifi_mgr_start();
|
||||
|
||||
ESP_ERROR_CHECK(i2cdev_init());
|
||||
|
||||
// 1) I2C-Bus initialisieren (bsp_i2c.h)
|
||||
// I2C-Bus initialisieren (bsp_i2c.h)
|
||||
i2c_master_bus_handle_t i2c_bus_handle = bsp_i2c_init();
|
||||
|
||||
// 2) Diesen Bus von i2cdev "adoptieren", damit SEN5x denselben Bus nutzt
|
||||
// Diesen Bus von i2cdev "adoptieren", damit SEN5x denselben Bus nutzt
|
||||
ESP_ERROR_CHECK(i2cdev_adopt_bus(0, i2c_bus_handle, 18, 19)); // Port 0, SDA=18, SCL=19
|
||||
|
||||
// 3) Restliche Peripherie
|
||||
// Restliche Peripherie
|
||||
bsp_spi_init();
|
||||
bsp_battery_init();
|
||||
// bsp_qmi8658_init(i2c_bus_handle);
|
||||
@@ -370,7 +390,29 @@ void app_main(void)
|
||||
lv_timer_t *ui_timer = lv_timer_create(ui_tick_cb, 1000, NULL);
|
||||
(void)ui_timer;
|
||||
|
||||
// 4) SEN5x
|
||||
// WiFi AP+STA starten
|
||||
wifi_mgr_start();
|
||||
|
||||
// AP-Netif an DNS weitergeben
|
||||
dns_captive_set_ap_netif(wifi_mgr_get_ap_netif());
|
||||
// Captive-DNS starten
|
||||
ESP_ERROR_CHECK(dns_captive_start());
|
||||
|
||||
portal_http_callbacks_t cb = {
|
||||
.load_sta_creds = app_load_sta_creds,
|
||||
.save_sta_creds_and_reconnect= app_save_sta_creds_and_reconnect,
|
||||
.save_device_info = app_save_device_info
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(portal_http_start(
|
||||
wifi_mgr_get_event_group(),
|
||||
wifi_mgr_evt_sta_got_ip(),
|
||||
wifi_mgr_evt_sta_fail(),
|
||||
"nanoPSX",
|
||||
&cb
|
||||
));
|
||||
|
||||
// SEN5x
|
||||
const sen5x_i2c_cfg_t cfg = {
|
||||
.addr = 0x69,
|
||||
.port = 0,
|
||||
@@ -382,7 +424,7 @@ void app_main(void)
|
||||
};
|
||||
ESP_ERROR_CHECK(sen5x_app_init(&cfg));
|
||||
|
||||
// 5) Task starten
|
||||
// Task starten
|
||||
xTaskCreate(sen5x_app_task, "sen5x_task", 4096, NULL, 5, NULL);
|
||||
|
||||
for (;;) vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
Reference in New Issue
Block a user