From dbfc66687beda5ec26f6134357b9feaaa1f751e7 Mon Sep 17 00:00:00 2001 From: Avior Date: Thu, 24 Nov 2022 12:11:23 +0100 Subject: [PATCH] feat: Initial Commit Signed-off-by: Avior --- .clang-tidy | 7 ++++ .editorconfig | 40 +++++++++++++++++++++++ .gitattributes | 1 + .github/workflows/test_build.yml | 40 +++++++++++++++++++++++ .gitignore | 9 ++++++ .vscode/extensions.json | 10 ++++++ config.cppcheck | 19 +++++++++++ config.ini | 19 +++++++++++ envs.ini | 15 +++++++++ include/Program.h | 19 +++++++++++ lib/.gitkeep | 0 platformio.ini | 55 ++++++++++++++++++++++++++++++++ secrets.ini.example | 6 ++++ src/Program.cpp | 49 ++++++++++++++++++++++++++++ src/main.cpp | 11 +++++++ test/.gitkeep | 0 16 files changed, 300 insertions(+) create mode 100644 .clang-tidy create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/test_build.yml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 config.cppcheck create mode 100644 config.ini create mode 100644 envs.ini create mode 100644 include/Program.h create mode 100644 lib/.gitkeep create mode 100644 platformio.ini create mode 100644 secrets.ini.example create mode 100644 src/Program.cpp create mode 100644 src/main.cpp create mode 100644 test/.gitkeep diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..790367c --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,7 @@ +# Clangtidy configuration file (not used until PIO 6) +--- +Checks: 'abseil-*,boost-*,bugprone-*,cert-*,cppcoreguidelines-*,clang-analyzer-*,google-*,hicpp-*,modernize-*,performance-*,portability-*,readability-*,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-cppcoreguidelines-init-variables' +WarningsAsErrors: false +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: google diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..001ac44 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,40 @@ +############################################# +# EditorConfig # +# cross-platform Editor basic configuration # +############################################# + +# make the editor config file not search in upper folders +root = true + +# Base Configuration +[*] +indent_style = tab +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 +end_of_line = lf + +# Yaml Standard +[*.{yaml,yml}] +indent_style = space +indent_size = 2 + +# Markdown Standards +[*.md] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = false + +# C++ Standards +[*.{cpp,h,ino}] +indent_style = space + +# PHP Standards +[*.php] +indent_style = space + +# INI file Standards +[*.ini] +indent_style = space diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml new file mode 100644 index 0000000..97de001 --- /dev/null +++ b/.github/workflows/test_build.yml @@ -0,0 +1,40 @@ +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + # this cache the platformio binaries and not the .pio folder + - name: Cache PlatformIO + uses: actions/cache@v3 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Set up Python + uses: actions/setup-python@v3 + + - name: Install PlatformIO + run: pip install platformio + + - name: Build the project + run: platformio run + + - name: Test the project + run: platformio check --fail-on-defect high diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7718eb0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Platformio specifics +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch + +# Aptatio/Platformio specifics +secrets.ini diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/config.cppcheck b/config.cppcheck new file mode 100644 index 0000000..77fd7d8 --- /dev/null +++ b/config.cppcheck @@ -0,0 +1,19 @@ + + + + .cppcheck-build + Unspecified + false + true + false + 10 + + + + + noCopyConstructor + noExplicitConstructor + unusedFunction + noOperatorEq + + diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..11e4023 --- /dev/null +++ b/config.ini @@ -0,0 +1,19 @@ +; Project configuration file + +[config] +; Hardware Serial baud rate +; Also available in the code as `MONITOR_SPEED` +monitor_speed = 115200 + +; Software Config +; note: additionnal flags are added by Platform.io (see total amount in `.vscode/c_cpp_properties.json` in the `defines` section) +; notworthy ones: +; __PLATFORMIO_BUILD_DEBUG__ = debug mode +build_flags = +; DO NOT TOUCH --- START + -D MONITOR_SPEED=${config.monitor_speed} +; DO NOT TOUCH --- END + + -D EXAMPLE_NUMBER=69 + + -D EXAMPLE_STRING=\"Pouet\" diff --git a/envs.ini b/envs.ini new file mode 100644 index 0000000..9df4a04 --- /dev/null +++ b/envs.ini @@ -0,0 +1,15 @@ +; Add additionnal environments in this file + +; Default production environment +[env:prod] + +; Debug environemnt +[env:debug] +build_type = debug + + +; Example additionnal env +; [env:example] +; ; note: keep the `${env.build_flags}` to includes others build flags +; build_flags = ${env.build_flags} +; -D POUET diff --git a/include/Program.h b/include/Program.h new file mode 100644 index 0000000..66e4a79 --- /dev/null +++ b/include/Program.h @@ -0,0 +1,19 @@ +#ifndef PROGRAM_H +#define PROGRAM_H + +#include "Arduino.h" + +class Program { +public: + /** + * Program startup + */ + Program(); + + /** + * Program main loop + */ + void loop(); +}; + +#endif diff --git a/lib/.gitkeep b/lib/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..abf519d --- /dev/null +++ b/platformio.ini @@ -0,0 +1,55 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[secrets] +build_flags = + +[platformio] +default_envs = debug +extra_configs = + secrets.ini + config.ini + envs.ini + +[env] +build_flags = ${config.build_flags} ${secrets.build_flags} +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = ${config.monitor_speed} +monitor_filters = esp32_exception_decoder, default +monitor_flags = + --echo +lib_deps = +check_tool = clangtidy, cppcheck +check_patterns = + src/ + include/ + lib/ +check_skip_packages = yes +check_flags = + clangtidy: --checks=abseil-*,boost-*,bugprone-*,cert-*,cppcoreguidelines-*,clang-analyzer-*,google-*,hicpp-*,modernize-*,performance-*,portability-*,readability-*,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-cppcoreguidelines-init-variables + cppcheck: --project=config.cppcheck + +[config] +monitor_speed = 115200 +build_flags = + -D MONITOR_SPEED=${config.monitor_speed} + + -D EXAMPLE_NUMBER=69 + + -D EXAMPLE_STRING=\"Pouet\" + +[env:prod] +lib_deps = t-vk/ESP32 BLE Keyboard@^0.3.2 + +[env:debug] +build_type = debug +lib_deps = t-vk/ESP32 BLE Keyboard@^0.3.2 diff --git a/secrets.ini.example b/secrets.ini.example new file mode 100644 index 0000000..90b9782 --- /dev/null +++ b/secrets.ini.example @@ -0,0 +1,6 @@ +; Add secrets token/logins/etc `secrets.ini` +; Add the sames values as blank in `secrets.ini.example +; To be able to reproduce it + +[secrets] +build_flags = diff --git a/src/Program.cpp b/src/Program.cpp new file mode 100644 index 0000000..2c72a01 --- /dev/null +++ b/src/Program.cpp @@ -0,0 +1,49 @@ +#include "Program.h" +#include + +BleKeyboard bleKeyboard; + +Program::Program() { + // Startup + Serial.begin(MONITOR_SPEED); + Serial.println("Starting BLE work!"); + bleKeyboard.begin(); +} + +void Program::loop() { + if(bleKeyboard.isConnected()) { + Serial.println("Sending 'Hello world'..."); + bleKeyboard.print("Hello world"); + + delay(1000); + + Serial.println("Sending Enter key..."); + bleKeyboard.write(KEY_RETURN); + + delay(1000); + + Serial.println("Sending Play/Pause media key..."); + // bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE); + + delay(1000); + + // + // Below is an example of pressing multiple keyboard modifiers + // which by default is commented out. + /*Hello world + Serial.println("Sending Ctrl+Alt+Delete..."); + bleKeyboard.press(KEY_LEFT_CTRL); + bleKeyboard.press(KEY_LEFT_ALT); + bleKeyboard.press(KEY_DELETE);Hello world + Hello world + Hello world + + delay(100);Hello world + + bleKeyboard.releaseAll(); + */ + } + + Serial.println("Waiting 5 seconds..."); + delay(5000); +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..74bf5a7 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,11 @@ +#include "Program.h" + +Program* program; + +void setup() { + program = new Program(); +} + +void loop() { + program->loop(); +} diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29