Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Allman
ColumnLimit: 160
IncludeBlocks: Preserve
IndentCaseLabels: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: Never
16 changes: 7 additions & 9 deletions bootloader_components/boot_hooks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// source: https://github.com/espressif/esp-iot-solution/blob/4730d91db70df7e6e0a3191d725ab1c5f98ff9ce/examples/usb/device/usb_webcam/bootloader_components/boot_hooks/boot_hooks.c
// source:
// https://github.com/espressif/esp-iot-solution/blob/4730d91db70df7e6e0a3191d725ab1c5f98ff9ce/examples/usb/device/usb_webcam/bootloader_components/boot_hooks/boot_hooks.c

#ifdef CONFIG_GENERAL_INCLUDE_UVC_MODE
#include "esp_log.h"
Expand All @@ -9,16 +10,13 @@
* with all its symbols.
*/

void bootloader_hooks_include(void)
{
}
void bootloader_hooks_include(void) {}

void bootloader_before_init(void)
{

// Disable D+ pullup, to prevent the USB host from retrieving USB-Serial-JTAG's descriptor.
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
// Disable D+ pullup, to prevent the USB host from retrieving USB-Serial-JTAG's descriptor.
SET_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_PAD_PULL_OVERRIDE);
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
}
#endif
366 changes: 179 additions & 187 deletions components/CameraManager/CameraManager/CameraManager.cpp

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions components/CameraManager/CameraManager/CameraManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
#ifndef CAMERAMANAGER_HPP
#define CAMERAMANAGER_HPP

#include "esp_log.h"
#include "esp_camera.h"
#include "driver/gpio.h"
#include "esp_camera.h"
#include "esp_log.h"
#include "esp_psram.h"
#include "sdkconfig.h"

#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"

#include <StateManager.hpp>
#include <ProjectConfig.hpp>
#include <StateManager.hpp>

#define OV5640_XCLK_FREQ_HZ CONFIG_CAMERA_WIFI_XCLK_FREQ

class CameraManager
{
private:
sensor_t *camera_sensor;
std::shared_ptr<ProjectConfig> projectConfig;
QueueHandle_t eventQueue;
camera_config_t config;

public:
CameraManager(std::shared_ptr<ProjectConfig> projectConfig, QueueHandle_t eventQueue);
int setCameraResolution(framesize_t frameSize);
bool setupCamera();
int setVFlip(int direction);
int setHFlip(int direction);
int setVieWindow(int offsetX, int offsetY, int outputX, int outputY);

private:
void loadConfigData();
void setupCameraPinout();
void setupCameraSensor();
private:
sensor_t* camera_sensor;
std::shared_ptr<ProjectConfig> projectConfig;
QueueHandle_t eventQueue;
camera_config_t config;

public:
CameraManager(std::shared_ptr<ProjectConfig> projectConfig, QueueHandle_t eventQueue);
int setCameraResolution(framesize_t frameSize);
bool setupCamera();
int setVFlip(int direction);
int setHFlip(int direction);
int setVieWindow(int offsetX, int offsetY, int outputX, int outputY);

private:
void loadConfigData();
void setupCameraPinout();
void setupCameraSensor();
};

#endif // CAMERAMANAGER_HPP
#endif // CAMERAMANAGER_HPP
213 changes: 95 additions & 118 deletions components/CommandManager/CommandManager/CommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,140 +30,117 @@ std::unordered_map<std::string, CommandType> commandTypeMap = {
{"get_who_am_i", CommandType::GET_WHO_AM_I},
};

