From 2ca0174f0f30db6c15eecc3a7328c509da34e896 Mon Sep 17 00:00:00 2001 From: Zdzislaw Goik Date: Wed, 14 Jun 2023 15:30:17 +0200 Subject: [PATCH] Add pinout and environments for ESP32S3 Xiao Sense boards (#52) * Add pinout and environments for ESP32S3 Xiao Sense boards * Add opi memory_type to fix psram issues * fix: multiple typos or copy paste issues * fix: fix the XIAO ESP32S3 board type * fix: xaio crashing when allocating * fix: xaio crashing when allocating * fix: experiment with qio * fix: add some basic logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: add some more logging * fix: try to increase the stack size for the task * chore: enable wifi * ci(ci-gha); fix github actions failing * ci(ci-gha); fix github actions failing * ci(ci-gh): removing update logic from CI - i editing the docker container itself to be up-to-date * ci(ci-test): testing new gh action matrix format * ci(ci-test): testing new gh action matrix format * ci(ci-test): testing new gh action matrix format * ci(ci-test): testing new gh action matrix format * fix: fix esp32s3 xiao wifi - fix LED pin issue - force newest espressif toolchain - clean up pinout defines - add lots of logging - move strings into wifi handler - upgrade to c++17 * fix: fix esp32s3 xiao wifi - fix syntax error in wifihandler * fix: error handling in camera handler * fix: bug in wifi config saving routine - refactor lib - fix bug in wifi config logic - clean up --------- Co-authored-by: Sebastian Fitt <9294002+Blu3u@users.noreply.github.com> Co-authored-by: DaOfficialWizard <45744329+ZanzyTHEbar@users.noreply.github.com> --- .github/workflows/build_release_bins.yml | 23 +-- ESP.code-workspace | 166 +++++++++++------- ESP/ini/boards.ini | 49 +++++- ESP/ini/dev_config.ini | 8 +- ESP/ini/pinouts.ini | 77 +++++--- ESP/lib/src/data/config/project_config.cpp | 8 +- ESP/lib/src/io/camera/cameraHandler.cpp | 30 +++- .../src/network/wifihandler/wifihandler.cpp | 21 ++- .../src/network/wifihandler/wifihandler.hpp | 1 - ESP/lib/src/openiris.hpp | 20 +++ ESP/lib/src/usb/etvr_eye_tracker_usb.cpp | 10 +- ESP/src/main.cpp | 32 ++-- 12 files changed, 295 insertions(+), 150 deletions(-) create mode 100644 ESP/lib/src/openiris.hpp diff --git a/.github/workflows/build_release_bins.yml b/.github/workflows/build_release_bins.yml index 5508b4e..f723c3f 100644 --- a/.github/workflows/build_release_bins.yml +++ b/.github/workflows/build_release_bins.yml @@ -23,13 +23,19 @@ permissions: contents: write jobs: + setup: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - id: set-matrix + run: echo "matrix={\"target_name\":[\"esp32AIThinker\",\"esp32M5Stack\",\"esp32Cam\",\"esp_eye\",\"wrover\",\"wrooms3QIO\",\"wrooms3QIOUSB\",\"wrooms3\",\"wrooms3USB\"],\"target_build_type\":[\"\", \"_release\"]}" >> $GITHUB_OUTPUT + build: + needs: setup strategy: fail-fast: false - matrix: - target_name: - [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrooms3QIO, wrooms3QIOUSB, wrooms3, wrooms3USB] - target_build_type: ["", _release] #, _OTA] # OTA is not needed + matrix: ${{fromJson(needs.setup.outputs.matrix)}} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -45,6 +51,7 @@ jobs: export OPENIRIS_CI_BUILD=1 mkdir build mkdir build/${{ matrix.target_name }}${{ matrix.target_build_type }} + echo "::endgroup::" echo "::group::pio run" pio run --environment ${{ matrix.target_name }}${{ matrix.target_build_type }} echo "::endgroup::" @@ -99,15 +106,11 @@ jobs: chmod +x ./repo-tools/scripts/prepareCMD.sh semantic-release cleanup: + needs: [setup, release-openiris] strategy: fail-fast: false - matrix: - target_name: - [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrooms3QIO, wrooms3QIOUSB, wrooms3, wrooms3USB] - target_build_type: ["", _release] + matrix: ${{fromJson(needs.setup.outputs.matrix)}} name: Cleanup actions - needs: - - release-openiris runs-on: ubuntu-latest timeout-minutes: 10 steps: diff --git a/ESP.code-workspace b/ESP.code-workspace index f8dfb24..f06f60b 100644 --- a/ESP.code-workspace +++ b/ESP.code-workspace @@ -1,69 +1,99 @@ { - "folders": [ - { - "path": "ESP" - } - ], - "settings": { - "files.associations": { - "*.Rmd": "rmd", - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "map": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "regex": "cpp", - "set": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "iostream": "cpp" - }, - "cSpell.words": [ - "ESPS", - "JTAG", - "sccb" - ] - } -} \ No newline at end of file + "folders": [ + { + "name": "ESP Source Code", + "path": "ESP" + }, + { + "name": "Repo Root", + "path": "." + } + ], + "settings": { + "cSpell.words": [ + "cctype", + "cinttypes", + "clocale", + "cmath", + "cstdarg", + "cstddef", + "cstdint", + "cstdio", + "cstdlib", + "cstring", + "cwchar", + "cwctype", + "deque", + "ESPS", + "fstream", + "iomanip", + "iosfwd", + "iostream", + "istream", + "JTAG", + "ostream", + "sccb", + "sstream", + "stdexcept", + "streambuf", + "txpower", + "typeinfo", + "XIAO" + ], + "files.associations": { + "*.Rmd": "rmd", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "regex": "cpp", + "set": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "iostream": "cpp" + } + } +} diff --git a/ESP/ini/boards.ini b/ESP/ini/boards.ini index e559fd9..9d3e99f 100644 --- a/ESP/ini/boards.ini +++ b/ESP/ini/boards.ini @@ -98,30 +98,27 @@ build_flags = ${env.build_flags} [env:wrooms3QIO] board = esp32-s3-devkitc-1 -board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio build_type = debug build_flags = ${env.build_flags} -DCORE_DEBUG_LEVEL=4 -DDEBUG_MODE=1 - -DARDUINO_USB_CDC_ON_BOOT=1 - -DETVR_EYE_TRACKER_USB_API ${pinoutsESPS3WROVER.build_flags} upload_flags = --no-stub [env:wrooms3QIO_release] board = esp32-s3-devkitc-1 -board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 -DCORE_DEBUG_LEVEL=1 - -DARDUINO_USB_CDC_ON_BOOT=1 ${pinoutsESPS3WROVER.build_flags} upload_flags = --no-stub [env:wrooms3QIOUSB] board = esp32-s3-devkitc-1 -board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio build_type = debug build_flags = ${env.build_flags} -DCORE_DEBUG_LEVEL=4 @@ -132,7 +129,7 @@ build_flags = ${env.build_flags} [env:wrooms3QIOUSB_release] board = esp32-s3-devkitc-1 -board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 @@ -176,3 +173,41 @@ build_flags = ${env.build_flags} -DETVR_EYE_TRACKER_USB_API ${pinoutsESPS3WROOM.build_flags} upload_flags = --no-stub + +[env:xiaosenses3] +board = seeed_xiao_esp32s3 +build_type = debug +build_flags = ${env.build_flags} + -DCORE_DEBUG_LEVEL=4 + -DDEBUG_MODE=1 + #-DARDUINO_USB_MODE=1 + #-DARDUINO_USB_CDC_ON_BOOT=1 + ${pinoutsESPS3XIAOSENSE.build_flags} + +[env:xiaosenses3_USB] +board = seeed_xiao_esp32s3 +build_type = debug +build_flags = ${env.build_flags} + -DCORE_DEBUG_LEVEL=4 + -DDEBUG_MODE=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3XIAOSENSE.build_flags} +upload_flags = --no-stub + +[env:xiaosenses3_release] +board = seeed_xiao_esp32s3 +build_type = release +build_flags = ${env.build_flags} + -DDEBUG_MODE=0 + -DCORE_DEBUG_LEVEL=1 + ${pinoutsESPS3XIAOSENSE.build_flags} + +[env:xiaosenses3_USB_release] +board = seeed_xiao_esp32s3 +build_type = release +build_flags = ${env.build_flags} + -DDEBUG_MODE=0 + -DCORE_DEBUG_LEVEL=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3XIAOSENSE.build_flags} +upload_flags = --no-stub diff --git a/ESP/ini/dev_config.ini b/ESP/ini/dev_config.ini index ad99ae0..ac83e77 100644 --- a/ESP/ini/dev_config.ini +++ b/ESP/ini/dev_config.ini @@ -2,7 +2,7 @@ # IF YOU ARE A USER DO NOT TOUCH THIS FILE [env] -platform = espressif32 +platform = https://github.com/platformio/platform-espressif32.git framework = arduino monitor_speed = 115200 custom_firmware_version = 2.2.3 @@ -19,7 +19,7 @@ lib_ldf_mode = deep+ ;115200 is used for compatability - if you are on windows and want the code to flash faster use 921600 upload_speed = 921600 lib_deps = - esp32-camera + https://github.com/espressif/esp32-camera https://github.com/me-no-dev/ESPAsyncWebServer.git https://github.com/me-no-dev/AsyncTCP.git extra_scripts = @@ -29,7 +29,7 @@ build_flags = -DENABLE_ADHOC=${wifi.enableadhoc} -DADHOC_CHANNEL=${wifi.adhocchannel} -DWIFI_CHANNEL=${wifi.channel} - -DDEBUG_ESP_PORT=Serial + #-DDEBUG_ESP_PORT=Serial '-DVERSION=""' ; set the debug port '-DMDNS_HOSTNAME=${wifi.mdnsname}' ; Set the OTA password '-DWIFI_SSID=${wifi.ssid}' @@ -48,6 +48,8 @@ build_flags = # Comment these out if you are not using psram -DBOARD_HAS_PSRAM ; enable psram + -std=gnu++17 ; enable c++17 -mfix-esp32-psram-cache-issue ; fix for psram ; Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run faster -DHTTP_PARSER_STRICT=0 +build_unflags = -std=gnu++11 diff --git a/ESP/ini/pinouts.ini b/ESP/ini/pinouts.ini index 6ac2ce1..ab01eaf 100644 --- a/ESP/ini/pinouts.ini +++ b/ESP/ini/pinouts.ini @@ -203,8 +203,8 @@ vsync_gpio_num = 6 href_gpio_num = 7 pclk_gpio_num = 13 build_flags = - '-DCAMERA_MODULE_NAME="ESPS3WROVER"' - -DCONFIG_CAMERA_MODULE_ESPS3WROVER=1 + '-DCAMERA_MODULE_NAME="ESP32S3_WROVER"' + -DCONFIG_CAMERA_MODULE_ESPS3_WROVER=1 -DPWDN_GPIO_NUM=${pinoutsESPS3WROVER.PWDN_GPIO_NUM} -DRESET_GPIO_NUM=${pinoutsESPS3WROVER.RESET_GPIO_NUM} -DXCLK_GPIO_NUM=${pinoutsESPS3WROVER.XCLK_GPIO_NUM} @@ -240,21 +240,58 @@ vsync_gpio_num = 6 href_gpio_num = 7 pclk_gpio_num = 13 build_flags = - '-DCAMERA_MODULE_NAME="ESPS3WROOM"' - -DCONFIG_CAMERA_MODULE_ESPS3WROOM=1 - -DPWDN_GPIO_NUM=${pinoutsESPS3WROVER.PWDN_GPIO_NUM} - -DRESET_GPIO_NUM=${pinoutsESPS3WROVER.RESET_GPIO_NUM} - -DXCLK_GPIO_NUM=${pinoutsESPS3WROVER.XCLK_GPIO_NUM} - -DSIOD_GPIO_NUM=${pinoutsESPS3WROVER.SIOD_GPIO_NUM} - -DSIOC_GPIO_NUM=${pinoutsESPS3WROVER.SIOC_GPIO_NUM} - -DY9_GPIO_NUM=${pinoutsESPS3WROVER.Y9_GPIO_NUM} - -DY8_GPIO_NUM=${pinoutsESPS3WROVER.Y8_GPIO_NUM} - -DY7_GPIO_NUM=${pinoutsESPS3WROVER.Y7_GPIO_NUM} - -DY6_GPIO_NUM=${pinoutsESPS3WROVER.Y6_GPIO_NUM} - -DY5_GPIO_NUM=${pinoutsESPS3WROVER.Y5_GPIO_NUM} - -DY4_GPIO_NUM=${pinoutsESPS3WROVER.Y4_GPIO_NUM} - -DY3_GPIO_NUM=${pinoutsESPS3WROVER.Y3_GPIO_NUM} - -DY2_GPIO_NUM=${pinoutsESPS3WROVER.Y2_GPIO_NUM} - -DVSYNC_GPIO_NUM=${pinoutsESPS3WROVER.VSYNC_GPIO_NUM} - -DHREF_GPIO_NUM=${pinoutsESPS3WROVER.HREF_GPIO_NUM} - -DPCLK_GPIO_NUM=${pinoutsESPS3WROVER.PCLK_GPIO_NUM} + '-DCAMERA_MODULE_NAME="ESP32S3_WROOM"' + -DCONFIG_CAMERA_MODULE_ESP32S3_WROOM=1 + -DPWDN_GPIO_NUM=${pinoutsESPS3WROOM.PWDN_GPIO_NUM} + -DRESET_GPIO_NUM=${pinoutsESPS3WROOM.RESET_GPIO_NUM} + -DXCLK_GPIO_NUM=${pinoutsESPS3WROOM.XCLK_GPIO_NUM} + -DSIOD_GPIO_NUM=${pinoutsESPS3WROOM.SIOD_GPIO_NUM} + -DSIOC_GPIO_NUM=${pinoutsESPS3WROOM.SIOC_GPIO_NUM} + -DY9_GPIO_NUM=${pinoutsESPS3WROOM.Y9_GPIO_NUM} + -DY8_GPIO_NUM=${pinoutsESPS3WROOM.Y8_GPIO_NUM} + -DY7_GPIO_NUM=${pinoutsESPS3WROOM.Y7_GPIO_NUM} + -DY6_GPIO_NUM=${pinoutsESPS3WROOM.Y6_GPIO_NUM} + -DY5_GPIO_NUM=${pinoutsESPS3WROOM.Y5_GPIO_NUM} + -DY4_GPIO_NUM=${pinoutsESPS3WROOM.Y4_GPIO_NUM} + -DY3_GPIO_NUM=${pinoutsESPS3WROOM.Y3_GPIO_NUM} + -DY2_GPIO_NUM=${pinoutsESPS3WROOM.Y2_GPIO_NUM} + -DVSYNC_GPIO_NUM=${pinoutsESPS3WROOM.VSYNC_GPIO_NUM} + -DHREF_GPIO_NUM=${pinoutsESPS3WROOM.HREF_GPIO_NUM} + -DPCLK_GPIO_NUM=${pinoutsESPS3WROOM.PCLK_GPIO_NUM} + +[pinoutsESPS3XIAOSENSE] +pwdn_gpio_num = -1 +reset_gpio_num = -1 +xclk_gpio_num = 10 +siod_gpio_num = 40 +sioc_gpio_num = 39 +y9_gpio_num = 48 +y8_gpio_num = 11 +y7_gpio_num = 12 +y6_gpio_num = 14 +y5_gpio_num = 16 +y4_gpio_num = 18 +y3_gpio_num = 17 +y2_gpio_num = 15 +vsync_gpio_num = 38 +href_gpio_num = 47 +pclk_gpio_num = 13 +build_flags = + '-DCAMERA_MODULE_NAME="ESP32S3_XIAO_SENSE"' + -DCONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE=1 + -DPWDN_GPIO_NUM=${pinoutsESPS3XIAOSENSE.PWDN_GPIO_NUM} + -DRESET_GPIO_NUM=${pinoutsESPS3XIAOSENSE.RESET_GPIO_NUM} + -DXCLK_GPIO_NUM=${pinoutsESPS3XIAOSENSE.XCLK_GPIO_NUM} + -DSIOD_GPIO_NUM=${pinoutsESPS3XIAOSENSE.SIOD_GPIO_NUM} + -DSIOC_GPIO_NUM=${pinoutsESPS3XIAOSENSE.SIOC_GPIO_NUM} + -DY9_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y9_GPIO_NUM} + -DY8_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y8_GPIO_NUM} + -DY7_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y7_GPIO_NUM} + -DY6_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y6_GPIO_NUM} + -DY5_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y5_GPIO_NUM} + -DY4_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y4_GPIO_NUM} + -DY3_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y3_GPIO_NUM} + -DY2_GPIO_NUM=${pinoutsESPS3XIAOSENSE.Y2_GPIO_NUM} + -DVSYNC_GPIO_NUM=${pinoutsESPS3XIAOSENSE.VSYNC_GPIO_NUM} + -DHREF_GPIO_NUM=${pinoutsESPS3XIAOSENSE.HREF_GPIO_NUM} + -DPCLK_GPIO_NUM=${pinoutsESPS3XIAOSENSE.PCLK_GPIO_NUM} diff --git a/ESP/lib/src/data/config/project_config.cpp b/ESP/lib/src/data/config/project_config.cpp index 0ad5bd5..e0398c8 100644 --- a/ESP/lib/src/data/config/project_config.cpp +++ b/ESP/lib/src/data/config/project_config.cpp @@ -33,7 +33,7 @@ void ProjectConfig::initConfig() { this->config.device = {OTA_LOGIN, OTA_PASSWORD, 3232}; if (_mdnsName.empty()) { - log_e("MDNS name is null\n Autoassigning name to 'openiristracker'"); + log_e("MDNS name is null\n Auto-assigning name to 'openiristracker'"); _mdnsName = "openiristracker"; } this->config.mdns = { @@ -146,6 +146,8 @@ void ProjectConfig::load() { return; } + initConfig(); + /* Device Config */ this->config.device.OTALogin = getString("OTALogin", "openiris").c_str(); this->config.device.OTAPassword = @@ -278,7 +280,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName, if (shouldNotify) { wifiStateManager.setState(WiFiState_e::WiFiState_Disconnected); - WiFi.disconnect(); + //WiFi.disconnect(); this->wifiConfigSave(); this->notifyAll(ConfigState_e::networksConfigUpdated); } @@ -307,7 +309,7 @@ void ProjectConfig::setWifiConfig(const std::string& networkName, if (shouldNotify) { wifiStateManager.setState(WiFiState_e::WiFiState_None); - WiFi.disconnect(); + //WiFi.disconnect(); this->wifiConfigSave(); this->notifyAll(ConfigState_e::networksConfigUpdated); } diff --git a/ESP/lib/src/io/camera/cameraHandler.cpp b/ESP/lib/src/io/camera/cameraHandler.cpp index eb1b78a..9277ceb 100644 --- a/ESP/lib/src/io/camera/cameraHandler.cpp +++ b/ESP/lib/src/io/camera/cameraHandler.cpp @@ -6,9 +6,9 @@ CameraHandler::CameraHandler(ProjectConfig& configManager) void CameraHandler::setupCameraPinout() { // Workaround for espM5SStack not having a defined camera #ifdef CAMERA_MODULE_NAME - log_i("Camera module is %s", CAMERA_MODULE_NAME); + log_i("[Camera]: Camera module is %s", CAMERA_MODULE_NAME); #else - log_i("Camera module is undefined"); + log_i("[Camera]: Camera module is undefined"); #endif // camera external clock signal frequencies @@ -67,20 +67,23 @@ void CameraHandler::setupBasicResolution() { config.frame_size = FRAMESIZE_240X240; if (!psramFound()) { - log_e("Did not find psram, setting lower image quality"); + log_e("[Camera]: Did not find psram, setting lower image quality"); config.fb_location = CAMERA_FB_IN_DRAM; config.jpeg_quality = 9; config.fb_count = 2; return; } - log_d("Found psram, setting the higher image quality"); + log_d("[Camera]: Found psram, setting the higher image quality"); config.jpeg_quality = 7; // 0-63 lower number = higher quality, more latency // and less fps 7 for most fps, 5 for best quality config.fb_count = 3; + log_d("[Camera]: Setting fb_location to CAMERA_FB_IN_PSRAM"); } void CameraHandler::setupCameraSensor() { + log_d("[Camera]: Setting up camera sensor"); + camera_sensor = esp_camera_sensor_get(); // fixes corrupted jpegs, https://github.com/espressif/esp32-camera/issues/203 // documentation https://www.uctronics.com/download/cam_module/OV2640DS.pdf @@ -135,18 +138,27 @@ void CameraHandler::setupCameraSensor() { camera_sensor, 2); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, // 4 - Green Tint, 5 - Blue Tint, 6 - Sepia) + + log_d("[Camera]: Setting up camera sensor done"); } bool CameraHandler::setupCamera() { + log_d("[Camera]: Setting up camera pinout"); this->setupCameraPinout(); + log_d("[Camera]: Setting up camera with resolution"); this->setupBasicResolution(); - esp_err_t hasCameraBeenInitialized = esp_camera_init(&config); + log_d("[Camera]: Initializing camera..."); + esp_err_t hasCameraBeenInitialized = esp_camera_init(&config); + log_d("[Camera]: Camera initialized: %s \r\n", + esp_err_to_name(hasCameraBeenInitialized)); if (hasCameraBeenInitialized != ESP_OK) { - log_e("Camera initialization failed with error: 0x%x \r\n", - hasCameraBeenInitialized); + log_e("[Camera]: Camera initialization failed with error: %s \r\n", + esp_err_to_name(hasCameraBeenInitialized)); log_e( - "Camera most likely not seated properly in the socket. Please fix the " + "[Camera]: Camera most likely not seated properly in the socket. " + "Please " + "fix the " "camera and reboot the device.\r\n"); ledStateManager.setState(LEDStates_e::_Camera_Error); return false; @@ -157,12 +169,14 @@ bool CameraHandler::setupCamera() { } void CameraHandler::loadConfigData() { + log_d("[Camera]: Loading camera config data"); ProjectConfig::CameraConfig_t cameraConfig = configManager.getCameraConfig(); this->setHFlip(cameraConfig.href); this->setVFlip(cameraConfig.vflip); this->setCameraResolution((framesize_t)cameraConfig.framesize); camera_sensor->set_quality(camera_sensor, cameraConfig.quality); camera_sensor->set_agc_gain(camera_sensor, cameraConfig.brightness); + log_d("Loading camera config data done"); } int CameraHandler::setCameraResolution(framesize_t frameSize) { diff --git a/ESP/lib/src/network/wifihandler/wifihandler.cpp b/ESP/lib/src/network/wifihandler/wifihandler.cpp index 0c191f8..9e944ee 100644 --- a/ESP/lib/src/network/wifihandler/wifihandler.cpp +++ b/ESP/lib/src/network/wifihandler/wifihandler.cpp @@ -8,8 +8,8 @@ WiFiHandler::WiFiHandler(ProjectConfig& configManager, const std::string& password, uint8_t channel) : configManager(configManager), - ssid(ssid), - password(password), + ssid(std::move(ssid)), + password(std::move(password)), channel(channel), power(0), _enable_adhoc(false) {} @@ -17,14 +17,23 @@ WiFiHandler::WiFiHandler(ProjectConfig& configManager, WiFiHandler::~WiFiHandler() {} void WiFiHandler::begin() { + log_i("Starting WiFi Handler \n\r"); if (this->_enable_adhoc || wifiStateManager.getCurrentState() == WiFiState_e::WiFiState_ADHOC) { + log_d("ADHOC is enabled, setting up ADHOC network \n\r"); this->setUpADHOC(); return; } + + log_d( + "ADHOC is disabled, setting up STA network and checking transmission " + "power \n\r"); auto txpower = configManager.getWiFiTxPowerConfig(); - WiFi.mode(WIFI_STA); - WiFi.setSleep(WIFI_PS_NONE); + log_d("Setting Wifi Power to: %d", txpower.power); + // log_d("Enabling STA mode \n\r"); + // WiFi.mode(WIFI_STA); + log_d("Setting WiFi sleep mode to NONE \n\r"); + WiFi.setSleep(false); log_i("Initializing connection to wifi \n\r"); wifiStateManager.setState(WiFiState_e::WiFiState_Connecting); @@ -126,12 +135,14 @@ bool WiFiHandler::iniSTA(const std::string& ssid, wifiStateManager.setState(WiFiState_e::WiFiState_Connecting); log_i("Trying to connect to: %s \n\r", ssid.c_str()); - auto mdnsConfig = configManager.getMDNSConfig(); + + log_d("Setting hostname %s \n\r"); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); // need to call before setting hostname WiFi.setHostname(mdnsConfig.hostname.c_str()); WiFi.begin(ssid.c_str(), password.c_str(), channel); + log_d("Waiting for WiFi to connect... \n\r"); while (WiFi.status() != WL_CONNECTED) { progress++; currentMillis = millis(); diff --git a/ESP/lib/src/network/wifihandler/wifihandler.hpp b/ESP/lib/src/network/wifihandler/wifihandler.hpp index 11cdab0..c83ef46 100644 --- a/ESP/lib/src/network/wifihandler/wifihandler.hpp +++ b/ESP/lib/src/network/wifihandler/wifihandler.hpp @@ -16,7 +16,6 @@ class WiFiHandler : public IObserver { void update(ConfigState_e event) override; std::string getName() override; - bool _enable_adhoc; private: diff --git a/ESP/lib/src/openiris.hpp b/ESP/lib/src/openiris.hpp new file mode 100644 index 0000000..7316fdd --- /dev/null +++ b/ESP/lib/src/openiris.hpp @@ -0,0 +1,20 @@ +#ifndef OPENIRIS_HPP +#define OPENIRIS_HPP + +#include + +#include +#include +#include +#include + +#ifndef ETVR_EYE_TRACKER_USB_API +#include +#include +#include +#include +#else +#include +#endif // ETVR_EYE_TRACKER_WEB_API + +#endif // OPENIRIS_HPP diff --git a/ESP/lib/src/usb/etvr_eye_tracker_usb.cpp b/ESP/lib/src/usb/etvr_eye_tracker_usb.cpp index 331c695..216d236 100644 --- a/ESP/lib/src/usb/etvr_eye_tracker_usb.cpp +++ b/ESP/lib/src/usb/etvr_eye_tracker_usb.cpp @@ -37,11 +37,11 @@ void etvr_eye_tracker_usb_loop() { } if (err == ESP_OK) Serial.write(ETVR_HEADER, 2); - Serial.write(ETVR_HEADER_FRAME, 2); - len_bytes[0] = len & 0xFF; - len_bytes[1] = (len >> CHAR_BIT) & 0xFF; - Serial.write(len_bytes, 2); - Serial.write((const char*)buf, len); + Serial.write(ETVR_HEADER_FRAME, 2); + len_bytes[0] = len & 0xFF; + len_bytes[1] = (len >> CHAR_BIT) & 0xFF; + Serial.write(len_bytes, 2); + Serial.write((const char*)buf, len); if (fb) { esp_camera_fb_return(fb); fb = NULL; diff --git a/ESP/src/main.cpp b/ESP/src/main.cpp index daa4c4d..05c3c04 100644 --- a/ESP/src/main.cpp +++ b/ESP/src/main.cpp @@ -1,18 +1,4 @@ -#include - -#include -#include -#include -#include - -#ifndef ETVR_EYE_TRACKER_USB_API -#include -#include -#include -#include -#else -#include -#endif // ETVR_EYE_TRACKER_WEB_API +#include /** * @brief ProjectConfig object @@ -22,7 +8,11 @@ */ ProjectConfig deviceConfig("openiris", MDNS_HOSTNAME); +#ifdef CONFIG_CAMERA_MODULE_ESP32S3_XIAO_SENSE +LEDManager ledManager(LED_BUILTIN); +#else LEDManager ledManager(33); +#endif // ESP32S3_XIAO_SENSE #ifndef SIM_ENABLED CameraHandler cameraHandler(deviceConfig); @@ -39,10 +29,14 @@ StreamServer streamServer; #endif // SIM_ENABLED void etvr_eye_tracker_web_init() { - deviceConfig.attach(mdnsHandler); - //deviceConfig.attach(wifiHandler); + log_d("[SETUP]: Starting Network Handler"); + // deviceConfig.attach(wifiHandler); + log_d("[SETUP]: Checking ADHOC Settings"); wifiHandler._enable_adhoc = ENABLE_ADHOC; + deviceConfig.attach(mdnsHandler); + log_d("[SETUP]: Starting WiFi Handler"); wifiHandler.begin(); + log_d("[SETUP]: Starting MDNS Handler"); mdnsHandler.startMDNS(); switch (wifiStateManager.getCurrentState()) { @@ -84,14 +78,12 @@ void setup() { setCpuFrequencyMhz(240); Serial.begin(115200); Logo::printASCII(); - Serial.flush(); + // Serial.flush(); ledManager.begin(); #ifndef SIM_ENABLED deviceConfig.attach(cameraHandler); #endif // SIM_ENABLED - - deviceConfig.initConfig(); deviceConfig.load(); #ifndef ETVR_EYE_TRACKER_USB_API