mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-29 02:53:46 +02:00
Refactor the startup flow, cleanup old progress logs, cleanup globals
This commit is contained in:
@@ -128,8 +128,20 @@ CommandResult getLEDDutyCycleCommand(std::shared_ptr<DependencyRegistry> registr
|
||||
|
||||
CommandResult startStreamingCommand()
|
||||
{
|
||||
activateStreaming(false); // Don't disable setup interfaces by default
|
||||
return CommandResult::getSuccessResult("Streaming started");
|
||||
// since we're trying to kill the serial handler
|
||||
// from *inside* the serial handler, we'd deadlock.
|
||||
// we can just pass nullptr to the vtaskdelete(),
|
||||
// but then we won't get any response, so we schedule a timer instead
|
||||
esp_timer_create_args_t args{
|
||||
.callback = activateStreaming,
|
||||
.arg = nullptr,
|
||||
.name = "activateStreaming"};
|
||||
|
||||
esp_timer_handle_t activateStreamingTimer;
|
||||
esp_timer_create(&args, &activateStreamingTimer);
|
||||
esp_timer_start_once(activateStreamingTimer, pdMS_TO_TICKS(150));
|
||||
|
||||
return CommandResult::getSuccessResult("Streaming starting");
|
||||
}
|
||||
|
||||
CommandResult switchModeCommand(std::shared_ptr<DependencyRegistry> registry, std::string_view jsonPayload)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "main_globals.hpp"
|
||||
#include "esp_log.h"
|
||||
|
||||
// Forward declarations
|
||||
extern void start_video_streaming(void *arg);
|
||||
// used to force starting the stream setup process via commands
|
||||
extern void force_activate_streaming();
|
||||
|
||||
static bool s_startupCommandReceived = false;
|
||||
bool getStartupCommandReceived()
|
||||
@@ -15,17 +15,6 @@ void setStartupCommandReceived(bool startupCommandReceived)
|
||||
s_startupCommandReceived = startupCommandReceived;
|
||||
}
|
||||
|
||||
static TaskHandle_t *g_serial_manager_handle = nullptr;
|
||||
TaskHandle_t *getSerialManagerHandle()
|
||||
{
|
||||
return g_serial_manager_handle;
|
||||
}
|
||||
|
||||
void setSerialManagerHandle(TaskHandle_t *serialManagerHandle)
|
||||
{
|
||||
g_serial_manager_handle = serialManagerHandle;
|
||||
}
|
||||
|
||||
// Global pause state
|
||||
static bool s_startupPaused = false;
|
||||
bool getStartupPaused()
|
||||
@@ -39,14 +28,9 @@ void setStartupPaused(bool startupPaused)
|
||||
}
|
||||
|
||||
// Function to manually activate streaming
|
||||
void activateStreaming(bool disableSetup)
|
||||
void activateStreaming(void *arg)
|
||||
{
|
||||
ESP_LOGI("[MAIN_GLOBALS]", "Manually activating streaming, disableSetup=%s", disableSetup ? "true" : "false");
|
||||
|
||||
TaskHandle_t *serialHandle = disableSetup ? g_serial_manager_handle : nullptr;
|
||||
void *serialTaskHandle = (serialHandle && *serialHandle) ? *serialHandle : nullptr;
|
||||
|
||||
start_video_streaming(serialTaskHandle);
|
||||
force_activate_streaming();
|
||||
}
|
||||
|
||||
// USB handover state
|
||||
|
||||
@@ -6,14 +6,10 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
// Functions for main to set global handles
|
||||
|
||||
// Functions to access global handles from components
|
||||
TaskHandle_t *getSerialManagerHandle();
|
||||
void setSerialManagerHandle(TaskHandle_t *serialManagerHandle);
|
||||
|
||||
// Function to manually activate streaming
|
||||
void activateStreaming(bool disableSetup = false);
|
||||
// designed to be scheduled as a task
|
||||
// so that the serial manager has time to return the response
|
||||
void activateStreaming(void *arg);
|
||||
|
||||
bool getStartupCommandReceived();
|
||||
void setStartupCommandReceived(bool startupCommandReceived);
|
||||
|
||||
@@ -132,15 +132,15 @@ void SerialManager::shutdown()
|
||||
{
|
||||
// Stop heartbeats; timer will be deleted by main if needed.
|
||||
// Uninstall the USB Serial JTAG driver to free the internal USB for TinyUSB.
|
||||
// esp_err_t err = usb_serial_jtag_driver_uninstall();
|
||||
// if (err == ESP_OK)
|
||||
// {
|
||||
// ESP_LOGI("[SERIAL]", "usb_serial_jtag driver uninstalled");
|
||||
// }
|
||||
// else if (err != ESP_ERR_INVALID_STATE)
|
||||
// {
|
||||
// ESP_LOGW("[SERIAL]", "usb_serial_jtag_driver_uninstall returned %s", esp_err_to_name(err));
|
||||
// }
|
||||
esp_err_t err = usb_serial_jtag_driver_uninstall();
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
ESP_LOGI("[SERIAL]", "usb_serial_jtag driver uninstalled");
|
||||
}
|
||||
else if (err != ESP_ERR_INVALID_STATE)
|
||||
{
|
||||
ESP_LOGW("[SERIAL]", "usb_serial_jtag_driver_uninstall returned %s", esp_err_to_name(err));
|
||||
}
|
||||
}
|
||||
|
||||
// we can cancel this task once we're in cdc
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#include "esp_vfs_dev.h"
|
||||
#include "esp_mac.h"
|
||||
|
||||
void tud_cdc_rx_cb(uint8_t itf);
|
||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
|
||||
extern "C" void tud_cdc_rx_cb(uint8_t itf);
|
||||
extern "C" void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
|
||||
|
||||
extern QueueHandle_t cdcMessageQueue;
|
||||
|
||||
@@ -49,5 +49,5 @@ private:
|
||||
};
|
||||
|
||||
void HandleSerialManagerTask(void *pvParameters);
|
||||
void HandleCDCSerialManagerTask(void *pvParameters)
|
||||
void HandleCDCSerialManagerTask(void *pvParameters);
|
||||
#endif
|
||||
Reference in New Issue
Block a user