std::function<CommandResult()> CommandManager::createCommand(const CommandType type, const nlohmann::json &json) const
std::function<CommandResult()> CommandManager::createCommand(const CommandType type, const nlohmann::json& json) const
{
switch (type)
{
case CommandType::PING:
return {PingCommand};
case CommandType::PAUSE:
return [json]
{ return PauseCommand(json); };
case CommandType::UPDATE_OTA_CREDENTIALS:
return [this, json]
{ return updateOTACredentialsCommand(this->registry, json); };
case CommandType::SET_WIFI:
return [this, json]
{ return setWiFiCommand(this->registry, json); };
case CommandType::UPDATE_WIFI:
return [this, json]
{ return updateWiFiCommand(this->registry, json); };
case CommandType::UPDATE_AP_WIFI:
return [this, json]
{ return updateAPWiFiCommand(this->registry, json); };
case CommandType::DELETE_NETWORK:
return [this, json]
{ return deleteWiFiCommand(this->registry, json); };
case CommandType::SET_MDNS:
return [this, json]
{ return setMDNSCommand(this->registry, json); };
case CommandType::GET_MDNS_NAME:
return [this]
{ return getMDNSNameCommand(this->registry); };
case CommandType::UPDATE_CAMERA:
return [this, json]
{ return updateCameraCommand(this->registry, json); };
case CommandType::GET_CONFIG:
return [this]
{ return getConfigCommand(this->registry); };
case CommandType::SAVE_CONFIG:
return [this]
{ return saveConfigCommand(this->registry); };
case CommandType::RESET_CONFIG:
return [this, json]
{ return resetConfigCommand(this->registry, json); };
case CommandType::RESTART_DEVICE:
return restartDeviceCommand;
case CommandType::SCAN_NETWORKS:
return [this, json]
{ return scanNetworksCommand(this->registry, json); };
case CommandType::START_STREAMING:
return startStreamingCommand;
case CommandType::GET_WIFI_STATUS:
return [this]
{ return getWiFiStatusCommand(this->registry); };
case CommandType::CONNECT_WIFI:
return [this]
{ return connectWiFiCommand(this->registry); };
case CommandType::SWITCH_MODE:
return [this, json]
{ return switchModeCommand(this->registry, json); };
case CommandType::GET_DEVICE_MODE:
return [this]
{ return getDeviceModeCommand(this->registry); };
case CommandType::SET_LED_DUTY_CYCLE:
return [this, json]
{ return updateLEDDutyCycleCommand(this->registry, json); };
case CommandType::GET_LED_DUTY_CYCLE:
return [this]
{ return getLEDDutyCycleCommand(this->registry); };
case CommandType::GET_SERIAL:
return [this]
{ return getSerialNumberCommand(this->registry); };
case CommandType::GET_LED_CURRENT:
return [this]
{ return getLEDCurrentCommand(this->registry); };
case CommandType::GET_BATTERY_STATUS:
return [this]
{ return getBatteryStatusCommand(this->registry); };
case CommandType::GET_WHO_AM_I:
return [this]
{ return getInfoCommand(this->registry); };
default:
return nullptr;
}
switch (type)
{
case CommandType::PING:
return {PingCommand};
case CommandType::PAUSE:
return [json] { return PauseCommand(json); };
case CommandType::UPDATE_OTA_CREDENTIALS:
return [this, json] { return updateOTACredentialsCommand(this->registry, json); };
case CommandType::SET_WIFI:
return [this, json] { return setWiFiCommand(this->registry, json); };
case CommandType::UPDATE_WIFI:
return [this, json] { return updateWiFiCommand(this->registry, json); };
case CommandType::UPDATE_AP_WIFI:
return [this, json] { return updateAPWiFiCommand(this->registry, json); };
case CommandType::DELETE_NETWORK:
return [this, json] { return deleteWiFiCommand(this->registry, json); };
case CommandType::SET_MDNS:
return [this, json] { return setMDNSCommand(this->registry, json); };
case CommandType::GET_MDNS_NAME:
return [this] { return getMDNSNameCommand(this->registry); };
case CommandType::UPDATE_CAMERA:
return [this, json] { return updateCameraCommand(this->registry, json); };
case CommandType::GET_CONFIG:
return [this] { return getConfigCommand(this->registry); };
case CommandType::SAVE_CONFIG:
return [this] { return saveConfigCommand(this->registry); };
case CommandType::RESET_CONFIG:
return [this, json] { return resetConfigCommand(this->registry, json); };
case CommandType::RESTART_DEVICE:
return restartDeviceCommand;
case CommandType::SCAN_NETWORKS:
return [this, json] { return scanNetworksCommand(this->registry, json); };
case CommandType::START_STREAMING:
return startStreamingCommand;
case CommandType::GET_WIFI_STATUS:
return [this] { return getWiFiStatusCommand(this->registry); };
case CommandType::CONNECT_WIFI:
return [this] { return connectWiFiCommand(this->registry); };
case CommandType::SWITCH_MODE:
return [this, json] { return switchModeCommand(this->registry, json); };
case CommandType::GET_DEVICE_MODE:
return [this] { return getDeviceModeCommand(this->registry); };
case CommandType::SET_LED_DUTY_CYCLE:
return [this, json] { return updateLEDDutyCycleCommand(this->registry, json); };
case CommandType::GET_LED_DUTY_CYCLE:
return [this] { return getLEDDutyCycleCommand(this->registry); };
case CommandType::GET_SERIAL:
return [this] { return getSerialNumberCommand(this->registry); };
case CommandType::GET_LED_CURRENT:
return [this] { return getLEDCurrentCommand(this->registry); };
case CommandType::GET_BATTERY_STATUS:
return [this] { return getBatteryStatusCommand(this->registry); };
case CommandType::GET_WHO_AM_I:
return [this] { return getInfoCommand(this->registry); };
default:
return nullptr;
}
}

