From ce74e1a55ade597eb0ef60304f82f74dfc8e102f Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 09:27:04 +0200 Subject: [PATCH 01/19] add OneWire library --- .gitmodules | 3 +++ README.md | 2 ++ lib/OneWireLibrary | 1 + 3 files changed, 6 insertions(+) create mode 160000 lib/OneWireLibrary diff --git a/.gitmodules b/.gitmodules index 6c0b555..dd318a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "lib/SparkFun_Qwiic_OpenLog_Arduino_Library"] path = lib/SparkFun_Qwiic_OpenLog_Arduino_Library url = https://github.com/sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library.git +[submodule "lib/OneWireLibrary"] + path = lib/OneWireLibrary + url = https://github.com/particle-iot/OneWireLibrary diff --git a/README.md b/README.md index e352fbb..fff243a 100644 --- a/README.md +++ b/README.md @@ -78,5 +78,7 @@ The following third-party software is used in the ***LabLogger*** libraries: | LoggerCore | SequentialFileRK | https://github.com/rickkas7/SequentialFileRK | MIT | | LoggerCore | PublishQueueExtRK | https://github.com/rickkas7/PublishQueueExtRK | MIT | | LoggerCore | SparkFun_Qwiic_OpenLog_Arduino_Library | https://github.com/sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library | MIT | +| LoggerCore | OneWire | https://github.com/particle-iot/OneWireLibrary | MIT | | LoggerOled | Adafruit_SSD1306 | https://github.com/adafruit/Adafruit_SSD1306 | BSD | + diff --git a/lib/OneWireLibrary b/lib/OneWireLibrary new file mode 160000 index 0000000..3715182 --- /dev/null +++ b/lib/OneWireLibrary @@ -0,0 +1 @@ +Subproject commit 3715182950f0a802dc58ccd89259bdcbe0547439 From 1241b3330c4b4c71585de66891198a162e483399 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 09:39:02 +0200 Subject: [PATCH 02/19] add vscode settings for intellisense to work --- .vscode/settings.json | 79 +++++++++++++++++++++++++++++++++++++++++++ project.properties | 2 ++ 2 files changed, 81 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 project.properties diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d9cd3ea --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,79 @@ +{ + "C_Cpp.default.configurationProvider": "particle.particle-vscode-core", + "C_Cpp.errorSquiggles": "enabled", + "C_Cpp.dimInactiveRegions": false, + "particle.targetPlatform": "p2", // needs to be defined for IntelliSense to work + "particle.firmwareVersion": "6.2.1", // needs to be defined for IntelliSense to work + "editor.tabSize": 4, + "files.associations": { + "__config": "cpp", + "__cxx_version": "cpp", + "__locale": "cpp", + "cstdlib": "cpp", + "memory_resource": "cpp", + "locale": "cpp", + "ostream": "cpp", + "system_error": "cpp", + "typeinfo": "cpp", + "vector": "cpp", + "__bit_reference": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__functional_base": "cpp", + "__hash_table": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__nullptr": "cpp", + "__split_buffer": "cpp", + "__string": "cpp", + "__threading_support": "cpp", + "__tuple": "cpp", + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "unordered_map": "cpp", + "utility": "cpp", + "__memory": "cpp", + "__functional_03": "cpp", + "*.hold": "cpp", + "__verbose_abort": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "span": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..372325f --- /dev/null +++ b/project.properties @@ -0,0 +1,2 @@ +# note: this project.properties file needs to exist for VSCode IntelliSense to work properly for the particle code base, it serves no other purpose +name=LabLoggerLibs \ No newline at end of file From d36271e960f2e9eb5de611b726d4daee07d9eb31 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 09:57:53 +0200 Subject: [PATCH 03/19] clarify name of compile firmware action --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index e939d5c..c376c32 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -1,4 +1,4 @@ -name: Compile Firmware +name: Base workflow_call for compile actions on: workflow_call: From 514188a62a55cce22612630a41ef5464524cfcfc Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 10:29:05 +0200 Subject: [PATCH 04/19] remove one wire library --- .gitmodules | 3 --- lib/OneWireLibrary | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lib/OneWireLibrary diff --git a/.gitmodules b/.gitmodules index dd318a6..6c0b555 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,6 +13,3 @@ [submodule "lib/SparkFun_Qwiic_OpenLog_Arduino_Library"] path = lib/SparkFun_Qwiic_OpenLog_Arduino_Library url = https://github.com/sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library.git -[submodule "lib/OneWireLibrary"] - path = lib/OneWireLibrary - url = https://github.com/particle-iot/OneWireLibrary diff --git a/lib/OneWireLibrary b/lib/OneWireLibrary deleted file mode 160000 index 3715182..0000000 --- a/lib/OneWireLibrary +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3715182950f0a802dc58ccd89259bdcbe0547439 From 55612e3b664b33cdaf0cb0c1df6eff394b9101a8 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 11:56:26 +0200 Subject: [PATCH 05/19] document dependencies --- src/publish/project.properties | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/publish/project.properties b/src/publish/project.properties index f89a431..be3a5c8 100644 --- a/src/publish/project.properties +++ b/src/publish/project.properties @@ -1 +1,17 @@ -name=publish \ No newline at end of file +name=publish + +## DEPENDENCIES ## +# dependencies added in lib/ as submodules to include full codebase in repo +# these will be included in `rake PROGRA` compile as long as they are listed +# in .github/workflows/compile-PROGRAM.yaml under program -> lib +# if a dependency is not available locally in lib/, comment it in here + +#dependencies.DeviceNameHelperRK=0.0.1 + +#dependencies.FileHelperRK=0.0.3 + +#dependencies.PublishQueueExtRK=0.0.7 +#dependencies.SequentialFileRK=0.0.3 # dependency of PublishQueueExtRK + +#dependencies.SparkFun_Qwiic_OpenLog_Arduino_Library=3.0.1 + From 2a91d0c5858134d8e4bbcc06dd23cea77ebc5010 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 11:57:11 +0200 Subject: [PATCH 06/19] make src explicit in lib --- .github/workflows/compile-blink.yaml | 2 +- .github/workflows/compile-publish.yaml | 2 +- .github/workflows/compile.yaml | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/compile-blink.yaml b/.github/workflows/compile-blink.yaml index b17a291..7e5350b 100644 --- a/.github/workflows/compile-blink.yaml +++ b/.github/workflows/compile-blink.yaml @@ -18,7 +18,7 @@ jobs: # CHANGE program/lib/aux as needed program: - src: 'blink' - lib: 'DeviceNameHelperRK MyLib' + lib: 'DeviceNameHelperRK/src MyLib/src' aux: '' # CHANGE platforms as needed platform: diff --git a/.github/workflows/compile-publish.yaml b/.github/workflows/compile-publish.yaml index 46e4bd8..df8cb0b 100644 --- a/.github/workflows/compile-publish.yaml +++ b/.github/workflows/compile-publish.yaml @@ -19,7 +19,7 @@ jobs: # CHANGE program/lib/aux as needed program: - src: 'publish' - lib: 'DeviceNameHelperRK FileHelperRK SequentialFileRK PublishQueueExtRK SparkFun_Qwiic_OpenLog_Arduino_Library' + lib: 'DeviceNameHelperRK/src FileHelperRK/src SequentialFileRK/src PublishQueueExtRK/src SparkFun_Qwiic_OpenLog_Arduino_Library/src' aux: 'LoggerCore/src/LoggerPlatform* LoggerCore/src/LoggerUtils* LoggerCore/src/LoggerPublisher* LoggerCore/src/LoggerSD*' # CHANGE platforms as needed platform: diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index c376c32..899ffa6 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -41,13 +41,13 @@ jobs: echo "Including libraries:" for lib in ${{ inputs.lib }}; do if [ -d "$lib" ]; then - echo " - $lib/src/*" - mv $lib/src/* ${{ inputs.src }} + echo " - $lib/*" + mv $lib/* ${{ inputs.src }} elif [ -d "lib/$lib" ]; then - echo " - lib/$lib/src/*" - mv lib/$lib/src/* ${{ inputs.src }} + echo " - lib/$lib/*" + mv lib/$lib/* ${{ inputs.src }} else - echo " - could not find $lib, make sure the library exists" + echo " - could not find $lib, make sure the folder exists" fi done echo "Including auxiliary resources:" From a735d83be5bb18a1018c49f191ca2720076bc98d Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 12:29:12 +0200 Subject: [PATCH 07/19] test secretes --- .github/workflows/compile-blink.yaml | 1 + .github/workflows/compile-publish.yaml | 1 + .github/workflows/compile.yaml | 18 +++++++++--------- LoggerCore/src/LoggerPlatform.h | 5 +++++ src/blink/blink.cpp | 2 ++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/compile-blink.yaml b/.github/workflows/compile-blink.yaml index 7e5350b..57cd396 100644 --- a/.github/workflows/compile-blink.yaml +++ b/.github/workflows/compile-blink.yaml @@ -31,6 +31,7 @@ jobs: # workflow call uses: ./.github/workflows/compile.yaml + secrets: inherit with: platform: ${{ matrix.platform.name }} version: ${{ matrix.platform.version }} diff --git a/.github/workflows/compile-publish.yaml b/.github/workflows/compile-publish.yaml index df8cb0b..c39c572 100644 --- a/.github/workflows/compile-publish.yaml +++ b/.github/workflows/compile-publish.yaml @@ -30,6 +30,7 @@ jobs: # workflow call uses: ./.github/workflows/compile.yaml + secrets: inherit with: platform: ${{ matrix.platform.name }} version: ${{ matrix.platform.version }} diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 899ffa6..1151486 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -56,7 +56,7 @@ jobs: mv $aux ${{ inputs.src }} done - - name: Compile in cloud + - name: Compile in cloud (on master) id: compile uses: particle-iot/compile-action@v1 with: @@ -65,6 +65,14 @@ jobs: device-os-version: ${{ inputs.version }} sources-folder: ${{ inputs.src }} + - name: Compile locally # if not on master or if cloud compile failed + if: ${{ failure() || github.ref != 'refs/heads/master' }} + uses: particle-iot/compile-action@v1 + with: + particle-platform-name: ${{ inputs.platform }} + device-os-version: ${{ inputs.version }} + sources-folder: ${{ inputs.src }} + - name: Move binary run: | mv ${{ steps.compile.outputs.firmware-path }} ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin @@ -74,11 +82,3 @@ jobs: with: name: ${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }} path: ${{ inputs.src }} - - - name: Compile locally to debug - if: ${{ failure() }} - uses: particle-iot/compile-action@v1 - with: - particle-platform-name: ${{ inputs.platform }} - device-os-version: ${{ inputs.version }} - sources-folder: ${{ inputs.src }} \ No newline at end of file diff --git a/LoggerCore/src/LoggerPlatform.h b/LoggerCore/src/LoggerPlatform.h index 34bba29..721dbcd 100644 --- a/LoggerCore/src/LoggerPlatform.h +++ b/LoggerCore/src/LoggerPlatform.h @@ -2,6 +2,11 @@ #include "Particle.h" +// address issue where this is not defined anymore in newer firmware +#ifndef PLATFORM_PHOTON +#define PLATFORM_PHOTON 0 +#endif + // file helper to get at flash system usage // dependencies.FileHelperRK=0.0.3 #include "FileHelperRK.h" diff --git a/src/blink/blink.cpp b/src/blink/blink.cpp index d1a81c9..640ddb6 100644 --- a/src/blink/blink.cpp +++ b/src/blink/blink.cpp @@ -34,7 +34,9 @@ void info_handler(const char *topic, const char *data) { } // enable sysstem treading +#ifndef SYSTEM_VERSION_v620 SYSTEM_THREAD(ENABLED); +#endif // manual mode SYSTEM_MODE(MANUAL); From 509e2e1d2e98e0e47ef592961fadd9c25f5a4f69 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 12:34:39 +0200 Subject: [PATCH 08/19] cleanup actions --- .github/workflows/compile-controller.yaml | 3 ++- .github/workflows/compile.yaml | 1 + lib/MyLib/src/lib.h | 1 - src/blink/blink.cpp | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 lib/MyLib/src/lib.h diff --git a/.github/workflows/compile-controller.yaml b/.github/workflows/compile-controller.yaml index 823d5af..645c6a5 100644 --- a/.github/workflows/compile-controller.yaml +++ b/.github/workflows/compile-controller.yaml @@ -19,7 +19,7 @@ jobs: # CHANGE program/lib/aux as needed program: - src: 'controller' - lib: 'LoggerCore DeviceNameHelperRK FileHelperRK SequentialFileRK PublishQueueExtRK SparkFun_Qwiic_OpenLog_Arduino_Library' + lib: 'LoggerCore/src DeviceNameHelperRK/src FileHelperRK/src SequentialFileRK/src PublishQueueExtRK/src SparkFun_Qwiic_OpenLog_Arduino_Library/src' aux: '' # CHANGE platforms as needed platform: @@ -30,6 +30,7 @@ jobs: # workflow call uses: ./.github/workflows/compile.yaml + secrets: inherit with: platform: ${{ matrix.platform.name }} version: ${{ matrix.platform.version }} diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 1151486..a100eed 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -57,6 +57,7 @@ jobs: done - name: Compile in cloud (on master) + if: ${{ github.ref == 'refs/heads/master' }} id: compile uses: particle-iot/compile-action@v1 with: diff --git a/lib/MyLib/src/lib.h b/lib/MyLib/src/lib.h deleted file mode 100644 index 24b5389..0000000 --- a/lib/MyLib/src/lib.h +++ /dev/null @@ -1 +0,0 @@ -#define MY_CONST 42 \ No newline at end of file diff --git a/src/blink/blink.cpp b/src/blink/blink.cpp index 640ddb6..ccbd4bc 100644 --- a/src/blink/blink.cpp +++ b/src/blink/blink.cpp @@ -1,5 +1,4 @@ #include "Particle.h" -#include "lib.h" // generic blink test From 72434f4f80a932008cf788369edb16549b905745 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 13:12:55 +0200 Subject: [PATCH 09/19] collect artifacts also from local compile --- .github/workflows/compile.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index a100eed..6a2ca25 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -66,6 +66,11 @@ jobs: device-os-version: ${{ inputs.version }} sources-folder: ${{ inputs.src }} + - name: Move cloud binary + if: ${{ github.ref == 'refs/heads/master' }} + run: | + mv ${{ steps.compile.outputs.firmware-path }} ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin + - name: Compile locally # if not on master or if cloud compile failed if: ${{ failure() || github.ref != 'refs/heads/master' }} uses: particle-iot/compile-action@v1 @@ -74,9 +79,10 @@ jobs: device-os-version: ${{ inputs.version }} sources-folder: ${{ inputs.src }} - - name: Move binary + - name: Move compile results run: | - mv ${{ steps.compile.outputs.firmware-path }} ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin + mv /workspace/target/workspace.lst ${{ inputs.src }}/ + mv /workspace/target/workspace.bin ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin - name: Upload binary uses: actions/upload-artifact@v4 From ab8e154815a4a70921c694c38cd4b3ab862c6d48 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 13:30:20 +0200 Subject: [PATCH 10/19] update compile --- .github/workflows/compile.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 6a2ca25..eeabeb8 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -81,6 +81,10 @@ jobs: - name: Move compile results run: | + ls -la / + ls -la ./ + ls -la /firmware/modules/tron/user-part + ls -la /workspace/target mv /workspace/target/workspace.lst ${{ inputs.src }}/ mv /workspace/target/workspace.bin ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin From 7d4eb902b023368fa43661fb0b47625e4cc7b594 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 13:35:29 +0200 Subject: [PATCH 11/19] fix local binary --- .github/workflows/compile.yaml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index eeabeb8..6a449cc 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -73,20 +73,17 @@ jobs: - name: Compile locally # if not on master or if cloud compile failed if: ${{ failure() || github.ref != 'refs/heads/master' }} + id: localcompile uses: particle-iot/compile-action@v1 with: particle-platform-name: ${{ inputs.platform }} device-os-version: ${{ inputs.version }} sources-folder: ${{ inputs.src }} - - name: Move compile results + - name: Move local binary + if: ${{ github.ref != 'refs/heads/master' }} run: | - ls -la / - ls -la ./ - ls -la /firmware/modules/tron/user-part - ls -la /workspace/target - mv /workspace/target/workspace.lst ${{ inputs.src }}/ - mv /workspace/target/workspace.bin ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin + mv ${{ steps.localcompile.outputs.firmware-path }} ${{ inputs.src }}/${{ inputs.src }}-${{ inputs.platform }}-${{ inputs.version }}.bin - name: Upload binary uses: actions/upload-artifact@v4 From c9f38a38c5d85861f2056e977cecb2ef3286bf56 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 14:16:40 +0200 Subject: [PATCH 12/19] update rakfile rake finds .c/.h/.cpp binaries explicitly rake can be run with compile PROGRAM=x --- Rakefile | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Rakefile b/Rakefile index ab04032..6875505 100644 --- a/Rakefile +++ b/Rakefile @@ -3,17 +3,20 @@ # install the CLI from https://github.com/spark/particle-cli # install ruby rake with: bundle install # log into your particle account with: particle login -# to compile: rake PROGRAM +# to compile program x: rake x +# to compile program x without shortcut: rake compile PROGRAM=x # to flash latest compile via USB: rake flash # to flash latest compile via cloud: rake flash DEVICE=name # to start serial monitor: rake monitor -# to compile & flash: rake PROGRAM flash -# to compile, flash & monitor: rake PROGRAM flash monitor +# to compile & flash: rake x flash +# to compile, flash & monitor: rake x flash monitor ### PROGRAMS ### task :blink => :compile task :publish => :compile +task :i2c_scanner => :compile +task :oled => :compile ### SETUP ### @@ -46,7 +49,7 @@ bin = ENV['BIN'] desc "compile binary in the cloud" task :compile do # what program are we compiling? - program = Rake.application.top_level_tasks.first + program = ENV['PROGRAM'] || Rake.application.top_level_tasks.first if program == "default" next end @@ -62,47 +65,55 @@ task :compile do # paths workflow_path = File.join(".github", "workflows", "compile-#{program}.yaml") unless File.exist?(workflow_path) - raise "Workflow YAML config file not found: #{workflow_path}" + warn "Workflow YAML config file not found, compiling just with source folder: #{workflow_path}" + src_path = program + lib_path = "" + aux_files = "" + else + workflow = YAML.load_file(workflow_path) + paths = workflow.dig("jobs", "compile", "strategy", "matrix", "program")[0] + src_path = paths["src"] + lib_path = paths["lib"] + aux_files = paths["aux"] + if src_path.nil? || src_path.strip.empty? + raise "Error: could not extract src/lib/aux dependencies from #{workflow_path}" + end end - workflow = YAML.load_file(workflow_path) - - paths = workflow.dig("jobs", "compile", "strategy", "matrix", "program")[0] - src_path = paths["src"] - lib_path = paths["lib"] - aux_path = paths["aux"] - if src_path.nil? || src_path.strip.empty? - raise "Error: could not extract src/lib/aux dependencies from #{workflow_path}" - end - + # source src_path = File.join(src_folder, src_path) unless Dir.exist?(src_path) raise "Error: folder '#{src_path}' does not exist." end + src_files = Dir.glob("#{src_path}/**/*.{h,c,cpp,properties}").join(' ') # libs unless lib_path.nil? || lib_path.strip.empty? paths = lib_path.strip.split(/\s+/).map do |path| if Dir.exist?(path) - File.join(path, src_folder) + path elsif Dir.exists?(File.join(lib_folder, path)) - File.join(lib_folder, path, src_folder) + File.join(lib_folder, path) else raise "Warning: could not find '#{path}' library in root or #{lib_folder} - rake sure it exists" end end.compact lib_path = paths.join(' ') + lib_files = paths.map do |path| + Dir.glob("#{path}/**/*.{h,c,cpp}").join(' ') + end + lib_files = lib_files.join(' ') end # info puts "\nINFO: compiling '#{program}' in the cloud for #{platform} #{version}...." puts " - src path: #{src_path}" puts " - lib paths: #{lib_path}" - puts " - aux files: #{aux_path}" + puts " - aux files: #{aux_files}" puts "\n" - + # compile - sh "particle compile #{platform} #{src_path} #{src_path}/project.properties #{lib_path} #{aux_path} --target #{version} --saveTo #{bin_folder}/#{program}-#{platform}-#{version}.bin", verbose: false + sh "particle compile #{platform} #{src_files} #{lib_files} #{aux_files} --target #{version} --saveTo #{bin_folder}/#{program}-#{platform}-#{version}.bin", verbose: false end ### FLASH ### From e700c42d35390f36ac5b541b95a822051905f90c Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 14:17:51 +0200 Subject: [PATCH 13/19] make sure credentials are not accidentally committed --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 061ab17..b0a95af 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,7 @@ bin/*.bin .DS_Store # gemfile -Gemfile.lock \ No newline at end of file +Gemfile.lock + +# credentials +credentials \ No newline at end of file From 404a1a67086eec8ae9b1b90ce550cd2d4fe5a15d Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 14:33:20 +0200 Subject: [PATCH 14/19] guardfile now also considers platform and version on autocompile --- Guardfile | 7 ++++--- Rakefile | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Guardfile b/Guardfile index b99719d..b87d2c6 100644 --- a/Guardfile +++ b/Guardfile @@ -14,8 +14,9 @@ bin_folder = "bin" # program last_bin = Dir.glob(File.join(bin_folder, '*.bin')).select { |f| File.file?(f) }.max_by { |f| File.mtime(f) } -program = File.basename(last_bin).split('-').first -puts "\nINFO: Setting up guard to re-compile '#{program}' when there are code changes in:" +program, platform, version = File.basename(last_bin).split('-') +version = version.chomp('.bin') +puts "\nINFO: Setting up guard to re-compile '#{program}' for #{platform} #{version} when there are code changes in:" # workflow workflow_path = File.join(".github", "workflows", "compile-#{program}.yaml") @@ -32,7 +33,7 @@ end puts "\n" # guard -guard 'rake', :task => 'autoCompile', :run_on_start => false, wait_for_changes: true, :task_args => [program] do +guard 'rake', :task => 'autoCompile', :run_on_start => false, wait_for_changes: true, :task_args => [program, platform, version] do watch_paths.each do |pattern| watch(Regexp.new(pattern)) end diff --git a/Rakefile b/Rakefile index 6875505..28daa3c 100644 --- a/Rakefile +++ b/Rakefile @@ -228,12 +228,14 @@ task :update do end desc "used by Guardfile to automatically re-compile binaries on code changes" -task :autoCompile, [:program, :paths] do |t, args| +task :autoCompile, [:program, :platform, :version, :paths] do |t, args| puts "\n**** RE-COMPILE AUTOMATICALLY ****" - puts "program: #{args.program}\nmodified files:" + puts "program: #{args.program}" + puts "platform: #{args.platform} #{args.version}" + puts "modified files:" args.paths.each do |path| puts " - #{path}" end - sh "bundle exec rake #{args.program}", verbose: false + sh "bundle exec rake compile PROGRAM=#{args.program} PLATFORM=#{args.platform} VERSION=#{args.version}", verbose: false puts "**** RE-COMPILE COMPLETE ****" end \ No newline at end of file From 42dbabe1b4e4e87cf1be3e07419a329324d45d58 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 14:34:32 +0200 Subject: [PATCH 15/19] automatically run identify too on list --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 28daa3c..648ffd3 100644 --- a/Rakefile +++ b/Rakefile @@ -158,6 +158,7 @@ desc "list available devices connected to USB" task :list do puts "\nINFO: querying list of available USB devices..." sh "particle usb list" + sh "particle identify" end desc "get MAC address of device connected to USB" From 7889656fcdb1160dbe32efe5a943fddf6b52688f Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 14:38:28 +0200 Subject: [PATCH 16/19] fix typo --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 648ffd3..8b4b53c 100644 --- a/Rakefile +++ b/Rakefile @@ -95,7 +95,7 @@ task :compile do elsif Dir.exists?(File.join(lib_folder, path)) File.join(lib_folder, path) else - raise "Warning: could not find '#{path}' library in root or #{lib_folder} - rake sure it exists" + raise "Could not find '#{path}' library in root or #{lib_folder} - make sure it exists" end end.compact lib_path = paths.join(' ') From 9b79cb33a1b806015f7443c4f4a54e7e1ba361bc Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 15:39:40 +0200 Subject: [PATCH 17/19] update rake --- Rakefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 8b4b53c..39ed652 100644 --- a/Rakefile +++ b/Rakefile @@ -212,6 +212,7 @@ end desc "update device OS" task :update do puts "\nINFO: updating device OS of the device connected on USB to #{version}..." + puts "Careful, the firmware on the device needs to be compatible with the new OS (tinker is usually safe)." print "Are you sure you want to continue? (y/N): " answer = STDIN.gets.strip.downcase unless answer == 'y' || answer == 'yes' @@ -223,7 +224,7 @@ end desc "flash the tinker app" # commands: digitalWrite "D7,HIGH", analogWrite, digitalRead, analogRead "A0" -task :update do +task :tinker do puts "\nINFO: flashing tinker..." sh "particle flash --usb tinker" end From 6269927613a70b719ca2d80335381718c8cc33e3 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 15:40:21 +0200 Subject: [PATCH 18/19] add i2c scanner --- .github/workflows/compile-i2c_scanner.yaml | 40 +++++++++++++++++ src/i2c_scanner/i2c_scanner.cpp | 51 ++++++++++++++++++++++ src/i2c_scanner/project.properties | 1 + 3 files changed, 92 insertions(+) create mode 100644 .github/workflows/compile-i2c_scanner.yaml create mode 100644 src/i2c_scanner/i2c_scanner.cpp create mode 100644 src/i2c_scanner/project.properties diff --git a/.github/workflows/compile-i2c_scanner.yaml b/.github/workflows/compile-i2c_scanner.yaml new file mode 100644 index 0000000..839e840 --- /dev/null +++ b/.github/workflows/compile-i2c_scanner.yaml @@ -0,0 +1,40 @@ +# name of the job +name: Compile i2c scanner + +# specify which paths to watch for changes +on: + push: + paths: + - src/i2c_scanner + - .github/workflows/compile.yaml + - .github/workflows/compile-i2c_scanner.yaml + +# run compile via the compile.yaml +jobs: + compile: + strategy: + fail-fast: false + matrix: + # CHANGE program/lib/aux as needed + program: + - src: 'i2c_scanner' + lib: '' + aux: '' + # CHANGE platforms as needed + platform: + - {name: 'photon', version: '2.3.1'} + - {name: 'argon', version: '4.2.0'} + - {name: 'p2', version: '6.3.2'} + + # program name + name: ${{ matrix.program.src }}-${{ matrix.platform.name }}-${{ matrix.platform.version }} + + # workflow call + uses: ./.github/workflows/compile.yaml + secrets: inherit + with: + platform: ${{ matrix.platform.name }} + version: ${{ matrix.platform.version }} + src: ${{ matrix.program.src }} + lib: ${{ matrix.program.lib }} + aux: ${{ matrix.program.aux }} \ No newline at end of file diff --git a/src/i2c_scanner/i2c_scanner.cpp b/src/i2c_scanner/i2c_scanner.cpp new file mode 100644 index 0000000..23e462a --- /dev/null +++ b/src/i2c_scanner/i2c_scanner.cpp @@ -0,0 +1,51 @@ +#include "Particle.h" +#include "Wire.h" + +// enable system treading +#ifndef SYSTEM_VERSION_v620 +SYSTEM_THREAD(ENABLED); +#endif + +// manual mode, no wifi +SYSTEM_MODE(MANUAL); + +// log handler +SerialLogHandler logHandler(LOG_LEVEL_TRACE); + +// setup +void setup() { + Wire.begin(); +} + +// loop +uint counter = 0; +unsigned long timer = 0; +const std::chrono::milliseconds wait = 2s; +const std::chrono::milliseconds timeout = 100ms; + +void loop() { + byte error, address; + int n_devices = 0; + + if (millis() - timer > wait.count()) { + + Log.info("I2C scan #%d...", ++counter); + + for(address = 1; address < 127; address++ ) { + timer = millis(); + Wire.beginTransmission(address); + error = Wire.endTransmission(); + if (error == 0) { + Log.info("I2C device #%d at address 0x%02X", ++n_devices, address); + } else if (error==4) { + Log.error("Unknown error at address 0x%02X", address); + } else if (millis() - timer > timeout.count()) { + Log.error("Timeout at address 0x%02X, there might be an I2C issue.", address); + } + } + if (n_devices == 0) + Log.info("No I2C devices found.\n"); + else + Log.info("Done.\n"); + } +} \ No newline at end of file diff --git a/src/i2c_scanner/project.properties b/src/i2c_scanner/project.properties new file mode 100644 index 0000000..065e230 --- /dev/null +++ b/src/i2c_scanner/project.properties @@ -0,0 +1 @@ +name=i2c_scanner \ No newline at end of file From 5d5a1978f416930cd82375b73b476c6d8fb1e221 Mon Sep 17 00:00:00 2001 From: Sebastian Kopf Date: Fri, 16 May 2025 15:41:11 +0200 Subject: [PATCH 19/19] add instructions for new programs --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fff243a..ba65e49 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The following firmware is included in the repository to provide frequently used | Program | *main* branch | *dev* branch | | :------- | :--- | :--- | | blink | ![blink](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-blink.yaml/badge.svg?branch=main) | ![blink-dev](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-blink.yaml/badge.svg?branch=dev) | +| i2c_scanner | ![blink](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-i2c_scanner.yaml/badge.svg?branch=main) | ![blink-dev](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-i2c_scanner.yaml/badge.svg?branch=dev) | | publish | ![publish](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-publish.yaml/badge.svg?branch=main) | ![publish-dev](https://github.com/KopfLab/LabLoggerLibs/actions/workflows/compile-publish.yaml/badge.svg?branch=dev) | ### Compile @@ -53,6 +54,17 @@ The configuration for individual programs is managed via their compile workflow The workflow YAML additionally specifies which folders to watch for changes to trigger the automatic rebuild on GitHub in the `push` -> `paths` setting. This information is also used by the [Guardfile](Guardfile) to figure out which files should trigger an automatic rebuild during development. Use `rake PROGRAM` to compile a program for the first time and then activate automatic re-compiles by running `bundle exec guard`. It will figure out which program was last build, pull the folders to watch out of the workflow YAML and trigger re-compile if anything changes. +To add a new program (`myprog`): + + - work in a development git branch (e.g. `dev-myprog`) + - create a sub folder `src/myprog` that includes a `project.properties` file with `name=myprog` and a list of commented out dependencies + - if there are any new dependencies, add them to the table at the end of the `README.md`, and as git submodules in the lib/ folder via `cd lib` + `git submodule add https://github.com/...` + - add a YAML workflow for github actions in `.github/workflows/compile-myprog.yaml` (see e.g. `i2c_scanner` as example) that lists the `src`, `lib` and `aux` needed to compile the program + - add a task in the `Rakefile` under the `### PROGRAM ###` subheading that's simply `task :myprog => :compile` + - test compilation with `rake myprog`, fix issues in the sources (`src/myprog/`) and with libraries as needed until it compiles successfully + - use `bundle exec guard` to continue development with auto compilation + - once the program works as intended and compiles correctly via GitHub actions (https://github.com/kopflab/LabLoggerLibs/actions), add it to the list of firmware in the `README.md` with the github actions badges to `main` and `dev` (whichever dev branch is the correct one, e.g. `dev-myprog`) + ## Libraries ### LoggerCore @@ -78,7 +90,8 @@ The following third-party software is used in the ***LabLogger*** libraries: | LoggerCore | SequentialFileRK | https://github.com/rickkas7/SequentialFileRK | MIT | | LoggerCore | PublishQueueExtRK | https://github.com/rickkas7/PublishQueueExtRK | MIT | | LoggerCore | SparkFun_Qwiic_OpenLog_Arduino_Library | https://github.com/sparkfun/SparkFun_Qwiic_OpenLog_Arduino_Library | MIT | -| LoggerCore | OneWire | https://github.com/particle-iot/OneWireLibrary | MIT | | LoggerOled | Adafruit_SSD1306 | https://github.com/adafruit/Adafruit_SSD1306 | BSD | +| LoggerOled | Adafruit-GFX-Library | https://github.com/adafruit/Adafruit-GFX-Library | BSD | +| LoggerOled | Adafruit_BusIO | https://github.com/adafruit/Adafruit_BusIO | MIT |