From f1f6655c6e876bc2842251278ab8d834b1f685a0 Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sat, 5 Feb 2022 15:21:21 +0100 Subject: [PATCH 01/14] added library files --- LICENSE | 21 +++++++++++++++++ README.md | 23 +++++++++++++++++-- extras/codespell-ignore-words-list.txt | 1 + keywords.txt | 31 ++++++++++++++++++++++++++ library.properties | 11 +++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 LICENSE create mode 100644 extras/codespell-ignore-words-list.txt create mode 100644 keywords.txt create mode 100644 library.properties diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..28176f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Alexander Entinger, LXRobotics GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index c990c91..3f4396f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ -# 107-Arduino-TCS3472 -Arduino library for the ams TCS34725 and TCS34727 Color Sensor + +`107-Arduino-TCS3472` +===================== +[![Arduino Library Badge](https://www.ardu-badge.com/badge/107-Arduino-TCS3472.svg?)](https://www.ardu-badge.com/107-Arduino-TCS3472) +[![Compile Examples](https://github.com/107-systems/107-Arduino-TCS3472/workflows/Compile%20Examples/badge.svg)](https://github.com/107-systems/107-Arduino-TCS3472/actions?workflow=Compile+Examples) +[![Check Arduino](https://github.com/107-systems/107-Arduino-TCS3472/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/107-systems/107-Arduino-TCS3472/actions/workflows/check-arduino.yml) +[![Check keywords.txt](https://github.com/107-systems/107-Arduino-TCS3472/actions/workflows/check-keywords-txt.yml/badge.svg)](https://github.com/107-systems/107-Arduino-TCS3472/actions/workflows/check-keywords-txt.yml) +[![General Formatting Checks](https://github.com/107-systems/107-Arduino-TCS3472/workflows/General%20Formatting%20Checks/badge.svg)](https://github.com/107-systems/107-Arduino-TCS3472/actions?workflow=General+Formatting+Checks) +[![Spell Check](https://github.com/107-systems/107-Arduino-TCS3472/workflows/Spell%20Check/badge.svg)](https://github.com/107-systems/107-Arduino-TCS3472/actions?workflow=Spell+Check) + +

+ +

