mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-13 11:43:44 +02:00
Begin porting OpenIris from platformio to ESP-IDF, wifi works, blinking works, Preferences work, flashing etc works, configuration for xiaos works
This commit is contained in:
47
.devcontainer/Dockerfile
Normal file
47
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
||||
FROM espressif/idf
|
||||
|
||||
ARG DEBIAN_FRONTEND=nointeractive
|
||||
ARG CONTAINER_USER=esp
|
||||
ARG USER_UID=1050
|
||||
ARG USER_GID=$USER_UID
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt install -y -q \
|
||||
cmake \
|
||||
git \
|
||||
libglib2.0-0 \
|
||||
libnuma1 \
|
||||
libpixman-1-0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# QEMU
|
||||
ENV QEMU_REL=esp_develop_8.2.0_20240122
|
||||
ENV QEMU_SHA256=e7c72ef5705ad1444d391711088c8717fc89f42e9bf6d1487f9c2a326b8cfa83
|
||||
ENV QEMU_DIST=qemu-xtensa-softmmu-${QEMU_REL}-x86_64-linux-gnu.tar.xz
|
||||
ENV QEMU_URL=https://github.com/espressif/qemu/releases/download/esp-develop-8.2.0-20240122/${QEMU_DIST}
|
||||
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
RUN wget --no-verbose ${QEMU_URL} \
|
||||
&& echo "${QEMU_SHA256} *${QEMU_DIST}" | sha256sum --check --strict - \
|
||||
&& tar -xf $QEMU_DIST -C /opt \
|
||||
&& rm ${QEMU_DIST}
|
||||
|
||||
ENV PATH=/opt/qemu/bin:${PATH}
|
||||
|
||||
RUN groupadd --gid $USER_GID $CONTAINER_USER \
|
||||
&& adduser --uid $USER_UID --gid $USER_GID --disabled-password --gecos "" ${CONTAINER_USER} \
|
||||
&& usermod -a -G root $CONTAINER_USER && usermod -a -G dialout $CONTAINER_USER
|
||||
|
||||
RUN chmod -R 775 /opt/esp/python_env/
|
||||
|
||||
USER ${CONTAINER_USER}
|
||||
ENV USER=${CONTAINER_USER}
|
||||
WORKDIR /home/${CONTAINER_USER}
|
||||
|
||||
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||
|
||||
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||
|
||||
CMD ["/bin/bash", "-c"]
|
||||
36
.devcontainer/devcontainer.json
Normal file
36
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "ESP-IDF QEMU",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"terminal.integrated.defaultProfile.linux": "bash",
|
||||
"idf.espIdfPath": "/opt/esp/idf",
|
||||
"idf.customExtraPaths": "",
|
||||
"idf.pythonBinPath": "/opt/esp/python_env/idf5.4_py3.12_env/bin/python",
|
||||
"idf.toolsPath": "/opt/esp",
|
||||
"idf.gitPath": "/usr/bin/git"
|
||||
},
|
||||
"extensions": [
|
||||
"espressif.esp-idf-extension"
|
||||
]
|
||||
},
|
||||
"codespaces": {
|
||||
"settings": {
|
||||
"terminal.integrated.defaultProfile.linux": "bash",
|
||||
"idf.espIdfPath": "/opt/esp/idf",
|
||||
"idf.customExtraPaths": "",
|
||||
"idf.pythonBinPath": "/opt/esp/python_env/idf5.4_py3.12_env/bin/python",
|
||||
"idf.toolsPath": "/opt/esp",
|
||||
"idf.gitPath": "/usr/bin/git"
|
||||
},
|
||||
"extensions": [
|
||||
"espressif.esp-idf-extension",
|
||||
"espressif.esp-idf-web"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runArgs": ["--privileged"]
|
||||
}
|
||||
23
.vscode/c_cpp_properties.json
vendored
Normal file
23
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "ESP-IDF",
|
||||
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-13.2.0_20240530\\xtensa-esp-elf\\bin\\xtensa-esp32s3-elf-gcc.exe",
|
||||
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||
"includePath": [
|
||||
"${config:idf.espIdfPath}/components/**",
|
||||
"${config:idf.espIdfPathWin}/components/**",
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"browse": {
|
||||
"path": [
|
||||
"${config:idf.espIdfPath}/components",
|
||||
"${config:idf.espIdfPathWin}/components",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdbtarget",
|
||||
"request": "attach",
|
||||
"name": "Eclipse CDT GDB Adapter"
|
||||
},
|
||||
{
|
||||
"type": "espidf",
|
||||
"name": "Launch",
|
||||
"request": "launch"
|
||||
}
|
||||
]
|
||||
}
|
||||
84
.vscode/settings.json
vendored
Normal file
84
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "default",
|
||||
"idf.portWin": "COM3",
|
||||
"idf.flashType": "UART",
|
||||
"idf.adapterTargetName": "esp32s3",
|
||||
"idf.openOcdConfigs": [
|
||||
"board/esp32s3-builtin.cfg"
|
||||
],
|
||||
"files.associations": {
|
||||
"esp_camera.h": "c",
|
||||
"gpio.h": "c",
|
||||
"customsomething.hpp": "c",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"netfwd": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"regex": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"format": "cpp",
|
||||
"fstream": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"span": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp"
|
||||
}
|
||||
}
|
||||
259
.vscode/tasks.json
vendored
Normal file
259
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build - Build project",
|
||||
"type": "shell",
|
||||
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py build",
|
||||
"windows": {
|
||||
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py build",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||
}
|
||||
},
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Set ESP-IDF Target",
|
||||
"type": "shell",
|
||||
"command": "${command:espIdf.setTarget}",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Clean - Clean the project",
|
||||
"type": "shell",
|
||||
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py fullclean",
|
||||
"windows": {
|
||||
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py fullclean",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||
}
|
||||
},
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Flash - Flash the device",
|
||||
"type": "shell",
|
||||
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} -b ${config:idf.flashBaudRate} flash",
|
||||
"windows": {
|
||||
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py flash -p ${config:idf.portWin} -b ${config:idf.flashBaudRate}",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||
}
|
||||
},
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "Monitor: Start the monitor",
|
||||
"type": "shell",
|
||||
"command": "${config:idf.pythonBinPath} ${config:idf.espIdfPath}/tools/idf.py -p ${config:idf.port} monitor",
|
||||
"windows": {
|
||||
"command": "${config:idf.pythonBinPathWin} ${config:idf.espIdfPathWin}\\tools\\idf.py -p ${config:idf.portWin} monitor",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||
}
|
||||
},
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
],
|
||||
"dependsOn": "Flash - Flash the device"
|
||||
},
|
||||
{
|
||||
"label": "OpenOCD: Start openOCD",
|
||||
"type": "shell",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "never",
|
||||
"focus": false,
|
||||
"panel": "new"
|
||||
},
|
||||
"command": "openocd -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}",
|
||||
"windows": {
|
||||
"command": "openocd.exe -s ${command:espIdf.getOpenOcdScriptValue} ${command:espIdf.getOpenOcdConfigs}",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}"
|
||||
}
|
||||
},
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "adapter",
|
||||
"type": "shell",
|
||||
"command": "${config:idf.pythonBinPath}",
|
||||
"isBackground": true,
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH}:${config:idf.customExtraPaths}",
|
||||
"PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter"
|
||||
}
|
||||
},
|
||||
"problemMatcher": {
|
||||
"background": {
|
||||
"beginsPattern": "\bDEBUG_ADAPTER_STARTED\b",
|
||||
"endsPattern": "DEBUG_ADAPTER_READY2CONNECT",
|
||||
"activeOnStart": true
|
||||
},
|
||||
"pattern": {
|
||||
"regexp": "(\\d+)-(\\d+)-(\\d+)\\s(\\d+):(\\d+):(\\d+),(\\d+)\\s-(.+)\\s(ERROR)",
|
||||
"file": 8,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"message": 9
|
||||
}
|
||||
},
|
||||
"args": [
|
||||
"${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter_main.py",
|
||||
"-e",
|
||||
"${workspaceFolder}/build/${command:espIdf.getProjectName}.elf",
|
||||
"-s",
|
||||
"$OPENOCD_SCRIPTS",
|
||||
"-dn",
|
||||
"esp32",
|
||||
"-om",
|
||||
"connect_to_instance",
|
||||
"-t",
|
||||
"xtensa-esp32-elf-"
|
||||
|
||||
],
|
||||
"windows": {
|
||||
"command": "${config:idf.pythonBinPathWin}",
|
||||
"options": {
|
||||
"env": {
|
||||
"PATH": "${env:PATH};${config:idf.customExtraPaths}",
|
||||
"PYTHONPATH": "${command:espIdf.getExtensionPath}/esp_debug_adapter/debug_adapter"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/components)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(blink)
|
||||
69
README.md
Normal file
69
README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
|
||||
# Blink Example
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example demonstrates how to blink a LED by using the GPIO driver or using the [led_strip](https://components.espressif.com/component/espressif/led_strip) library if the LED is addressable e.g. [WS2812](https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf). The `led_strip` library is installed via [component manager](main/idf_component.yml).
|
||||
|
||||
## How to Use Example
|
||||
|
||||
Before project configuration and build, be sure to set the correct chip target using `idf.py set-target <chip_name>`.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
* A development board with normal LED or addressable LED on-board (e.g., ESP32-S3-DevKitC, ESP32-C6-DevKitC etc.)
|
||||
* A USB cable for Power supply and programming
|
||||
|
||||
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
|
||||
|
||||
### Configure the Project
|
||||
|
||||
Open the project configuration menu (`idf.py menuconfig`).
|
||||
|
||||
In the `Example Configuration` menu:
|
||||
|
||||
* Select the LED type in the `Blink LED type` option.
|
||||
* Use `GPIO` for regular LED
|
||||
* Use `LED strip` for addressable LED
|
||||
* If the LED type is `LED strip`, select the backend peripheral
|
||||
* `RMT` is only available for ESP targets with RMT peripheral supported
|
||||
* `SPI` is available for all ESP targets
|
||||
* Set the GPIO number used for the signal in the `Blink GPIO number` option.
|
||||
* Set the blinking period in the `Blink period in ms` option.
|
||||
|
||||
### Build and Flash
|
||||
|
||||
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example Output
|
||||
|
||||
As you run the example, you will see the LED blinking, according to the previously defined period. For the addressable LED, you can also change the LED color by setting the `led_strip_set_pixel(led_strip, 0, 16, 16, 16);` (LED Strip, Pixel Number, Red, Green, Blue) with values from 0 to 255 in the [source file](main/blink_example_main.c).
|
||||
|
||||
```text
|
||||
I (315) example: Example configured to blink addressable LED!
|
||||
I (325) example: Turning the LED OFF!
|
||||
I (1325) example: Turning the LED ON!
|
||||
I (2325) example: Turning the LED OFF!
|
||||
I (3325) example: Turning the LED ON!
|
||||
I (4325) example: Turning the LED OFF!
|
||||
I (5325) example: Turning the LED ON!
|
||||
I (6325) example: Turning the LED OFF!
|
||||
I (7325) example: Turning the LED ON!
|
||||
I (8325) example: Turning the LED OFF!
|
||||
```
|
||||
|
||||
Note: The color order could be different according to the LED model.
|
||||
|
||||
The pixel number indicates the pixel position in the LED strip. For a single LED, use 0.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
* If the LED isn't blinking, check the GPIO or the LED type selection in the `Example Configuration` menu.
|
||||
|
||||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
4
components/Preferences/CMakeLists.txt
Normal file
4
components/Preferences/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "Preferences/Preferences.cpp"
|
||||
INCLUDE_DIRS "Preferences"
|
||||
REQUIRES nvs_flash
|
||||
)
|
||||
668
components/Preferences/Preferences/Preferences.cpp
Normal file
668
components/Preferences/Preferences/Preferences.cpp
Normal file
@@ -0,0 +1,668 @@
|
||||
// source: https://github.com/espressif/arduino-esp32/blob/master/libraries/Preferences/src/Preferences.cpp
|
||||
// ported by: Lorow
|
||||
|
||||
#include "Preferences.hpp"
|
||||
|
||||
const char *PREFERENCES_TAG = "[PREFERENCES]";
|
||||
const char *nvs_errors[] = {"OTHER", "NOT_INITIALIZED", "NOT_FOUND", "TYPE_MISMATCH", "READ_ONLY", "NOT_ENOUGH_SPACE", "INVALID_NAME",
|
||||
"INVALID_HANDLE", "REMOVE_FAILED", "KEY_TOO_LONG", "PAGE_FULL", "INVALID_STATE", "INVALID_LENGTH"};
|
||||
#define nvs_error(e) (((e) > ESP_ERR_NVS_BASE) ? nvs_errors[(e) & ~(ESP_ERR_NVS_BASE)] : nvs_errors[0])
|
||||
|
||||
Preferences::Preferences() : _handle(0), _started(false), _readOnly(false) {}
|
||||
bool Preferences::begin(const char *name, bool readOnly, const char *partition_label)
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_readOnly = readOnly;
|
||||
esp_err_t err = ESP_OK;
|
||||
if (partition_label != NULL)
|
||||
{
|
||||
err = nvs_flash_init_partition(partition_label);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_flash_init_partition failed: %s", nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
err = nvs_open_from_partition(partition_label, name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nvs_open(name, readOnly ? NVS_READONLY : NVS_READWRITE, &_handle);
|
||||
}
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_open failed: %s", nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
_started = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Preferences::~Preferences()
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
void Preferences::end()
|
||||
{
|
||||
if (!_started)
|
||||
{
|
||||
return;
|
||||
}
|
||||
nvs_close(_handle);
|
||||
_started = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear all keys in opened preferences
|
||||
* */
|
||||
|
||||
bool Preferences::clear()
|
||||
{
|
||||
if (!_started || _readOnly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
esp_err_t err = nvs_erase_all(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_erase_all fail: %s", nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s", nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a key
|
||||
* */
|
||||
|
||||
bool Preferences::remove(const char *key)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_err_t err = nvs_erase_key(_handle, key);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_erase_key fail: %s %s", key, nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Put a key value
|
||||
* */
|
||||
|
||||
size_t Preferences::putChar(const char *key, int8_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_i8(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_i8 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t Preferences::putUChar(const char *key, uint8_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_u8(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_u8 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t Preferences::putShort(const char *key, int16_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_i16(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_i16 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
size_t Preferences::putUShort(const char *key, uint16_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_u16(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_u16 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
size_t Preferences::putInt(const char *key, int32_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_i32(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_i32 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
size_t Preferences::putUInt(const char *key, uint32_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_u32(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_u32 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
size_t Preferences::putLong(const char *key, int32_t value)
|
||||
{
|
||||
return putInt(key, value);
|
||||
}
|
||||
|
||||
size_t Preferences::putULong(const char *key, uint32_t value)
|
||||
{
|
||||
return putUInt(key, value);
|
||||
}
|
||||
|
||||
size_t Preferences::putLong64(const char *key, int64_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_i64(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_i64 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
|
||||
size_t Preferences::putULong64(const char *key, uint64_t value)
|
||||
{
|
||||
if (!_started || !key || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_u64(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_u64 fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return 8;
|
||||
}
|
||||
|
||||
size_t Preferences::putFloat(const char *key, const float_t value)
|
||||
{
|
||||
return putBytes(key, (void *)&value, sizeof(float_t));
|
||||
}
|
||||
|
||||
size_t Preferences::putDouble(const char *key, const double_t value)
|
||||
{
|
||||
return putBytes(key, (void *)&value, sizeof(double_t));
|
||||
}
|
||||
|
||||
size_t Preferences::putBool(const char *key, const bool value)
|
||||
{
|
||||
return putUChar(key, (uint8_t)(value ? 1 : 0));
|
||||
}
|
||||
|
||||
size_t Preferences::putString(const char *key, const char *value)
|
||||
{
|
||||
if (!_started || !key || !value || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_str(_handle, key, value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_str fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return strlen(value);
|
||||
}
|
||||
|
||||
size_t Preferences::putString(const char *key, const std::string value)
|
||||
{
|
||||
return putString(key, value.c_str());
|
||||
}
|
||||
|
||||
size_t Preferences::putBytes(const char *key, const void *value, size_t len)
|
||||
{
|
||||
if (!_started || !key || !value || !len || _readOnly)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_set_blob(_handle, key, value, len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_set_blob fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
err = nvs_commit(_handle);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_commit fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
PreferenceType Preferences::getType(const char *key)
|
||||
{
|
||||
if (!_started || !key || strlen(key) > 15)
|
||||
{
|
||||
return PT_INVALID;
|
||||
}
|
||||
int8_t mt1;
|
||||
uint8_t mt2;
|
||||
int16_t mt3;
|
||||
uint16_t mt4;
|
||||
int32_t mt5;
|
||||
uint32_t mt6;
|
||||
int64_t mt7;
|
||||
uint64_t mt8;
|
||||
size_t len = 0;
|
||||
if (nvs_get_i8(_handle, key, &mt1) == ESP_OK)
|
||||
{
|
||||
return PT_I8;
|
||||
}
|
||||
if (nvs_get_u8(_handle, key, &mt2) == ESP_OK)
|
||||
{
|
||||
return PT_U8;
|
||||
}
|
||||
if (nvs_get_i16(_handle, key, &mt3) == ESP_OK)
|
||||
{
|
||||
return PT_I16;
|
||||
}
|
||||
if (nvs_get_u16(_handle, key, &mt4) == ESP_OK)
|
||||
{
|
||||
return PT_U16;
|
||||
}
|
||||
if (nvs_get_i32(_handle, key, &mt5) == ESP_OK)
|
||||
{
|
||||
return PT_I32;
|
||||
}
|
||||
if (nvs_get_u32(_handle, key, &mt6) == ESP_OK)
|
||||
{
|
||||
return PT_U32;
|
||||
}
|
||||
if (nvs_get_i64(_handle, key, &mt7) == ESP_OK)
|
||||
{
|
||||
return PT_I64;
|
||||
}
|
||||
if (nvs_get_u64(_handle, key, &mt8) == ESP_OK)
|
||||
{
|
||||
return PT_U64;
|
||||
}
|
||||
if (nvs_get_str(_handle, key, NULL, &len) == ESP_OK)
|
||||
{
|
||||
return PT_STR;
|
||||
}
|
||||
if (nvs_get_blob(_handle, key, NULL, &len) == ESP_OK)
|
||||
{
|
||||
return PT_BLOB;
|
||||
}
|
||||
return PT_INVALID;
|
||||
}
|
||||
|
||||
bool Preferences::isKey(const char *key)
|
||||
{
|
||||
return getType(key) != PT_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a key value
|
||||
* */
|
||||
|
||||
int8_t Preferences::getChar(const char *key, const int8_t defaultValue)
|
||||
{
|
||||
int8_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_i8(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_i8 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t Preferences::getUChar(const char *key, const uint8_t defaultValue)
|
||||
{
|
||||
uint8_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_u8(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_u8 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int16_t Preferences::getShort(const char *key, const int16_t defaultValue)
|
||||
{
|
||||
int16_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_i16(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_i16 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t Preferences::getUShort(const char *key, const uint16_t defaultValue)
|
||||
{
|
||||
uint16_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_u16(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_u16 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int32_t Preferences::getInt(const char *key, const int32_t defaultValue)
|
||||
{
|
||||
int32_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_i32(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_i32 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t Preferences::getUInt(const char *key, const uint32_t defaultValue)
|
||||
{
|
||||
uint32_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_u32(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_u32 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int32_t Preferences::getLong(const char *key, const int32_t defaultValue)
|
||||
{
|
||||
return getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
uint32_t Preferences::getULong(const char *key, const uint32_t defaultValue)
|
||||
{
|
||||
return getUInt(key, defaultValue);
|
||||
}
|
||||
|
||||
int64_t Preferences::getLong64(const char *key, const int64_t defaultValue)
|
||||
{
|
||||
int64_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_i64(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_i64 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint64_t Preferences::getULong64(const char *key, const uint64_t defaultValue)
|
||||
{
|
||||
uint64_t value = defaultValue;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
esp_err_t err = nvs_get_u64(_handle, key, &value);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGV(PREFERENCES_TAG, "nvs_get_u64 fail: %s %s", key, nvs_error(err));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
float_t Preferences::getFloat(const char *key, const float_t defaultValue)
|
||||
{
|
||||
float_t value = defaultValue;
|
||||
getBytes(key, (void *)&value, sizeof(float_t));
|
||||
return value;
|
||||
}
|
||||
|
||||
double_t Preferences::getDouble(const char *key, const double_t defaultValue)
|
||||
{
|
||||
double_t value = defaultValue;
|
||||
getBytes(key, (void *)&value, sizeof(double_t));
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Preferences::getBool(const char *key, const bool defaultValue)
|
||||
{
|
||||
return getUChar(key, defaultValue ? 1 : 0) == 1;
|
||||
}
|
||||
|
||||
size_t Preferences::getString(const char *key, char *value, const size_t maxLen)
|
||||
{
|
||||
size_t len = 0;
|
||||
if (!_started || !key || !value || !maxLen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_get_str(_handle, key, NULL, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_str len fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
if (len > maxLen)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "not enough space in value: %u < %u", maxLen, len);
|
||||
return 0;
|
||||
}
|
||||
err = nvs_get_str(_handle, key, value, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_str fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
std::string Preferences::getString(const char *key, const std::string defaultValue)
|
||||
{
|
||||
char *value = NULL;
|
||||
size_t len = 0;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
esp_err_t err = nvs_get_str(_handle, key, value, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_str len fail: %s %s", key, nvs_error(err));
|
||||
return defaultValue;
|
||||
}
|
||||
char buf[len];
|
||||
value = buf;
|
||||
err = nvs_get_str(_handle, key, value, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_str fail: %s %s", key, nvs_error(err));
|
||||
return defaultValue;
|
||||
}
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
size_t Preferences::getBytesLength(const char *key)
|
||||
{
|
||||
size_t len = 0;
|
||||
if (!_started || !key)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_get_blob(_handle, key, NULL, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_blob len fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t Preferences::getBytes(const char *key, void *buf, size_t maxLen)
|
||||
{
|
||||
size_t len = getBytesLength(key);
|
||||
if (!len || !buf || !maxLen)
|
||||
{
|
||||
return len;
|
||||
}
|
||||
if (len > maxLen)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "not enough space in buffer: %u < %u", maxLen, len);
|
||||
return 0;
|
||||
}
|
||||
esp_err_t err = nvs_get_blob(_handle, key, buf, &len);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "nvs_get_blob fail: %s %s", key, nvs_error(err));
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t Preferences::freeEntries()
|
||||
{
|
||||
nvs_stats_t nvs_stats;
|
||||
esp_err_t err = nvs_get_stats(NULL, &nvs_stats);
|
||||
if (err)
|
||||
{
|
||||
ESP_LOGE(PREFERENCES_TAG, "Failed to get nvs statistics");
|
||||
return 0;
|
||||
}
|
||||
return nvs_stats.free_entries;
|
||||
}
|
||||
87
components/Preferences/Preferences/Preferences.hpp
Normal file
87
components/Preferences/Preferences/Preferences.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// source: https://github.com/espressif/arduino-esp32/blob/master/libraries/Preferences/src/Preferences.h
|
||||
// ported by: Lorow, do not trust this please
|
||||
|
||||
#pragma once
|
||||
#ifndef _PREFERENCES_HPP_
|
||||
#define _PREFERENCES_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <math.h>
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PT_I8,
|
||||
PT_U8,
|
||||
PT_I16,
|
||||
PT_U16,
|
||||
PT_I32,
|
||||
PT_U32,
|
||||
PT_I64,
|
||||
PT_U64,
|
||||
PT_STR,
|
||||
PT_BLOB,
|
||||
PT_INVALID
|
||||
} PreferenceType;
|
||||
|
||||
class Preferences
|
||||
{
|
||||
protected:
|
||||
uint32_t _handle;
|
||||
bool _started;
|
||||
bool _readOnly;
|
||||
|
||||
public:
|
||||
Preferences();
|
||||
~Preferences();
|
||||
|
||||
bool begin(const char *name, bool readOnly = false, const char *partition_label = nullptr);
|
||||
void end();
|
||||
|
||||
bool clear();
|
||||
bool remove(const char *key);
|
||||
|
||||
size_t putChar(const char *key, int8_t value);
|
||||
size_t putUChar(const char *key, uint8_t value);
|
||||
size_t putShort(const char *key, int16_t value);
|
||||
size_t putUShort(const char *key, uint16_t value);
|
||||
size_t putInt(const char *key, int32_t value);
|
||||
size_t putUInt(const char *key, uint32_t value);
|
||||
size_t putLong(const char *key, int32_t value);
|
||||
size_t putULong(const char *key, uint32_t value);
|
||||
size_t putLong64(const char *key, int64_t value);
|
||||
size_t putULong64(const char *key, uint64_t value);
|
||||
size_t putFloat(const char *key, float_t value);
|
||||
size_t putDouble(const char *key, double_t value);
|
||||
size_t putBool(const char *key, bool value);
|
||||
size_t putString(const char *key, const char *value);
|
||||
size_t putString(const char *key, std::string value);
|
||||
size_t putBytes(const char *key, const void *value, size_t len);
|
||||
|
||||
bool isKey(const char *key);
|
||||
PreferenceType getType(const char *key);
|
||||
int8_t getChar(const char *key, int8_t defaultValue = 0);
|
||||
uint8_t getUChar(const char *key, uint8_t defaultValue = 0);
|
||||
int16_t getShort(const char *key, int16_t defaultValue = 0);
|
||||
uint16_t getUShort(const char *key, uint16_t defaultValue = 0);
|
||||
int32_t getInt(const char *key, int32_t defaultValue = 0);
|
||||
uint32_t getUInt(const char *key, uint32_t defaultValue = 0);
|
||||
int32_t getLong(const char *key, int32_t defaultValue = 0);
|
||||
uint32_t getULong(const char *key, uint32_t defaultValue = 0);
|
||||
int64_t getLong64(const char *key, int64_t defaultValue = 0);
|
||||
uint64_t getULong64(const char *key, uint64_t defaultValue = 0);
|
||||
float_t getFloat(const char *key, float_t defaultValue = NAN);
|
||||
double_t getDouble(const char *key, double_t defaultValue = NAN);
|
||||
bool getBool(const char *key, bool defaultValue = false);
|
||||
size_t getString(const char *key, char *value, size_t maxLen);
|
||||
std::string getString(const char *key, std::string defaultValue = std::string());
|
||||
size_t getBytesLength(const char *key);
|
||||
size_t getBytes(const char *key, void *buf, size_t maxLen);
|
||||
size_t freeEntries();
|
||||
};
|
||||
|
||||
#endif _PREFERENCES_HPP_
|
||||
4
components/customSomething/CMakeLists.txt
Normal file
4
components/customSomething/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "customSomething/customSomething.hpp"
|
||||
INCLUDE_DIRS "customSomething"
|
||||
REQUIRES "driver"
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "esp_log.h"
|
||||
|
||||
void printTheInclude()
|
||||
{
|
||||
ESP_LOGI("customSomething", "test");
|
||||
}
|
||||
4
components/openiris_logo/CMakeLists.txt
Normal file
4
components/openiris_logo/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "openiris_logo/openiris_logo.hpp"
|
||||
INCLUDE_DIRS "openiris_logo"
|
||||
REQUIRES "driver"
|
||||
)
|
||||
76
components/openiris_logo/openiris_logo/openiris_logo.hpp
Normal file
76
components/openiris_logo/openiris_logo/openiris_logo.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Made by ZanzyTHEBar
|
||||
#pragma once
|
||||
#ifndef OPENIRIS_LOGO_HPP
|
||||
#define OPENIRIS_LOGO_HPP
|
||||
#include "esp_log.h"
|
||||
|
||||
namespace Logo
|
||||
{
|
||||
static const char *LOGO_TAG = "[LOGO]";
|
||||
|
||||
inline static void printASCII()
|
||||
{
|
||||
ESP_LOGI(LOGO_TAG, " : === WELCOME === TO === : ");
|
||||
ESP_LOGI(LOGO_TAG, " <===========================================================================================================================> ");
|
||||
ESP_LOGI(LOGO_TAG, " ██████╗ ██████╗ ███████╗███╗ ██╗██╗██████╗ ██╗███████╗ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██╔═══██╗██╔══██╗██╔════╝████╗ ██║██║██╔══██╗██║██╔════╝ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██║ ██║██████╔╝█████╗ ██╔██╗ ██║██║██████╔╝██║███████╗ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║██║██╔══██╗██║╚════██║ ");
|
||||
ESP_LOGI(LOGO_TAG, " ╚██████╔╝██║ ███████╗██║ ╚████║██║██║ ██║██║███████║ ");
|
||||
ESP_LOGI(LOGO_TAG, " ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚═╝╚══════╝ ");
|
||||
ESP_LOGI(LOGO_TAG, " ");
|
||||
ESP_LOGI(LOGO_TAG, " ██████████████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓▓▓▒▒▒▒▒▒▒▒░░▒▒▓▓▓▓██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████▓▓░░░░▒▒░░░░░░▒▒░░░░░░▒▒░░████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▓▓▓▓▒▒▒▒░░░░░░▒▒░░▒▒░░░░░░▒▒░░▒▒▓▓▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒▒▒▒▒░░▒▒░░░░░░░░░░░░▒▒░░░░▒▒░░░░▒▒░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓░░░░▒▒░░░░▒▒▒▒░░░░░░░░░░▒▒░░ ░░░░░░░░▒▒░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓▓▓▓▓▓▓░░░░░░▒▒░░░░░░░░░░░░░░ ░░░░░░░░░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░▒▒░░░░░░░░░░░░ ░░ ▒▒▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒▒▒▒▒░░░░▒▒░░░░░░░░░░░░░░░░░░ ░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓▓▓▒▒▒▒▒▒▒▒▒▒░░░░░░▒▒░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓ ░░ ▒▒▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▒▒▒▒▒▒▒▒▓▓▓▓▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░ ▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓▓▒▒ ░░▒▒▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒░░░░░░▒▒▒▒▒▒░░░░░░░░░░░░░░░░▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▓▓▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒░░░░░░░░░░░░ ▒▒▒▒▒▒▒▒▒▒▒▒████▓▓░░░░▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒▒▒▓▓▒▒▓▓░░░░░░░░░░░░░░░░░░▓▓▒▒▒▒░░▒▒▒▒████ ▒▒██░░▒▒▓▓▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░▓▓░░▒▒▒▒▒▒██████▒▒ ▓▓▓▓░░▓▓▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒░░▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░▓▓▒▒░░▒▒░░████████▓▓ ██▓▓▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓▓▓▓▓▒▒▒▒▒▒░░░░░░▒▒░░░░░░░░░░▒▒░░▒▒░░▒▒██████████▒▒██▒▒▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒▒▒░░░░░░░░▒▒▒▒░░░░░░░░░░░░▒▒▒▒░░░░▒▒██▒▒██████ ██▒▒▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒░░▓▓▓▓▓▓▒▒░░░░░░░░░░░░░░░░▒▒░░ ▒▒░░██ ▒▒████▒▒██▒▒▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▓▓▓▓▓▓░░▒▒▒▒░░▒▒░░░░░░░░░░░░░░▒▒▒▒░░░░░░▒▒██ ██████▒▒▒▒▒▒▓▓░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓██▓▓▒▒▒▒▓▓░░░░▒▒░░░░░░░░░░░░░░░░░░▒▒▒▒░░▒▒░░▒▒██████▒▒▒▒▒▒▓▓ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓██▒▒▒▒▒▒▒▒▓▓▓▓▒▒░░░░░░░░░░░░░░░░░░▒▒░░▒▒░░▒▒░░▒▒░░▒▒▒▒▒▒▒▒▓▓░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▓▓██▓▓▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░▒▒░░▒▒░░░░░░▒▒▒▒▒▒▒▒▓▓ ░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▓▓██▓▓▓▓▒▒▒▒▒▒▒▒░░░░░░░░▒▒░░░░░░░░░░░░▒▒▒▒▒▒░░▒▒▒▒▒▒▓▓▓▓ ░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓▓▓▒▒▒▒▓▓██▓▓▒▒▒▒▒▒░░░░▒▒▒▒░░▒▒░░░░░░░░░░░░░░░░░░▒▒▒▒▓▓▓▓▓▓░░░░░░░░▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▓▓▒▒▓▓██▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░ ░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▓▓░░▒▒▒▒██▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒▒░░▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▓▓▒▒░░▓▓▒▒██▓▓▒▒▒▒▒▒▒▒░░▓▓▒▒▓▓▒▒░░░░▒▒░░░░░░░░░░░░░░░░░░░░░░▓▓██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒░░▒▒▒▒▒▒▓▓██▓▓▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▒▒▓▓░░░░░░░░░░▒▒░░░░▒▒░░▒▒▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒░░▒▒░░▒▒████ ██▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▓▓▒▒▒▒▒▒▓▓▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▓▓░░▒▒░░▓▓ ████▓▓▒▒▓▓▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▒▒██▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒ ██ ████▓▓▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒░░██ ██████▓▓▒▒▒▒▒▒▒▒▓▓▓▓██████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒░░ ████ ██████████████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▒▒▒▒▒▒▒▒░░ ░░████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████▒▒▒▒▒▒░░░░ ░░████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████▒▒▒▒▒▒░░░░ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████▒▒▒▒▒▒░░ ░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██▓▓▒▒▒▒░░ ▒▒▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████▒▒░░ ▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓▒▒░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██░░ ██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓██ ██░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██░░██ ██░░░░██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██░░██ ██░░▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ██░░▒▒████░░▒▒██ ");
|
||||
ESP_LOGI(LOGO_TAG, " ▓▓▒▒▒▒▒▒▒▒▓▓ ");
|
||||
ESP_LOGI(LOGO_TAG, " ████████ ");
|
||||
ESP_LOGI(LOGO_TAG, " ");
|
||||
ESP_LOGI(LOGO_TAG, " <============================================================================================================================> ");
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
4
components/wifiManager/CMakeLists.txt
Normal file
4
components/wifiManager/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "wifiManager/wifiManager.cpp"
|
||||
INCLUDE_DIRS "wifiManager"
|
||||
REQUIRES esp_wifi nvs_flash esp_event esp_netif lwip
|
||||
)
|
||||
113
components/wifiManager/wifiManager/wifiManager.cpp
Normal file
113
components/wifiManager/wifiManager/wifiManager.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "wifiManager.hpp"
|
||||
|
||||
WiFiManager::state_e WiFiManager::_state = {state_e::NOT_INITIALIZED};
|
||||
|
||||
void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "Trying to connect, got event: %d", (int)event_id);
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
esp_err_t err = esp_wifi_connect();
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "esp_wifi_connect() failed: %s", esp_err_to_name(err));
|
||||
// xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
|
||||
{
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "retry to connect to the AP");
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "connect to the AP fail");
|
||||
}
|
||||
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiManager::SetCredentials(const char *ssid, const char *password)
|
||||
{
|
||||
memcpy(_wifi_cfg.sta.ssid, ssid, std::min(strlen(ssid), sizeof(_wifi_cfg.sta.ssid)));
|
||||
|
||||
memcpy(_wifi_cfg.sta.password, password, std::min(strlen(password), sizeof(_wifi_cfg.sta.password)));
|
||||
}
|
||||
|
||||
void WiFiManager::Begin()
|
||||
{
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t esp_wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&esp_wifi_init_config));
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
_wifi_cfg = {};
|
||||
_wifi_cfg.sta.threshold.authmode = WIFI_AUTH_WEP;
|
||||
_wifi_cfg.sta.pmf_cfg.capable = true;
|
||||
_wifi_cfg.sta.pmf_cfg.required = false;
|
||||
|
||||
// we try to connect with the hardcoded credentials first
|
||||
// todo, add support for more networks and setting up an AP
|
||||
this->SetCredentials(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSOWRD);
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &_wifi_cfg));
|
||||
|
||||
_state = state_e::READY_TO_CONNECT;
|
||||
esp_wifi_start();
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "wifi_init_sta finished.");
|
||||
|
||||
_state = state_e::CONNECTING;
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
ESP_LOGI(WIFI_MAMANGER_TAG, "connected to ap SSID:%s password:%s",
|
||||
_wifi_cfg.sta.ssid, _wifi_cfg.sta.password);
|
||||
_state = state_e::CONNECTED;
|
||||
}
|
||||
|
||||
else if (bits & WIFI_FAIL_BIT)
|
||||
{
|
||||
ESP_LOGE(WIFI_MAMANGER_TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
_wifi_cfg.sta.ssid, _wifi_cfg.sta.password);
|
||||
_state = state_e::ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(WIFI_MAMANGER_TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
}
|
||||
58
components/wifiManager/wifiManager/wifiManager.hpp
Normal file
58
components/wifiManager/wifiManager/wifiManager.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#ifndef WIFIHANDLER_HPP
|
||||
#define WIFIHANDLER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 3
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
static int s_retry_num = 0;
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
static const char *WIFI_MAMANGER_TAG = "[WIFI_MANAGER]";
|
||||
|
||||
class WiFiManager
|
||||
{
|
||||
public:
|
||||
public:
|
||||
enum class state_e
|
||||
{
|
||||
NOT_INITIALIZED,
|
||||
INITIALIZED,
|
||||
READY_TO_CONNECT,
|
||||
CONNECTING,
|
||||
WAITING_FOR_IP,
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
ERROR
|
||||
};
|
||||
|
||||
private:
|
||||
uint8_t channel;
|
||||
wifi_init_config_t _wifi_init_cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
wifi_config_t _wifi_cfg = {};
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
|
||||
static state_e _state;
|
||||
|
||||
int8_t power;
|
||||
bool _enable_adhoc;
|
||||
|
||||
// static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
// int32_t event_id, void *event_data);
|
||||
|
||||
public:
|
||||
void SetCredentials(const char *ssid, const char *password);
|
||||
constexpr const state_e &GetState(void) { return _state; }
|
||||
void Begin();
|
||||
};
|
||||
|
||||
#endif
|
||||
76
dependencies.lock
Normal file
76
dependencies.lock
Normal file
@@ -0,0 +1,76 @@
|
||||
dependencies:
|
||||
espressif/cmake_utilities:
|
||||
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.1'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 0.5.3
|
||||
espressif/esp32-camera:
|
||||
component_hash: 4aadd189e9ca97298f1d69920f2d8c6b07cb3cbca014584b60e96de8a3cbb249
|
||||
dependencies: []
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 2.0.10
|
||||
espressif/led_strip:
|
||||
component_hash: 28c6509a727ef74925b372ed404772aeedf11cce10b78c3f69b3c66799095e2d
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=4.4'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 2.5.5
|
||||
espressif/tinyusb:
|
||||
component_hash: 214989d502fc168241a4a4f83b097d8ac44a93cd6f1787b4ac10069a8b3bebd3
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
- esp32p4
|
||||
version: 0.15.0~10
|
||||
espressif/usb_device_uvc:
|
||||
component_hash: f86ee44e64f3914474919a14ac4d47082d6a2888a62c239e6e9dc58c32da4682
|
||||
dependencies:
|
||||
- name: espressif/cmake_utilities
|
||||
registry_url: https://components.espressif.com/
|
||||
require: private
|
||||
version: '*'
|
||||
- name: espressif/tinyusb
|
||||
registry_url: https://components.espressif.com/
|
||||
require: private
|
||||
version: '>=0.15.0~10'
|
||||
- name: idf
|
||||
require: private
|
||||
version: '>=5.0'
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
targets:
|
||||
- esp32s2
|
||||
- esp32s3
|
||||
- esp32p4
|
||||
version: 1.1.0
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 5.3.1
|
||||
direct_dependencies:
|
||||
- espressif/esp32-camera
|
||||
- espressif/led_strip
|
||||
- espressif/usb_device_uvc
|
||||
- idf
|
||||
manifest_hash: 10ae06dee995e9f5b117c494c0d7becd586027c7109cd05681c7e469c643dd90
|
||||
target: esp32s3
|
||||
version: 2.0.0
|
||||
2
main/CMakeLists.txt
Normal file
2
main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "openiris_main.cpp"
|
||||
INCLUDE_DIRS ".")
|
||||
56
main/Kconfig.projbuild
Normal file
56
main/Kconfig.projbuild
Normal file
@@ -0,0 +1,56 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
|
||||
|
||||
choice BLINK_LED
|
||||
prompt "Blink LED type"
|
||||
default BLINK_LED_GPIO
|
||||
help
|
||||
Select the LED type. A normal level controlled LED or an addressable LED strip.
|
||||
The default selection is based on the Espressif DevKit boards.
|
||||
You can change the default selection according to your board.
|
||||
|
||||
config BLINK_LED_GPIO
|
||||
bool "GPIO"
|
||||
config BLINK_LED_STRIP
|
||||
bool "LED strip"
|
||||
endchoice
|
||||
|
||||
choice BLINK_LED_STRIP_BACKEND
|
||||
depends on BLINK_LED_STRIP
|
||||
prompt "LED strip backend peripheral"
|
||||
default BLINK_LED_STRIP_BACKEND_RMT if SOC_RMT_SUPPORTED
|
||||
default BLINK_LED_STRIP_BACKEND_SPI
|
||||
help
|
||||
Select the backend peripheral to drive the LED strip.
|
||||
|
||||
config BLINK_LED_STRIP_BACKEND_RMT
|
||||
depends on SOC_RMT_SUPPORTED
|
||||
bool "RMT"
|
||||
config BLINK_LED_STRIP_BACKEND_SPI
|
||||
bool "SPI"
|
||||
endchoice
|
||||
|
||||
config BLINK_GPIO
|
||||
int "Blink GPIO number"
|
||||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
|
||||
default 8
|
||||
help
|
||||
GPIO number (IOxx) to blink on and off the LED.
|
||||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
|
||||
|
||||
config BLINK_PERIOD
|
||||
int "Blink period in ms"
|
||||
range 10 3600000
|
||||
default 1000
|
||||
help
|
||||
Define the blinking period in milliseconds.
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi network name"
|
||||
default ""
|
||||
|
||||
config WIFI_PASSOWRD
|
||||
string "WiFi password"
|
||||
default ""
|
||||
endmenu
|
||||
5
main/idf_component.yml
Normal file
5
main/idf_component.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
dependencies:
|
||||
espressif/led_strip: "^2.4.1"
|
||||
idf: "^5.0"
|
||||
espressif/esp32-camera: "^2.0.0"
|
||||
espressif/usb_device_uvc: "1.1.0"
|
||||
95
main/openiris_main.cpp
Normal file
95
main/openiris_main.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/* Blink Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "led_strip.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "usb_device_uvc.h"
|
||||
#include "esp_camera.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include <openiris_logo.hpp>
|
||||
#include <customSomething.hpp>
|
||||
#include <wifiManager.hpp>
|
||||
#include <Preferences.hpp>
|
||||
|
||||
static const char *TAG = "example";
|
||||
|
||||
/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
|
||||
or you can edit the following line and set a number here.
|
||||
*/
|
||||
#define BLINK_GPIO (gpio_num_t) CONFIG_BLINK_GPIO
|
||||
|
||||
static uint8_t s_led_state = 0;
|
||||
|
||||
static void blink_led(void)
|
||||
{
|
||||
/* Set the GPIO level according to the state (LOW or HIGH)*/
|
||||
gpio_set_level(BLINK_GPIO, s_led_state);
|
||||
}
|
||||
|
||||
static void configure_led(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
|
||||
gpio_reset_pin(BLINK_GPIO);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
static void initNVSStorage()
|
||||
{
|
||||
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());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
}
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
// porting plan:
|
||||
// port the wifi manager first. - worky!!!
|
||||
// get it connect to the network and setup an AP with hardcoded creds first -- connects. AP will be next
|
||||
// port the logo - done
|
||||
// port preferences lib - in progress; prolly temporary
|
||||
// then port the config - in progress
|
||||
// then port the led manager as this will be fairly easy
|
||||
// then port the serial manager
|
||||
// then port the camera manager
|
||||
// then port the streaming stuff (web and uvc)
|
||||
// then port the async web server
|
||||
// then port the Elegant OTA stuff
|
||||
// then port the mdns stuff
|
||||
|
||||
Logo::printASCII();
|
||||
initNVSStorage();
|
||||
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.Begin();
|
||||
|
||||
/* Configure the peripheral according to the LED type */
|
||||
configure_led();
|
||||
|
||||
while (1)
|
||||
{
|
||||
printTheInclude();
|
||||
ESP_LOGI(TAG, "Turning the LED on pin %d %s!", BLINK_GPIO, s_led_state == true ? "ON" : "OFF");
|
||||
blink_led();
|
||||
/* Toggle the LED state */
|
||||
s_led_state = !s_led_state;
|
||||
vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
16
pytest_blink.py
Normal file
16
pytest_blink.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from pytest_embedded_idf.dut import IdfDut
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.generic
|
||||
def test_blink(dut: IdfDut) -> None:
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'blink.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
logging.info('blink_bin_size : {}KB'.format(bin_size // 1024))
|
||||
9
sdkconfig.defaults
Normal file
9
sdkconfig.defaults
Normal file
@@ -0,0 +1,9 @@
|
||||
CONFIG_BLINK_LED_GPIO=y
|
||||
CONFIG_BLINK_GPIO=21
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
|
||||
CONFIG_CAMERA_MODULE_ESP_S3_EYE=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
|
||||
CONFIG_SPIRAM_MODE_OCT=y
|
||||
9
sdkconfig.defaults.esp32s3
Normal file
9
sdkconfig.defaults.esp32s3
Normal file
@@ -0,0 +1,9 @@
|
||||
CONFIG_BLINK_LED_GPIO=y
|
||||
CONFIG_BLINK_GPIO=21
|
||||
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
|
||||
CONFIG_CAMERA_MODULE_ESP_S3_EYE=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S3_SPIRAM_SUPPORT=y
|
||||
CONFIG_SPIRAM_MODE_OCT=y
|
||||
2149
sdkconfig.old
Normal file
2149
sdkconfig.old
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user