From ade24e86a80114edc084efb5efd8293001c28268 Mon Sep 17 00:00:00 2001 From: Luca Oliano Date: Sat, 27 Apr 2024 11:06:13 +0200 Subject: [PATCH] - move source file according with platformio standard directory structure - remove lib_deps from platformio.ini since they are already in libs folder --- .gitignore | 3 + CMakeLists.txt | 58 +++++++++---------- Docker/Dockerfile | 8 +-- include/README | 39 +++++++++++++ lib/README | 46 +++++++++++++++ platformio.ini | 10 +--- CharBuffer.cpp => src/CharBuffer.cpp | 0 CharBuffer.h => src/CharBuffer.h | 0 Config.h => src/Config.h | 0 Gpio.cpp => src/Gpio.cpp | 2 +- Gpio.h => src/Gpio.h | 0 LockActionResult.h => src/LockActionResult.h | 0 Logger.cpp => src/Logger.cpp | 0 Logger.h => src/Logger.h | 0 MqttReceiver.h => src/MqttReceiver.h | 0 MqttTopics.h => src/MqttTopics.h | 0 Network.cpp => src/Network.cpp | 0 Network.h => src/Network.h | 0 NetworkLock.cpp => src/NetworkLock.cpp | 0 NetworkLock.h => src/NetworkLock.h | 0 NetworkOpener.cpp => src/NetworkOpener.cpp | 0 NetworkOpener.h => src/NetworkOpener.h | 0 NukiDeviceId.cpp => src/NukiDeviceId.cpp | 0 NukiDeviceId.h => src/NukiDeviceId.h | 0 .../NukiOpenerWrapper.cpp | 0 .../NukiOpenerWrapper.h | 0 NukiWrapper.cpp => src/NukiWrapper.cpp | 0 NukiWrapper.h => src/NukiWrapper.h | 0 Ota.cpp => src/Ota.cpp | 0 Ota.h => src/Ota.h | 0 PreferencesKeys.h => src/PreferencesKeys.h | 0 .../PresenceDetection.cpp | 0 .../PresenceDetection.h | 0 QueryCommand.h => src/QueryCommand.h | 0 RestartReason.h => src/RestartReason.h | 0 WebCfgServer.cpp => src/WebCfgServer.cpp | 0 WebCfgServer.h => src/WebCfgServer.h | 0 .../WebCfgServerConstants.h | 0 main.cpp => src/main.cpp | 0 .../networkDevices}/ClientSyncW5500.cpp | 0 .../networkDevices}/ClientSyncW5500.h | 0 .../networkDevices}/EthLan8720Device.cpp | 0 .../networkDevices}/EthLan8720Device.h | 0 .../networkDevices}/IPConfiguration.cpp | 0 .../networkDevices}/IPConfiguration.h | 0 .../networkDevices}/NetworkDevice.cpp | 0 .../networkDevices}/NetworkDevice.h | 0 .../networkDevices}/W5500Device.cpp | 0 .../networkDevices}/W5500Device.h | 0 .../networkDevices}/WifiDevice.cpp | 0 .../networkDevices}/WifiDevice.h | 0 .../networkDevices}/espMqttClientW5500.cpp | 0 .../networkDevices}/espMqttClientW5500.h | 0 test/README | 11 ++++ 54 files changed, 132 insertions(+), 45 deletions(-) create mode 100644 include/README create mode 100644 lib/README rename CharBuffer.cpp => src/CharBuffer.cpp (100%) rename CharBuffer.h => src/CharBuffer.h (100%) rename Config.h => src/Config.h (100%) rename Gpio.cpp => src/Gpio.cpp (99%) rename Gpio.h => src/Gpio.h (100%) rename LockActionResult.h => src/LockActionResult.h (100%) rename Logger.cpp => src/Logger.cpp (100%) rename Logger.h => src/Logger.h (100%) rename MqttReceiver.h => src/MqttReceiver.h (100%) rename MqttTopics.h => src/MqttTopics.h (100%) rename Network.cpp => src/Network.cpp (100%) rename Network.h => src/Network.h (100%) rename NetworkLock.cpp => src/NetworkLock.cpp (100%) rename NetworkLock.h => src/NetworkLock.h (100%) rename NetworkOpener.cpp => src/NetworkOpener.cpp (100%) rename NetworkOpener.h => src/NetworkOpener.h (100%) rename NukiDeviceId.cpp => src/NukiDeviceId.cpp (100%) rename NukiDeviceId.h => src/NukiDeviceId.h (100%) rename NukiOpenerWrapper.cpp => src/NukiOpenerWrapper.cpp (100%) rename NukiOpenerWrapper.h => src/NukiOpenerWrapper.h (100%) rename NukiWrapper.cpp => src/NukiWrapper.cpp (100%) rename NukiWrapper.h => src/NukiWrapper.h (100%) rename Ota.cpp => src/Ota.cpp (100%) rename Ota.h => src/Ota.h (100%) rename PreferencesKeys.h => src/PreferencesKeys.h (100%) rename PresenceDetection.cpp => src/PresenceDetection.cpp (100%) rename PresenceDetection.h => src/PresenceDetection.h (100%) rename QueryCommand.h => src/QueryCommand.h (100%) rename RestartReason.h => src/RestartReason.h (100%) rename WebCfgServer.cpp => src/WebCfgServer.cpp (100%) rename WebCfgServer.h => src/WebCfgServer.h (100%) rename WebCfgServerConstants.h => src/WebCfgServerConstants.h (100%) rename main.cpp => src/main.cpp (100%) rename {networkDevices => src/networkDevices}/ClientSyncW5500.cpp (100%) rename {networkDevices => src/networkDevices}/ClientSyncW5500.h (100%) rename {networkDevices => src/networkDevices}/EthLan8720Device.cpp (100%) rename {networkDevices => src/networkDevices}/EthLan8720Device.h (100%) rename {networkDevices => src/networkDevices}/IPConfiguration.cpp (100%) rename {networkDevices => src/networkDevices}/IPConfiguration.h (100%) rename {networkDevices => src/networkDevices}/NetworkDevice.cpp (100%) rename {networkDevices => src/networkDevices}/NetworkDevice.h (100%) rename {networkDevices => src/networkDevices}/W5500Device.cpp (100%) rename {networkDevices => src/networkDevices}/W5500Device.h (100%) rename {networkDevices => src/networkDevices}/WifiDevice.cpp (100%) rename {networkDevices => src/networkDevices}/WifiDevice.h (100%) rename {networkDevices => src/networkDevices}/espMqttClientW5500.cpp (100%) rename {networkDevices => src/networkDevices}/espMqttClientW5500.h (100%) create mode 100644 test/README diff --git a/.gitignore b/.gitignore index 6e63376..b55bea0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ build cmake-build-debug cmake-build-release cmake-build-release-s3 +.pio +.vscode +.project diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ae3a59..add703f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,34 +42,34 @@ include_directories(${PROJECT_NAME} ) set(SRCFILES - Config.h - NukiDeviceId.cpp - CharBuffer.cpp - Network.cpp - MqttReceiver.h - NetworkLock.cpp - NetworkOpener.cpp - networkDevices/NetworkDevice.h - networkDevices/NetworkDevice.cpp - networkDevices/WifiDevice.cpp - networkDevices/W5500Device.cpp - networkDevices/EthLan8720Device.cpp - networkDevices/ClientSyncW5500.cpp - networkDevices/espMqttClientW5500.cpp - networkDevices/IPConfiguration.cpp - LockActionResult.h - QueryCommand.h - NukiWrapper.cpp - NukiOpenerWrapper.cpp - MqttTopics.h - Ota.cpp - WebCfgServerConstants.h - WebCfgServer.cpp - PresenceDetection.cpp - PreferencesKeys.h - Gpio.cpp - Logger.cpp - RestartReason.h + src/Config.h + src/NukiDeviceId.cpp + src/CharBuffer.cpp + src/Network.cpp + src/MqttReceiver.h + src/NetworkLock.cpp + src/NetworkOpener.cpp + src/networkDevices/NetworkDevice.h + src/networkDevices/NetworkDevice.cpp + src/networkDevices/WifiDevice.cpp + src/networkDevices/W5500Device.cpp + src/networkDevices/EthLan8720Device.cpp + src/networkDevices/ClientSyncW5500.cpp + src/networkDevices/espMqttClientW5500.cpp + src/networkDevices/IPConfiguration.cpp + src/LockActionResult.h + src/QueryCommand.h + src/NukiWrapper.cpp + src/NukiOpenerWrapper.cpp + src/MqttTopics.h + src/Ota.cpp + src/WebCfgServerConstants.h + src/WebCfgServer.cpp + src/PresenceDetection.cpp + src/PreferencesKeys.h + src/Gpio.cpp + src/Logger.cpp + src/RestartReason.h # include/RTOS.h lib/WiFiManager/WiFiManager.cpp lib/WiFiManager/wm_consts_en.h @@ -114,7 +114,7 @@ file(GLOB_RECURSE SRCFILESREC ) add_executable(${PROJECT_NAME} - main.cpp + src/main.cpp ${SRCFILES} ${SRCFILESREC} ) diff --git a/Docker/Dockerfile b/Docker/Dockerfile index d94b1cc..637fdbb 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -14,14 +14,10 @@ RUN cd ~/arduino* && \ RUN git clone --recurse-submodules https://github.com/technyon/Arduino-CMake-Toolchain.git ~/Arduino-CMake-Toolchain -COPY icon /usr/src/nuki_hub/icon -COPY include /usr/src/nuki_hub/include +COPY src /usr/src/nuki_hub/src COPY lib /usr/src/nuki_hub/lib -COPY networkDevices /usr/src/nuki_hub/networkDevices +COPY include /usr/src/nuki_hub/include COPY CMakeLists.txt /usr/src/nuki_hub -COPY index.html /usr/src/nuki_hub -COPY *.h /usr/src/nuki_hub/ -COPY *.cpp /usr/src/nuki_hub/ RUN mkdir -p /usr/src/nuki_hub/build diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..2593a33 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini index af66466..332c71b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,6 @@ [platformio] default_envs = esp32dev -src_dir = . [env] platform = espressif32 @@ -34,18 +33,11 @@ build_flags = ; -DDEBUG_NUKI_HEX_DATA ; -DDEBUG_NUKI_READABLE_DATA lib_deps = - https://github.com/technyon/nuki_ble.git - bertmelis/espMqttClient@1.6.0 - bblanchon/ArduinoJson@7.0.4 + monitor_speed = 115200 monitor_filters = esp32_exception_decoder time -build_src_filter = - -<*> - +<*.cpp> - +<*.h> - + [env:esp32dev] board = esp32dev diff --git a/CharBuffer.cpp b/src/CharBuffer.cpp similarity index 100% rename from CharBuffer.cpp rename to src/CharBuffer.cpp diff --git a/CharBuffer.h b/src/CharBuffer.h similarity index 100% rename from CharBuffer.h rename to src/CharBuffer.h diff --git a/Config.h b/src/Config.h similarity index 100% rename from Config.h rename to src/Config.h diff --git a/Gpio.cpp b/src/Gpio.cpp similarity index 99% rename from Gpio.cpp rename to src/Gpio.cpp index c3b2601..f3d9334 100644 --- a/Gpio.cpp +++ b/src/Gpio.cpp @@ -5,7 +5,7 @@ #include "Logger.h" #include "PreferencesKeys.h" #include "RestartReason.h" -#include "lib/gpio2go/src/Gpio2Go.h" +#include "../lib/gpio2go/src/Gpio2Go.h" Gpio* Gpio::_inst = nullptr; unsigned long Gpio::_debounceTs = 0; diff --git a/Gpio.h b/src/Gpio.h similarity index 100% rename from Gpio.h rename to src/Gpio.h diff --git a/LockActionResult.h b/src/LockActionResult.h similarity index 100% rename from LockActionResult.h rename to src/LockActionResult.h diff --git a/Logger.cpp b/src/Logger.cpp similarity index 100% rename from Logger.cpp rename to src/Logger.cpp diff --git a/Logger.h b/src/Logger.h similarity index 100% rename from Logger.h rename to src/Logger.h diff --git a/MqttReceiver.h b/src/MqttReceiver.h similarity index 100% rename from MqttReceiver.h rename to src/MqttReceiver.h diff --git a/MqttTopics.h b/src/MqttTopics.h similarity index 100% rename from MqttTopics.h rename to src/MqttTopics.h diff --git a/Network.cpp b/src/Network.cpp similarity index 100% rename from Network.cpp rename to src/Network.cpp diff --git a/Network.h b/src/Network.h similarity index 100% rename from Network.h rename to src/Network.h diff --git a/NetworkLock.cpp b/src/NetworkLock.cpp similarity index 100% rename from NetworkLock.cpp rename to src/NetworkLock.cpp diff --git a/NetworkLock.h b/src/NetworkLock.h similarity index 100% rename from NetworkLock.h rename to src/NetworkLock.h diff --git a/NetworkOpener.cpp b/src/NetworkOpener.cpp similarity index 100% rename from NetworkOpener.cpp rename to src/NetworkOpener.cpp diff --git a/NetworkOpener.h b/src/NetworkOpener.h similarity index 100% rename from NetworkOpener.h rename to src/NetworkOpener.h diff --git a/NukiDeviceId.cpp b/src/NukiDeviceId.cpp similarity index 100% rename from NukiDeviceId.cpp rename to src/NukiDeviceId.cpp diff --git a/NukiDeviceId.h b/src/NukiDeviceId.h similarity index 100% rename from NukiDeviceId.h rename to src/NukiDeviceId.h diff --git a/NukiOpenerWrapper.cpp b/src/NukiOpenerWrapper.cpp similarity index 100% rename from NukiOpenerWrapper.cpp rename to src/NukiOpenerWrapper.cpp diff --git a/NukiOpenerWrapper.h b/src/NukiOpenerWrapper.h similarity index 100% rename from NukiOpenerWrapper.h rename to src/NukiOpenerWrapper.h diff --git a/NukiWrapper.cpp b/src/NukiWrapper.cpp similarity index 100% rename from NukiWrapper.cpp rename to src/NukiWrapper.cpp diff --git a/NukiWrapper.h b/src/NukiWrapper.h similarity index 100% rename from NukiWrapper.h rename to src/NukiWrapper.h diff --git a/Ota.cpp b/src/Ota.cpp similarity index 100% rename from Ota.cpp rename to src/Ota.cpp diff --git a/Ota.h b/src/Ota.h similarity index 100% rename from Ota.h rename to src/Ota.h diff --git a/PreferencesKeys.h b/src/PreferencesKeys.h similarity index 100% rename from PreferencesKeys.h rename to src/PreferencesKeys.h diff --git a/PresenceDetection.cpp b/src/PresenceDetection.cpp similarity index 100% rename from PresenceDetection.cpp rename to src/PresenceDetection.cpp diff --git a/PresenceDetection.h b/src/PresenceDetection.h similarity index 100% rename from PresenceDetection.h rename to src/PresenceDetection.h diff --git a/QueryCommand.h b/src/QueryCommand.h similarity index 100% rename from QueryCommand.h rename to src/QueryCommand.h diff --git a/RestartReason.h b/src/RestartReason.h similarity index 100% rename from RestartReason.h rename to src/RestartReason.h diff --git a/WebCfgServer.cpp b/src/WebCfgServer.cpp similarity index 100% rename from WebCfgServer.cpp rename to src/WebCfgServer.cpp diff --git a/WebCfgServer.h b/src/WebCfgServer.h similarity index 100% rename from WebCfgServer.h rename to src/WebCfgServer.h diff --git a/WebCfgServerConstants.h b/src/WebCfgServerConstants.h similarity index 100% rename from WebCfgServerConstants.h rename to src/WebCfgServerConstants.h diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/networkDevices/ClientSyncW5500.cpp b/src/networkDevices/ClientSyncW5500.cpp similarity index 100% rename from networkDevices/ClientSyncW5500.cpp rename to src/networkDevices/ClientSyncW5500.cpp diff --git a/networkDevices/ClientSyncW5500.h b/src/networkDevices/ClientSyncW5500.h similarity index 100% rename from networkDevices/ClientSyncW5500.h rename to src/networkDevices/ClientSyncW5500.h diff --git a/networkDevices/EthLan8720Device.cpp b/src/networkDevices/EthLan8720Device.cpp similarity index 100% rename from networkDevices/EthLan8720Device.cpp rename to src/networkDevices/EthLan8720Device.cpp diff --git a/networkDevices/EthLan8720Device.h b/src/networkDevices/EthLan8720Device.h similarity index 100% rename from networkDevices/EthLan8720Device.h rename to src/networkDevices/EthLan8720Device.h diff --git a/networkDevices/IPConfiguration.cpp b/src/networkDevices/IPConfiguration.cpp similarity index 100% rename from networkDevices/IPConfiguration.cpp rename to src/networkDevices/IPConfiguration.cpp diff --git a/networkDevices/IPConfiguration.h b/src/networkDevices/IPConfiguration.h similarity index 100% rename from networkDevices/IPConfiguration.h rename to src/networkDevices/IPConfiguration.h diff --git a/networkDevices/NetworkDevice.cpp b/src/networkDevices/NetworkDevice.cpp similarity index 100% rename from networkDevices/NetworkDevice.cpp rename to src/networkDevices/NetworkDevice.cpp diff --git a/networkDevices/NetworkDevice.h b/src/networkDevices/NetworkDevice.h similarity index 100% rename from networkDevices/NetworkDevice.h rename to src/networkDevices/NetworkDevice.h diff --git a/networkDevices/W5500Device.cpp b/src/networkDevices/W5500Device.cpp similarity index 100% rename from networkDevices/W5500Device.cpp rename to src/networkDevices/W5500Device.cpp diff --git a/networkDevices/W5500Device.h b/src/networkDevices/W5500Device.h similarity index 100% rename from networkDevices/W5500Device.h rename to src/networkDevices/W5500Device.h diff --git a/networkDevices/WifiDevice.cpp b/src/networkDevices/WifiDevice.cpp similarity index 100% rename from networkDevices/WifiDevice.cpp rename to src/networkDevices/WifiDevice.cpp diff --git a/networkDevices/WifiDevice.h b/src/networkDevices/WifiDevice.h similarity index 100% rename from networkDevices/WifiDevice.h rename to src/networkDevices/WifiDevice.h diff --git a/networkDevices/espMqttClientW5500.cpp b/src/networkDevices/espMqttClientW5500.cpp similarity index 100% rename from networkDevices/espMqttClientW5500.cpp rename to src/networkDevices/espMqttClientW5500.cpp diff --git a/networkDevices/espMqttClientW5500.h b/src/networkDevices/espMqttClientW5500.h similarity index 100% rename from networkDevices/espMqttClientW5500.h rename to src/networkDevices/espMqttClientW5500.h diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html