+ +Arduino library for the [AMS](https://ams.com) [TCS3472](https://ams.com/en/tcs34725) color sensor. + +This library works for +* [ArduinoCore-samd](https://github.com/arduino/ArduinoCore-samd): [`Arduino Zero`](https://store.arduino.cc/arduino-zero), [`MKR 1000`](https://store.arduino.cc/arduino-mkr1000-wifi), [`MKR WiFi 1010`](https://store.arduino.cc/arduino-mkr-wifi-1010), [`Nano 33 IoT`](https://store.arduino.cc/arduino-nano-33-iot), [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415), [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413), [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) :heavy_check_mark: +* [ArduinoCore-mbed](https://github.com/arduino/ArduinoCore-mbed): [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`Nano 33 BLE`](https://store.arduino.cc/arduino-nano-33-ble), [`Nano RP2040 Connect`](https://store.arduino.cc/nano-rp2040-connect), [`Edge Control`](https://store.arduino.cc/edge-control) :heavy_check_mark: +* [arduino-esp32](https://github.com/espressif/arduino-esp32): `ESP32 Dev Module`, `ESP32 Wrover Module`, ... :heavy_check_mark: +* [arduino-esp8266](https://github.com/esp8266/Arduino) :heavy_check_mark: diff --git a/extras/codespell-ignore-words-list.txt b/extras/codespell-ignore-words-list.txt new file mode 100644 index 0000000..e49ad48 --- /dev/null +++ b/extras/codespell-ignore-words-list.txt @@ -0,0 +1 @@ +wan diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..70b2ce2 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,31 @@ +####################################### +# Syntax Coloring Map for 107-Arduino-TCS3472 +####################################### + +####################################### +# Class (KEYWORD1) +####################################### + +ArduinoTCS3472 KEYWORD1 +TCS3472 KEYWORD1 +TCS3472_Io KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +angle_raw KEYWORD2 +read KEYWORD2 +write KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +TCS3472_ClearErrorFlag LITERAL1 +TCS3472_ProgrammingControl LITERAL1 +TCS3472_OTP_RegisterZeroPosition_HIGH LITERAL1 +TCS3472_OTP_RegisterZeroPosition_LOW LITERAL1 +TCS3472_Diagnostics_AutomaticGainControl LITERAL1 +TCS3472_Magnitude LITERAL1 +TCS3472_Angle LITERAL1 diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..a094c06 --- /dev/null +++ b/library.properties @@ -0,0 +1,11 @@ +name=107-Arduino-TCS3472 +version=1.0.0 +author=Bernhard Mayer +maintainer=Bernhard Mayer +sentence=Arduino library for TCS3472 color sensor +paragraph= +category=Sensors +url=https://github.com/107-systems/107-Arduino-TCS3472 +architectures=samd,mbed,mbed_nano,mbed_portenta,mbed_edge,esp8266 +includes=107-Arduino-TSL2550.h +depends=107-Arduino-Sensor From ee3518e0a85e13762169a4f4f0ce6817481892bc Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sat, 5 Feb 2022 15:21:50 +0100 Subject: [PATCH 02/14] added github workflow --- .github/workflows/check-arduino.yml | 26 ++++ .github/workflows/check-keywords-txt.yml | 36 +++++ .github/workflows/compile-examples.yml | 102 ++++++++++++++ .../workflows/general-formatting-checks.yml | 67 +++++++++ .github/workflows/report-size-deltas.yml | 17 +++ .github/workflows/spell-check.yml | 22 +++ .github/workflows/sync-labels.yml | 132 ++++++++++++++++++ 7 files changed, 402 insertions(+) create mode 100644 .github/workflows/check-arduino.yml create mode 100644 .github/workflows/check-keywords-txt.yml create mode 100644 .github/workflows/compile-examples.yml create mode 100644 .github/workflows/general-formatting-checks.yml create mode 100644 .github/workflows/report-size-deltas.yml create mode 100644 .github/workflows/spell-check.yml create mode 100644 .github/workflows/sync-labels.yml diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml new file mode 100644 index 0000000..b3d64e6 --- /dev/null +++ b/.github/workflows/check-arduino.yml @@ -0,0 +1,26 @@ +name: Check Arduino + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + pull_request: + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Arduino Lint + uses: arduino/arduino-lint-action@v1 + with: + compliance: specification + library-manager: update + project-type: library diff --git a/.github/workflows/check-keywords-txt.yml b/.github/workflows/check-keywords-txt.yml new file mode 100644 index 0000000..ff1595f --- /dev/null +++ b/.github/workflows/check-keywords-txt.yml @@ -0,0 +1,36 @@ +name: Check keywords.txt + +# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-keywords-txt.yml" + - "keywords.txt" + pull_request: + paths: + - ".github/workflows/check-keywords-txt.yml" + - "keywords.txt" + workflow_dispatch: + repository_dispatch: + +jobs: + extra-library-checks: + runs-on: ubuntu-latest + + env: + ARDUINO_CI_SCRIPT_FOLDER: extras/ci-tools/arduino-ci-script + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install arduino-ci-script + uses: per1234/install-arduino-ci-script-action@main + with: + installation-path: ${{ env.ARDUINO_CI_SCRIPT_FOLDER }} + + # See: https://github.com/per1234/arduino-ci-script#check_keywords_txt-searchpath-maximumsearchdepth + - name: Check keywords.txt + run: | + source "${ARDUINO_CI_SCRIPT_FOLDER}/arduino-ci-script.sh" + check_keywords_txt "$GITHUB_WORKSPACE" diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml new file mode 100644 index 0000000..d50125b --- /dev/null +++ b/.github/workflows/compile-examples.yml @@ -0,0 +1,102 @@ +name: Compile Examples + +on: + pull_request: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + push: + paths: + - ".github/workflows/compile-examples.yml" + - "examples/**" + - "src/**" + +jobs: + build: + runs-on: ubuntu-latest + + env: + SKETCHES_REPORTS_PATH: sketches-reports + LIBRARIES: | + # Install the library from the local path. + - source-path: ./ + - name: 107-Arduino-Debug + - name: 107-Arduino-Sensor + - name: 107-Arduino-BoostUnits + + strategy: + fail-fast: false + + matrix: + board: + - fqbn: arduino:samd:mkr1000 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrzero + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwifi1010 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrfox1200 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwan1300 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrwan1310 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrgsm1400 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrnb1500 + platforms: | + - name: arduino:samd + - fqbn: arduino:samd:mkrvidor4000 + platforms: | + - name: arduino:samd + - fqbn: arduino:mbed_portenta:envie_m7 + platforms: | + - name: arduino:mbed_portenta + - fqbn: arduino:mbed_portenta:envie_m4 + platforms: | + - name: arduino:mbed_portenta + - fqbn: arduino:mbed_nano:nano33ble + platforms: | + - name: arduino:mbed_nano + - fqbn: arduino:mbed_nano:nanorp2040connect + platforms: | + - name: arduino:mbed_nano + - fqbn: arduino:mbed_edge:edge_control + platforms: | + - name: arduino:mbed_edge + - fqbn: esp32:esp32:esp32 + platforms: | + - name: esp32:esp32 + source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install ESP32 platform dependencies + if: startsWith(matrix.board.fqbn, 'esp32:esp32') + run: pip3 install pyserial + + - name: Compile examples + uses: arduino/compile-sketches@main + with: + fqbn: ${{ matrix.board.fqbn }} + platforms: ${{ matrix.board.platforms }} + libraries: ${{ env.LIBRARIES }} + enable-deltas-report: true + sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} + + - name: Save memory usage change report as artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v2 + with: + name: ${{ env.SKETCHES_REPORTS_PATH }} + path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/general-formatting-checks.yml b/.github/workflows/general-formatting-checks.yml new file mode 100644 index 0000000..a036722 --- /dev/null +++ b/.github/workflows/general-formatting-checks.yml @@ -0,0 +1,67 @@ +name: General Formatting Checks + +on: + - pull_request + - push + +jobs: + blank-first-line: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for files starting with a blank line + run: find . -path './.git' -prune -or -type f -print0 | xargs -0 -L1 bash -c 'head -1 "$0" | grep --binary-files=without-match --regexp="^$"; if [[ "$?" == "0" ]]; then echo "Blank line found at start of $0."; false; fi' + + tabs: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for unnecessary use of true tabs + run: find . -path './.git' -prune -or \( -not -name 'keywords.txt' -and -type f \) -exec grep --with-filename --line-number --binary-files=without-match --regexp=$'\t' '{}' \; -exec echo 'Tab found.' \; -exec false '{}' + + + trailing: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for trailing whitespace + run: find . -path './.git' -prune -or -type f -exec grep --with-filename --line-number --binary-files=without-match --regexp='[[:blank:]]$' '{}' \; -exec echo 'Trailing whitespace found.' \; -exec false '{}' + + + line-endings: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for non-Unix line endings + run: find . -path './.git' -prune -or -type f -exec grep --files-with-matches --binary-files=without-match --regexp=$'\r$' '{}' \; -exec echo 'Non-Unix EOL detected.' \; -exec false '{}' + + + blank-last-line: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for blank lines at end of files + run: find . -path './.git' -prune -or -type f -print0 | xargs -0 -L1 bash -c 'tail -1 "$0" | grep --binary-files=without-match --regexp="^$"; if [[ "$?" == "0" ]]; then echo "Blank line found at end of $0."; false; fi' + + no-last-newline: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Check for files that don't end in a newline + # https://stackoverflow.com/a/25686825 + run: find . -path './.git' -prune -or -type f -print0 | xargs -0 -L1 bash -c 'if test "$(grep --files-with-matches --binary-files=without-match --max-count=1 --regexp='.*' "$0")" && test "$(tail --bytes=1 "$0")"; then echo "No new line at end of $0."; false; fi' diff --git a/.github/workflows/report-size-deltas.yml b/.github/workflows/report-size-deltas.yml new file mode 100644 index 0000000..6657a07 --- /dev/null +++ b/.github/workflows/report-size-deltas.yml @@ -0,0 +1,17 @@ +name: Report Size Deltas + +on: + schedule: + - cron: '*/5 * * * *' + +jobs: + report: + runs-on: ubuntu-latest + + steps: + # See: https://github.com/arduino/actions/blob/master/libraries/report-size-deltas/README.md + - name: Comment size deltas reports to PRs + uses: arduino/report-size-deltas@main + with: + # The name of the workflow artifact created by the "Compile Examples" workflow + sketches-reports-source: sketches-reports diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml new file mode 100644 index 0000000..f06a4c8 --- /dev/null +++ b/.github/workflows/spell-check.yml @@ -0,0 +1,22 @@ +name: Spell Check + +on: + - pull_request + - push + +jobs: + spellcheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md + - name: Spell check + uses: codespell-project/actions-codespell@master + with: + check_filenames: true + check_hidden: true + skip: ./.git,./extras/test/external,./src/lib + ignore_words_file: extras/codespell-ignore-words-list.txt diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..90939cc --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,132 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # run every Tuesday at 3 AM UTC + - cron: "0 3 * * 2" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v1.0.3 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/107-systems/.github/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v1.0.3 + with: + file-url: https://raw.githubusercontent.com/107-systems/.github/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v2 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event == 'pull_request' || + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Download configuration files artifact + uses: actions/download-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v1 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} From 9a28f5a300dcf48402e3d08caa2fc1172b0e298b Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sat, 5 Feb 2022 15:28:55 +0100 Subject: [PATCH 03/14] added source code --- src/107-Arduino-TCS3472.cpp | 63 +++++++++++++++++++++++++++ src/107-Arduino-TCS3472.h | 44 +++++++++++++++++++ src/TCS3472/TCS3472_Const.h | 78 +++++++++++++++++++++++++++++++++ src/TCS3472/TCS3472_Io.cpp | 86 +++++++++++++++++++++++++++++++++++++ src/TCS3472/TCS3472_Io.h | 72 +++++++++++++++++++++++++++++++ 5 files changed, 343 insertions(+) create mode 100644 src/107-Arduino-TCS3472.cpp create mode 100644 src/107-Arduino-TCS3472.h create mode 100644 src/TCS3472/TCS3472_Const.h create mode 100644 src/TCS3472/TCS3472_Io.cpp create mode 100644 src/TCS3472/TCS3472_Io.h diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp new file mode 100644 index 0000000..ffd86cd --- /dev/null +++ b/src/107-Arduino-TCS3472.cpp @@ -0,0 +1,63 @@ +/** + * This software is distributed under the terms of the MIT License. + * Copyright (c) 2022 LXRobotics. + * Author: Bernhard Mayer + * Contributors: https://github.com/107-systems/107-Arduino-TCS3472/graphs/contributors. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "107-Arduino-TCS3472.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace TCS3472; + +/************************************************************************************** + * CTOR/DTOR + **************************************************************************************/ + +ArduinoTCS3472::ArduinoTCS3472(TCS3472::I2cWriteFunc write, + TCS3472::I2cReadFunc read, + // TCS3472::DelayFunc delay, + uint8_t const i2c_slave_addr) +: _error{TCS3472::Error::None} +, _io{write, read, i2c_slave_addr} +{ +} + + +/************************************************************************************** + * PUBLIC MEMBER FUNCTIONS + **************************************************************************************/ + +bool ArduinoTCS3472::begin(bool const use_extended) +{ + /* Check the CHIP ID if it matches the expected value. + */ + if (_io.read(TCS3472::Register::TCS3472_ReadCommandRegister) != TCS3472::ID_EXPECTED_ID) { + _error = TCS3472::Error::ChipId; + return false; + } + + if(use_extended == true) _io.write(TCS3472::Register::TCS3472_WriteCommandExtendedRange); + else _io.write(TCS3472::Register::TCS3472_WriteCommandStandardRange); + + return true; +} + + +float ArduinoTCS3472::get_lux() +{ + float r=0, light_level=0; + return light_level; +} + +TCS3472::Error ArduinoTCS3472::error() +{ + return _error; +} diff --git a/src/107-Arduino-TCS3472.h b/src/107-Arduino-TCS3472.h new file mode 100644 index 0000000..4d2e8a0 --- /dev/null +++ b/src/107-Arduino-TCS3472.h @@ -0,0 +1,44 @@ +/** + * This software is distributed under the terms of the MIT License. + * Copyright (c) 2022 LXRobotics. + * Author: Bernhard Mayer + * Contributors: https://github.com/107-systems/107-Arduino-TCS3472/graphs/contributors. + */ + +#ifndef _107_ARDUINO_TCS3472_H_ +#define _107_ARDUINO_TCS3472_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "TCS3472/TCS3472_Io.h" +#include "Arduino.h" + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class ArduinoTCS3472 +{ + +public: + + ArduinoTCS3472(TCS3472::I2cWriteFunc write, + TCS3472::I2cReadFunc read, + // TCS3472::DelayFunc delay, + uint8_t const i2c_slave_addr); + + bool begin(bool const use_extended); + float get_lux(); + + TCS3472::Error error(); + +private: + + TCS3472::Error _error; + TCS3472::TCS3472_Io _io; + +}; + +#endif /* _107_ARDUINO_TCS3472_H_ */ diff --git a/src/TCS3472/TCS3472_Const.h b/src/TCS3472/TCS3472_Const.h new file mode 100644 index 0000000..0767f60 --- /dev/null +++ b/src/TCS3472/TCS3472_Const.h @@ -0,0 +1,78 @@ +/** + * This software is distributed under the terms of the MIT License. + * Copyright (c) 2022 LXRobotics. + * Author: Bernhard Mayer + * Contributors: https://github.com/107-systems/107-Arduino-TCS3472/graphs/contributors. + */ + +#ifndef ARDUINO_TCS3472_TCS3472_CONST_H_ +#define ARDUINO_TCS3472_TCS3472_CONST_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace TCS3472 +{ + +/************************************************************************************** + * TYPEDEF + **************************************************************************************/ + +enum class Register : uint8_t +{ + TCS3472_PowerDownState = 0x00, +}; + +enum class Error : int +{ + None = 0, + Timeout = -1, + ChipId = -2, + Param = -3, +}; + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static uint8_t constexpr ID_EXPECTED_ID = 0x03; +static uint8_t constexpr DEFAULT_I2C_ADDR = 0x39; + +/************************************************************************************** + * CONVERSION FUNCTIONS + **************************************************************************************/ + +template +constexpr auto to_integer(Enumeration const value) -> typename std::underlying_type::type +{ + return static_cast::type>(value); +} + +template +constexpr auto bp(Enumeration const value) -> typename std::underlying_type::type +{ + return to_integer(value); +} + +template +constexpr auto bm(Enumeration const value) -> typename std::underlying_type::type +{ + return (1 << to_integer(value)); +} + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* TCS3472 */ + +#endif /* ARDUINO_TCS3472_TCS3472_CONST_H_ */ diff --git a/src/TCS3472/TCS3472_Io.cpp b/src/TCS3472/TCS3472_Io.cpp new file mode 100644 index 0000000..ba89dd2 --- /dev/null +++ b/src/TCS3472/TCS3472_Io.cpp @@ -0,0 +1,86 @@ +/** + * This software is distributed under the terms of the MIT License. + * Copyright (c) 2022 LXRobotics. + * Author: Bernhard Mayer + * Contributors: https://github.com/107-systems/107-Arduino-TCS3472/graphs/contributors. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "TCS3472_Io.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace TCS3472 +{ + +/************************************************************************************** + * CTOR/DTOR + **************************************************************************************/ + +TCS3472_Io::TCS3472_Io(I2cWriteFunc write, I2cReadFunc read, uint8_t const i2c_slave_addr) +: _write{write} +, _read{read} +, _i2c_slave_addr{i2c_slave_addr} +{ + +} + +/************************************************************************************** + * PUBLIC MEMBER FUNCTIONS + **************************************************************************************/ + +uint8_t TCS3472_Io::read(Register const reg) +{ + uint8_t data = 0; + read(reg, &data, 1); + return data; +} + +void TCS3472_Io::write(Register const reg) +{ + uint8_t const val=0; + write(reg, &val, 0); +} + +void TCS3472_Io::write(Register const reg, uint8_t const val) +{ + write(reg, &val, 1); +} + +void TCS3472_Io::read(Register const reg, uint8_t * buf, size_t const bytes) +{ + _read(_i2c_slave_addr, to_integer(reg), buf, bytes); +} + +void TCS3472_Io::write(Register const reg, uint8_t const * buf, size_t const bytes) +{ + _write(_i2c_slave_addr, to_integer(reg), buf, bytes); +} + +void TCS3472_Io::modify(Register const reg, uint8_t const bitmask, uint8_t const val) +{ + uint8_t reg_val = read(reg); + reg_val &= ~(bitmask); + reg_val |= (val & bitmask); + write(reg, reg_val); +} + +bool TCS3472_Io::isBitSet(Register const reg, uint8_t const bitpos) +{ + uint8_t const reg_val = read(reg); + if (reg_val & (1< + * Contributors: https://github.com/107-systems/107-Arduino-TCS3472/graphs/contributors. + */ + +#ifndef ARDUINO_TCS3472_TCS3472_IO_H_ +#define ARDUINO_TCS3472_TCS3472_IO_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#undef max +#undef min +#include + +#include "TCS3472_Const.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace TCS3472 +{ + +/************************************************************************************** + * TYPEDEF + **************************************************************************************/ + +typedef std::function I2cWriteFunc; +typedef std::function I2cReadFunc; + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class TCS3472_Io +{ +public: + + TCS3472_Io(I2cWriteFunc write, I2cReadFunc read, uint8_t const i2c_slave_addr); + + + inline void set_i2c_slace_addr(uint8_t const i2c_slave_addr) { _i2c_slave_addr = i2c_slave_addr; } + + + void write (Register const reg); + uint8_t read (Register const reg); + void write (Register const reg, uint8_t const val); + void read (Register const reg, uint8_t * buf, size_t const bytes); + void write (Register const reg, uint8_t const * buf, size_t const bytes); + void modify (Register const reg, uint8_t const bitmask, uint8_t const val); + bool isBitSet(Register const reg, uint8_t const bitpos); + + +private: + + I2cWriteFunc _write; + I2cReadFunc _read; + + uint8_t _i2c_slave_addr; +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* TCS3472 */ + +#endif /* ARDUINO_TCS3472_TCS3472_IO_H_ */ From 6411880ab872f218e5c68cb2586c7c358a58eb0c Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sat, 5 Feb 2022 15:41:45 +0100 Subject: [PATCH 04/14] set consts --- src/107-Arduino-TCS3472.cpp | 7 ++++--- src/TCS3472/TCS3472_Const.h | 25 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp index ffd86cd..6f63423 100644 --- a/src/107-Arduino-TCS3472.cpp +++ b/src/107-Arduino-TCS3472.cpp @@ -39,13 +39,14 @@ bool ArduinoTCS3472::begin(bool const use_extended) { /* Check the CHIP ID if it matches the expected value. */ - if (_io.read(TCS3472::Register::TCS3472_ReadCommandRegister) != TCS3472::ID_EXPECTED_ID) { + if (_io.read(TCS3472::Register::TCS3472_ID) != TCS3472::ID_EXPECTED_ID) { _error = TCS3472::Error::ChipId; return false; } - if(use_extended == true) _io.write(TCS3472::Register::TCS3472_WriteCommandExtendedRange); - else _io.write(TCS3472::Register::TCS3472_WriteCommandStandardRange); + _io.write(TCS3472::Register::TCS3472_WTIME, 0xFF); /* set WTIME to default value */ + _io.write(TCS3472::Register::TCS3472_ATIME, 0xFF); /* set ATIME to default value */ + _io.write(TCS3472::Register::TCS3472_ENABLE, 0x0B); /* set WEN, PEN, AEN and PON bit in ENABLE */ return true; } diff --git a/src/TCS3472/TCS3472_Const.h b/src/TCS3472/TCS3472_Const.h index 0767f60..2d1316f 100644 --- a/src/TCS3472/TCS3472_Const.h +++ b/src/TCS3472/TCS3472_Const.h @@ -29,7 +29,26 @@ namespace TCS3472 enum class Register : uint8_t { - TCS3472_PowerDownState = 0x00, + TCS3472_ENABLE = 0x00, + TCS3472_ATIME = 0x01, + TCS3472_WTIME = 0x03, + TCS3472_AILTL = 0x04, + TCS3472_AILTH = 0x05, + TCS3472_AIHTL = 0x06, + TCS3472_AIHTH = 0x07, + TCS3472_PERS = 0x0C, + TCS3472_CONFIG = 0x0D, + TCS3472_CONTROL = 0x0F, + TCS3472_ID = 0x12, + TCS3472_STATUS = 0x13, + TCS3472_CDATAL = 0x14, + TCS3472_CDATAH = 0x15, + TCS3472_RDATAL = 0x16, + TCS3472_RDATAH = 0x17, + TCS3472_GDATAL = 0x18, + TCS3472_GDATAH = 0x19, + TCS3472_BDATAL = 0x1A, + TCS3472_BDATAH = 0x1B, }; enum class Error : int @@ -44,8 +63,8 @@ enum class Error : int * CONSTANTS **************************************************************************************/ -static uint8_t constexpr ID_EXPECTED_ID = 0x03; -static uint8_t constexpr DEFAULT_I2C_ADDR = 0x39; +static uint8_t constexpr ID_EXPECTED_ID = 0x44; +static uint8_t constexpr DEFAULT_I2C_ADDR = 0x29; /************************************************************************************** * CONVERSION FUNCTIONS From f90b4edc2789ffdcca4e2f8757a6dbcb2454dc0d Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sun, 6 Feb 2022 10:40:49 +0100 Subject: [PATCH 05/14] updated library functions --- src/107-Arduino-TCS3472.cpp | 8 +++++--- src/107-Arduino-TCS3472.h | 10 +++++++++- src/TCS3472/TCS3472_Io.cpp | 7 +++++++ src/TCS3472/TCS3472_Io.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp index 6f63423..cc8b9a0 100644 --- a/src/107-Arduino-TCS3472.cpp +++ b/src/107-Arduino-TCS3472.cpp @@ -52,10 +52,12 @@ bool ArduinoTCS3472::begin(bool const use_extended) } -float ArduinoTCS3472::get_lux() +void ArduinoTCS3472::get_colorData(struct colorDataRaw * color) { - float r=0, light_level=0; - return light_level; + color->clear = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_CDATAL)|0x40)); + color->red = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_RDATAL)|0x40)); + color->green = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_GDATAL)|0x40)); + color->blue = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_BDATAL)|0x40)); } TCS3472::Error ArduinoTCS3472::error() diff --git a/src/107-Arduino-TCS3472.h b/src/107-Arduino-TCS3472.h index 4d2e8a0..4508634 100644 --- a/src/107-Arduino-TCS3472.h +++ b/src/107-Arduino-TCS3472.h @@ -24,13 +24,21 @@ class ArduinoTCS3472 public: + struct colorDataRaw{ + uint16_t clear; + uint16_t red; + uint16_t green; + uint16_t blue; + }; + + ArduinoTCS3472(TCS3472::I2cWriteFunc write, TCS3472::I2cReadFunc read, // TCS3472::DelayFunc delay, uint8_t const i2c_slave_addr); bool begin(bool const use_extended); - float get_lux(); + void get_colorData(struct colorDataRaw * color); TCS3472::Error error(); diff --git a/src/TCS3472/TCS3472_Io.cpp b/src/TCS3472/TCS3472_Io.cpp index ba89dd2..2184fdb 100644 --- a/src/TCS3472/TCS3472_Io.cpp +++ b/src/TCS3472/TCS3472_Io.cpp @@ -41,6 +41,13 @@ uint8_t TCS3472_Io::read(Register const reg) return data; } +uint16_t TCS3472_Io::read16(Register const reg) +{ + uint16_t data = 0; + read(reg, (uint8_t *)&data, 2); + return data; +} + void TCS3472_Io::write(Register const reg) { uint8_t const val=0; diff --git a/src/TCS3472/TCS3472_Io.h b/src/TCS3472/TCS3472_Io.h index 5180f4c..2ad3305 100644 --- a/src/TCS3472/TCS3472_Io.h +++ b/src/TCS3472/TCS3472_Io.h @@ -48,6 +48,7 @@ class TCS3472_Io void write (Register const reg); uint8_t read (Register const reg); + uint16_t read16 (Register const reg); void write (Register const reg, uint8_t const val); void read (Register const reg, uint8_t * buf, size_t const bytes); void write (Register const reg, uint8_t const * buf, size_t const bytes); From 624438ad65588e25f9fee47c7297c532907b0a10 Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sun, 6 Feb 2022 10:42:20 +0100 Subject: [PATCH 06/14] added example --- examples/TCS3472-Basic/TCS3472-Basic.ino | 94 ++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 examples/TCS3472-Basic/TCS3472-Basic.ino diff --git a/examples/TCS3472-Basic/TCS3472-Basic.ino b/examples/TCS3472-Basic/TCS3472-Basic.ino new file mode 100644 index 0000000..3fa4688 --- /dev/null +++ b/examples/TCS3472-Basic/TCS3472-Basic.ino @@ -0,0 +1,94 @@ +/** + * @brief Basic example demonstrating usage of 107-Arduino-TCS3472 library. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include <107-Arduino-TCS3472.h> + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +void i2c_generic_write(uint8_t const i2c_slave_addr, uint8_t const reg_addr, uint8_t const * buf, uint8_t const num_bytes); +void i2c_generic_read (uint8_t const i2c_slave_addr, uint8_t const reg_addr, uint8_t * buf, uint8_t const num_bytes); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +ArduinoTCS3472 tcs3472(i2c_generic_write, + i2c_generic_read, +// delay, + TCS3472::DEFAULT_I2C_ADDR); + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while(!Serial) { } + + /* Setup Wire access */ + Wire.begin(); + + /* Configure TSL2550 with Extended Range */ + if (!tcs3472.begin(true)) + { + Serial.print("ArduinoTCS3472::begin(...) failed, error code "); + Serial.print((int)tcs3472.error()); + for(;;) { } + } + + Serial.println("TCS3472 OK"); +} + +void loop() +{ + ArduinoTCS3472::colorDataRaw color; + + tcs3472.get_colorData(&color); + Serial.print("Clear = "); + Serial.println(color.clear); + Serial.print("Red = "); + Serial.println(color.red); + Serial.print("Green = "); + Serial.println(color.green); + Serial.print("Blue = "); + Serial.println(color.blue); + Serial.println(""); + + delay(500); +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +void i2c_generic_write(uint8_t const i2c_slave_addr, uint8_t const reg_addr, uint8_t const * buf, uint8_t const num_bytes) +{ + Wire.beginTransmission(i2c_slave_addr); + Wire.write(reg_addr); + for(uint8_t bytes_written = 0; bytes_written < num_bytes; bytes_written++) { + Wire.write(buf[bytes_written]); + } + Wire.endTransmission(); +} + +void i2c_generic_read(uint8_t const i2c_slave_addr, uint8_t const reg_addr, uint8_t * buf, uint8_t const num_bytes) +{ + Wire.beginTransmission(i2c_slave_addr); + Wire.write(reg_addr); + Wire.endTransmission(); + + Wire.requestFrom(i2c_slave_addr, num_bytes); + for(uint8_t bytes_read = 0; (bytes_read < num_bytes) && Wire.available(); bytes_read++) { + buf[bytes_read] = Wire.read(); + } +} From 01fab6dbbbfff395103a1719e8b26b94b6d75a4f Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sun, 6 Feb 2022 13:23:03 +0100 Subject: [PATCH 07/14] corrected function of lib --- src/107-Arduino-TCS3472.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp index cc8b9a0..b254c2d 100644 --- a/src/107-Arduino-TCS3472.cpp +++ b/src/107-Arduino-TCS3472.cpp @@ -39,14 +39,14 @@ bool ArduinoTCS3472::begin(bool const use_extended) { /* Check the CHIP ID if it matches the expected value. */ - if (_io.read(TCS3472::Register::TCS3472_ID) != TCS3472::ID_EXPECTED_ID) { + if (_io.read((Register const)((uint8_t)(TCS3472::Register::TCS3472_ID)|0x80)) != TCS3472::ID_EXPECTED_ID) { _error = TCS3472::Error::ChipId; return false; } - _io.write(TCS3472::Register::TCS3472_WTIME, 0xFF); /* set WTIME to default value */ - _io.write(TCS3472::Register::TCS3472_ATIME, 0xFF); /* set ATIME to default value */ - _io.write(TCS3472::Register::TCS3472_ENABLE, 0x0B); /* set WEN, PEN, AEN and PON bit in ENABLE */ + _io.write((Register const)((uint8_t)(TCS3472::Register::TCS3472_WTIME)|0x80), 0xFF); /* set WTIME to default value */ + _io.write((Register const)((uint8_t)(TCS3472::Register::TCS3472_ATIME)|0x80), 0xFF); /* set ATIME to default value */ + _io.write((Register const)((uint8_t)(TCS3472::Register::TCS3472_ENABLE)|0x80), 0x0B); /* set WEN, PEN, AEN and PON bit in ENABLE */ return true; } @@ -54,10 +54,10 @@ bool ArduinoTCS3472::begin(bool const use_extended) void ArduinoTCS3472::get_colorData(struct colorDataRaw * color) { - color->clear = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_CDATAL)|0x40)); - color->red = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_RDATAL)|0x40)); - color->green = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_GDATAL)|0x40)); - color->blue = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_BDATAL)|0x40)); + color->clear = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_CDATAL)|0xA0)); + color->red = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_RDATAL)|0xA0)); + color->green = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_GDATAL)|0xA0)); + color->blue = _io.read16((Register const)((uint8_t)(TCS3472::Register::TCS3472_BDATAL)|0xA0)); } TCS3472::Error ArduinoTCS3472::error() From e81d793102887231837392555d4ea9069624aa8a Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Sun, 6 Feb 2022 13:26:51 +0100 Subject: [PATCH 08/14] removed unnecessary variables --- examples/TCS3472-Basic/TCS3472-Basic.ino | 2 +- src/107-Arduino-TCS3472.cpp | 2 +- src/107-Arduino-TCS3472.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/TCS3472-Basic/TCS3472-Basic.ino b/examples/TCS3472-Basic/TCS3472-Basic.ino index 3fa4688..6652778 100644 --- a/examples/TCS3472-Basic/TCS3472-Basic.ino +++ b/examples/TCS3472-Basic/TCS3472-Basic.ino @@ -39,7 +39,7 @@ void setup() Wire.begin(); /* Configure TSL2550 with Extended Range */ - if (!tcs3472.begin(true)) + if (!tcs3472.begin()) { Serial.print("ArduinoTCS3472::begin(...) failed, error code "); Serial.print((int)tcs3472.error()); diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp index b254c2d..3b9e980 100644 --- a/src/107-Arduino-TCS3472.cpp +++ b/src/107-Arduino-TCS3472.cpp @@ -35,7 +35,7 @@ ArduinoTCS3472::ArduinoTCS3472(TCS3472::I2cWriteFunc write, * PUBLIC MEMBER FUNCTIONS **************************************************************************************/ -bool ArduinoTCS3472::begin(bool const use_extended) +bool ArduinoTCS3472::begin() { /* Check the CHIP ID if it matches the expected value. */ diff --git a/src/107-Arduino-TCS3472.h b/src/107-Arduino-TCS3472.h index 4508634..f3d429f 100644 --- a/src/107-Arduino-TCS3472.h +++ b/src/107-Arduino-TCS3472.h @@ -37,7 +37,7 @@ class ArduinoTCS3472 // TCS3472::DelayFunc delay, uint8_t const i2c_slave_addr); - bool begin(bool const use_extended); + bool begin(); void get_colorData(struct colorDataRaw * color); TCS3472::Error error(); From de9dd0c11f0e35ae91454dafca9c35a5cadd03cd Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 7 Feb 2022 06:48:35 +0100 Subject: [PATCH 09/14] Change arduino-lint-action configuration to submit, i.e. pre-inclusion into library index. --- .github/workflows/check-arduino.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index b3d64e6..3bce782 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -22,5 +22,5 @@ jobs: uses: arduino/arduino-lint-action@v1 with: compliance: specification - library-manager: update + library-manager: submit project-type: library From bae6c46253f858683a0652f3c2394cc431b44162 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 7 Feb 2022 06:51:50 +0100 Subject: [PATCH 10/14] Fixing wrong include file. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index a094c06..538597e 100644 --- a/library.properties +++ b/library.properties @@ -7,5 +7,5 @@ paragraph= category=Sensors url=https://github.com/107-systems/107-Arduino-TCS3472 architectures=samd,mbed,mbed_nano,mbed_portenta,mbed_edge,esp8266 -includes=107-Arduino-TSL2550.h +includes=107-Arduino-TCS3472.h depends=107-Arduino-Sensor From 151f9601dab8e7cb1cf3733df58773dafe5b9abb Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 7 Feb 2022 06:55:31 +0100 Subject: [PATCH 11/14] Remove trailing whitespace. --- examples/TCS3472-Basic/TCS3472-Basic.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/TCS3472-Basic/TCS3472-Basic.ino b/examples/TCS3472-Basic/TCS3472-Basic.ino index 6652778..520b21c 100644 --- a/examples/TCS3472-Basic/TCS3472-Basic.ino +++ b/examples/TCS3472-Basic/TCS3472-Basic.ino @@ -52,7 +52,7 @@ void setup() void loop() { ArduinoTCS3472::colorDataRaw color; - + tcs3472.get_colorData(&color); Serial.print("Clear = "); Serial.println(color.clear); From f828d7d3f589077a8ea371081bf70d5f6878b81d Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Wed, 9 Feb 2022 22:50:11 +0100 Subject: [PATCH 12/14] cleaned up code --- .github/workflows/compile-examples.yml | 3 --- examples/TCS3472-Basic/TCS3472-Basic.ino | 3 +-- keywords.txt | 14 +++++++------- library.properties | 2 +- src/107-Arduino-TCS3472.cpp | 1 - src/107-Arduino-TCS3472.h | 2 -- src/TCS3472/TCS3472_Io.cpp | 17 ----------------- src/TCS3472/TCS3472_Io.h | 7 +------ 8 files changed, 10 insertions(+), 39 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index d50125b..b8f664e 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -21,9 +21,6 @@ jobs: LIBRARIES: | # Install the library from the local path. - source-path: ./ - - name: 107-Arduino-Debug - - name: 107-Arduino-Sensor - - name: 107-Arduino-BoostUnits strategy: fail-fast: false diff --git a/examples/TCS3472-Basic/TCS3472-Basic.ino b/examples/TCS3472-Basic/TCS3472-Basic.ino index 520b21c..c60cbfd 100644 --- a/examples/TCS3472-Basic/TCS3472-Basic.ino +++ b/examples/TCS3472-Basic/TCS3472-Basic.ino @@ -23,7 +23,6 @@ void i2c_generic_read (uint8_t const i2c_slave_addr, uint8_t const reg_addr, uin ArduinoTCS3472 tcs3472(i2c_generic_write, i2c_generic_read, -// delay, TCS3472::DEFAULT_I2C_ADDR); /************************************************************************************** @@ -42,7 +41,7 @@ void setup() if (!tcs3472.begin()) { Serial.print("ArduinoTCS3472::begin(...) failed, error code "); - Serial.print((int)tcs3472.error()); + Serial.print(static cast(tcs3472.error())); for(;;) { } } diff --git a/keywords.txt b/keywords.txt index 70b2ce2..0a70ea7 100644 --- a/keywords.txt +++ b/keywords.txt @@ -22,10 +22,10 @@ write KEYWORD2 # Constants (LITERAL1) ####################################### -TCS3472_ClearErrorFlag LITERAL1 -TCS3472_ProgrammingControl LITERAL1 -TCS3472_OTP_RegisterZeroPosition_HIGH LITERAL1 -TCS3472_OTP_RegisterZeroPosition_LOW LITERAL1 -TCS3472_Diagnostics_AutomaticGainControl LITERAL1 -TCS3472_Magnitude LITERAL1 -TCS3472_Angle LITERAL1 +ClearErrorFlag LITERAL1 +ProgrammingControl LITERAL1 +OTP_RegisterZeroPosition_HIGH LITERAL1 +OTP_RegisterZeroPosition_LOW LITERAL1 +Diagnostics_AutomaticGainControl LITERAL1 +Magnitude LITERAL1 +Angle LITERAL1 diff --git a/library.properties b/library.properties index 538597e..a45255d 100644 --- a/library.properties +++ b/library.properties @@ -8,4 +8,4 @@ category=Sensors url=https://github.com/107-systems/107-Arduino-TCS3472 architectures=samd,mbed,mbed_nano,mbed_portenta,mbed_edge,esp8266 includes=107-Arduino-TCS3472.h -depends=107-Arduino-Sensor +depends= diff --git a/src/107-Arduino-TCS3472.cpp b/src/107-Arduino-TCS3472.cpp index 3b9e980..09405ba 100644 --- a/src/107-Arduino-TCS3472.cpp +++ b/src/107-Arduino-TCS3472.cpp @@ -23,7 +23,6 @@ using namespace TCS3472; ArduinoTCS3472::ArduinoTCS3472(TCS3472::I2cWriteFunc write, TCS3472::I2cReadFunc read, - // TCS3472::DelayFunc delay, uint8_t const i2c_slave_addr) : _error{TCS3472::Error::None} , _io{write, read, i2c_slave_addr} diff --git a/src/107-Arduino-TCS3472.h b/src/107-Arduino-TCS3472.h index f3d429f..48e4508 100644 --- a/src/107-Arduino-TCS3472.h +++ b/src/107-Arduino-TCS3472.h @@ -13,7 +13,6 @@ **************************************************************************************/ #include "TCS3472/TCS3472_Io.h" -#include "Arduino.h" /************************************************************************************** * CLASS DECLARATION @@ -34,7 +33,6 @@ class ArduinoTCS3472 ArduinoTCS3472(TCS3472::I2cWriteFunc write, TCS3472::I2cReadFunc read, - // TCS3472::DelayFunc delay, uint8_t const i2c_slave_addr); bool begin(); diff --git a/src/TCS3472/TCS3472_Io.cpp b/src/TCS3472/TCS3472_Io.cpp index 2184fdb..0fd2004 100644 --- a/src/TCS3472/TCS3472_Io.cpp +++ b/src/TCS3472/TCS3472_Io.cpp @@ -69,23 +69,6 @@ void TCS3472_Io::write(Register const reg, uint8_t const * buf, size_t const byt _write(_i2c_slave_addr, to_integer(reg), buf, bytes); } -void TCS3472_Io::modify(Register const reg, uint8_t const bitmask, uint8_t const val) -{ - uint8_t reg_val = read(reg); - reg_val &= ~(bitmask); - reg_val |= (val & bitmask); - write(reg, reg_val); -} - -bool TCS3472_Io::isBitSet(Register const reg, uint8_t const bitpos) -{ - uint8_t const reg_val = read(reg); - if (reg_val & (1< Date: Wed, 9 Feb 2022 23:00:39 +0100 Subject: [PATCH 13/14] updated keywords --- keywords.txt | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/keywords.txt b/keywords.txt index 0a70ea7..5dea35e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -14,7 +14,7 @@ TCS3472_Io KEYWORD1 # Methods and Functions (KEYWORD2) ####################################### -angle_raw KEYWORD2 +get_colorData KEYWORD2 read KEYWORD2 write KEYWORD2 @@ -22,10 +22,23 @@ write KEYWORD2 # Constants (LITERAL1) ####################################### -ClearErrorFlag LITERAL1 -ProgrammingControl LITERAL1 -OTP_RegisterZeroPosition_HIGH LITERAL1 -OTP_RegisterZeroPosition_LOW LITERAL1 -Diagnostics_AutomaticGainControl LITERAL1 -Magnitude LITERAL1 -Angle LITERAL1 +TCS3472_ENABLE LITERAL1 +TCS3472_ATIME LITERAL1 +TCS3472_WTIME LITERAL1 +TCS3472_AILTL LITERAL1 +TCS3472_AILTH LITERAL1 +TCS3472_AIHTL LITERAL1 +TCS3472_AIHTH LITERAL1 +TCS3472_PERS LITERAL1 +TCS3472_CONFIG LITERAL1 +TCS3472_CONTROL LITERAL1 +TCS3472_ID LITERAL1 +TCS3472_STATUS LITERAL1 +TCS3472_CDATAL LITERAL1 +TCS3472_CDATAH LITERAL1 +TCS3472_RDATAL LITERAL1 +TCS3472_RDATAH LITERAL1 +TCS3472_GDATAL LITERAL1 +TCS3472_GDATAH LITERAL1 +TCS3472_BDATAL LITERAL1 +TCS3472_BDATAH LITERAL1 From 61cb64c4965e17f8561e2a5cb95fbbee1bb94f33 Mon Sep 17 00:00:00 2001 From: Bernhard Mayer Date: Wed, 9 Feb 2022 23:46:05 +0100 Subject: [PATCH 14/14] corrected compile error --- examples/TCS3472-Basic/TCS3472-Basic.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/TCS3472-Basic/TCS3472-Basic.ino b/examples/TCS3472-Basic/TCS3472-Basic.ino index c60cbfd..aa20a9f 100644 --- a/examples/TCS3472-Basic/TCS3472-Basic.ino +++ b/examples/TCS3472-Basic/TCS3472-Basic.ino @@ -41,7 +41,7 @@ void setup() if (!tcs3472.begin()) { Serial.print("ArduinoTCS3472::begin(...) failed, error code "); - Serial.print(static cast(tcs3472.error())); + Serial.print(static_cast(tcs3472.error())); for(;;) { } }