CommandManagerResponse CommandManager::executeFromJson(const std::string_view json) const
{
if (!nlohmann::json::accept(json))
{
return CommandManagerResponse(nlohmann::json{{"error", "Initial JSON Parse - Invalid JSON"}});
}

nlohmann::json parsedJson = nlohmann::json::parse(json);
if (!parsedJson.contains("commands") || !parsedJson["commands"].is_array() || parsedJson["commands"].empty())
{
return CommandManagerResponse(CommandResult::getErrorResult("Commands missing"));
}

nlohmann::json results = nlohmann::json::array();

for (auto &commandObject : parsedJson["commands"].items())
{
auto commandData = commandObject.value();
if (!commandData.contains("command"))
if (!nlohmann::json::accept(json))
{
return CommandManagerResponse({{"command", "Unknown command"}, {"error", "Missing command type"}});
return CommandManagerResponse(nlohmann::json{{"error", "Initial JSON Parse - Invalid JSON"}});
}

const auto commandName = commandData["command"].get<std::string>();
if (!commandTypeMap.contains(commandName))
nlohmann::json parsedJson = nlohmann::json::parse(json);
if (!parsedJson.contains("commands") || !parsedJson["commands"].is_array() || parsedJson["commands"].empty())
{
return CommandManagerResponse({{"command", commandName}, {"error", "Unknown command"}});
return CommandManagerResponse(CommandResult::getErrorResult("Commands missing"));
}

const auto commandType = commandTypeMap.at(commandName);
const auto commandPayload = commandData.contains("data") ? commandData["data"] : nlohmann::json::object();
nlohmann::json results = nlohmann::json::array();

for (auto& commandObject : parsedJson["commands"].items())
{
auto commandData = commandObject.value();
if (!commandData.contains("command"))
{
return CommandManagerResponse({{"command", "Unknown command"}, {"error", "Missing command type"}});
}

const auto commandName = commandData["command"].get<std::string>();
if (!commandTypeMap.contains(commandName))
{
return CommandManagerResponse({{"command", commandName}, {"error", "Unknown command"}});
}

const auto commandType = commandTypeMap.at(commandName);
const auto commandPayload = commandData.contains("data") ? commandData["data"] : nlohmann::json::object();

auto command = createCommand(commandType, commandPayload);
results.push_back({
{"command", commandName},
{"result", command()},
});
}
auto response = nlohmann::json{{"results", results}};
return CommandManagerResponse(response);
auto command = createCommand(commandType, commandPayload);
results.push_back({
{"command", commandName},
{"result", command()},
});
}
auto response = nlohmann::json{{"results", results}};
return CommandManagerResponse(response);
}

CommandManagerResponse CommandManager::executeFromType(const CommandType type, const std::string_view json) const
{
const auto command = createCommand(type, json);
const auto command = createCommand(type, json);

if (command == nullptr)
{
return CommandManagerResponse({{"command", type}, {"error", "Unknown command"}});
}
if (command == nullptr)
{
return CommandManagerResponse({{"command", type}, {"error", "Unknown command"}});
}

return CommandManagerResponse(nlohmann::json{{"result", command()}});
return CommandManagerResponse(nlohmann::json{{"result", command()}});
}
Loading